本文整理匯總了C#中Sharpen.FileInputStream.GetChannel方法的典型用法代碼示例。如果您正苦於以下問題:C# FileInputStream.GetChannel方法的具體用法?C# FileInputStream.GetChannel怎麽用?C# FileInputStream.GetChannel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sharpen.FileInputStream
的用法示例。
在下文中一共展示了FileInputStream.GetChannel方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadFully
/// <summary>Read an entire local file into memory as a byte array.</summary>
/// <remarks>Read an entire local file into memory as a byte array.</remarks>
/// <param name="path">location of the file to read.</param>
/// <param name="max">
/// maximum number of bytes to read, if the file is larger than
/// this limit an IOException is thrown.
/// </param>
/// <returns>complete contents of the requested local file.</returns>
/// <exception cref="System.IO.FileNotFoundException">the file does not exist.</exception>
/// <exception cref="System.IO.IOException">the file exists, but its contents cannot be read.
/// </exception>
public static byte[] ReadFully(FilePath path, int max)
{
FileInputStream @in = new FileInputStream(path);
try
{
long sz = @in.GetChannel().Size();
if (sz > max)
{
throw new IOException(MessageFormat.Format(JGitText.Get().fileIsTooLarge, path));
}
byte[] buf = new byte[(int)sz];
IOUtil.ReadFully(@in, buf, 0, buf.Length);
return buf;
}
finally
{
try
{
@in.Close();
}
catch (IOException)
{
}
}
}
示例2: VisitFile
/// <exception cref="System.IO.IOException"></exception>
public override void VisitFile(FileTreeEntry f)
{
FilePath path = new FilePath(GetCurrentDirectory(), f.GetName());
FileInputStream @in = new FileInputStream(path);
try
{
long sz = @in.GetChannel().Size();
f.SetId(inserter.Insert(Constants.OBJ_BLOB, sz, @in));
inserter.Flush();
}
finally
{
inserter.Release();
@in.Close();
}
}
示例3: CopyCurrentContent
/// <summary>Copy the current file content into the temporary file.</summary>
/// <remarks>
/// Copy the current file content into the temporary file.
/// <p>
/// This method saves the current file content by inserting it into the
/// temporary file, so that the caller can safely append rather than replace
/// the primary file.
/// <p>
/// This method does nothing if the current file does not exist, or exists
/// but is empty.
/// </remarks>
/// <exception cref="System.IO.IOException">
/// the temporary file could not be written, or a read error
/// occurred while reading from the current file. The lock is
/// released before throwing the underlying IO exception to the
/// caller.
/// </exception>
/// <exception cref="Sharpen.RuntimeException">
/// the temporary file could not be written. The lock is released
/// before throwing the underlying exception to the caller.
/// </exception>
public virtual void CopyCurrentContent()
{
RequireLock();
try
{
FileInputStream fis = new FileInputStream(@ref);
try
{
if (fsync)
{
FileChannel @in = fis.GetChannel();
long pos = 0;
long cnt = @in.Size();
while (0 < cnt)
{
long r = os.GetChannel().TransferFrom(@in, pos, cnt);
pos += r;
cnt -= r;
}
}
else
{
byte[] buf = new byte[2048];
int r;
while ((r = fis.Read(buf)) >= 0)
{
os.Write(buf, 0, r);
}
}
}
finally
{
fis.Close();
}
}
catch (FileNotFoundException)
{
}
catch (IOException ioe)
{
// Don't worry about a file that doesn't exist yet, it
// conceptually has no current content to copy.
//
Unlock();
throw;
}
catch (RuntimeException ioe)
{
Unlock();
throw;
}
catch (Error ioe)
{
Unlock();
throw;
}
}
示例4: OpenStream
/// <exception cref="NGit.Errors.MissingObjectException"></exception>
/// <exception cref="System.IO.IOException"></exception>
public override ObjectStream OpenStream()
{
FileInputStream @in = new FileInputStream(p);
long sz = @in.GetChannel().Size();
int type = this.GetType();
BufferedInputStream b = new BufferedInputStream(@in);
return new ObjectStream.Filter(type, sz, b);
}
示例5: ReadFully
// do nothing
/// <summary>Read an entire local file into memory as a byte array.</summary>
/// <remarks>Read an entire local file into memory as a byte array.</remarks>
/// <param name="path">location of the file to read.</param>
/// <param name="max">
/// maximum number of bytes to read, if the file is larger than
/// this limit an IOException is thrown.
/// </param>
/// <returns>complete contents of the requested local file.</returns>
/// <exception cref="System.IO.FileNotFoundException">the file does not exist.</exception>
/// <exception cref="System.IO.IOException">the file exists, but its contents cannot be read.
/// </exception>
public static byte[] ReadFully(FilePath path, int max)
{
FileInputStream @in = new FileInputStream(path);
try
{
long sz = @in.GetChannel().Size();
if (sz > max)
{
throw new IOException(MessageFormat.Format(JGitText.Get().fileIsTooLarge, path));
}
byte[] buf = new byte[(int)sz];
int actSz = IOUtil.ReadFully(@in, buf, 0);
if (actSz == sz)
{
byte[] ret = new byte[actSz];
System.Array.Copy(buf, 0, ret, 0, actSz);
return ret;
}
return buf;
}
finally
{
try
{
@in.Close();
}
catch (IOException)
{
}
}
}