///
/// Reads up to {@code length} bytes from the input stream, and returns the bytes read.
///
///
///
///
public static byte[] ToByteArray(Stream stream, int length)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream(length == Int32.MaxValue ? 4096 : length);
byte[] buffer = new byte[4096];
int totalBytes = 0, readBytes;
do
{
readBytes = stream.Read(buffer, 0, Math.Min(buffer.Length, length - totalBytes));
totalBytes += Math.Max(readBytes, 0);
if (readBytes > 0)
{
baos.Write(buffer, 0, readBytes);
}
} while (totalBytes < length && readBytes > 0);
if (length != Int32.MaxValue && totalBytes < length)
{
throw new IOException("unexpected EOF");
}
return baos.ToByteArray();
}
NPOI Version
2.7.1-rc1
File Type
Issue Description
///
/// Reads up to {@code length} bytes from the input stream, and returns the bytes read.
///
///
///
///
public static byte[] ToByteArray(Stream stream, int length)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream(length == Int32.MaxValue ? 4096 : length);