/// <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)
{
}
}
}