You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// 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();
}
The text was updated successfully, but these errors were encountered:
guangyu2002
changed the title
NPOI.Util.IOUtils中ToByteArray方法,ByteArrayOutputStream创建后是否未Dispose,是否会有内存泄露的bug呢?
NPOI.Util.IOUtils中ToByteArray方法,ByteArrayOutputStream创建后未Dispose,是否会有内存泄露的bug呢?
Jul 17, 2024
tonyqus
changed the title
NPOI.Util.IOUtils中ToByteArray方法,ByteArrayOutputStream创建后未Dispose,是否会有内存泄露的bug呢?
ByteArrayOutputStream is not disposed in NPOI.Util.IOUtils.ToByteArray method. Potential Memory leak
Jul 17, 2024
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);
The text was updated successfully, but these errors were encountered: