I am experiencing a memory problem that I do not understand. I have the following case
Case 1
public byte[] getBytes(InputStream is) throws IOException {
int len;
int size = 1024;
byte[] buf;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
buf = new byte[size];
while ((len = is.read(buf, 0, size)) != -1)
{
bos.write(buf, 0, len);
}
buf = bos.toByteArray();
return buf;
}
Public void dosomething()
{
//instructions
InputStream is = new ByteArrayInputStream(getBytes(bodyPart.getInputStream()));
}
Work fine without error
but this
Case 2
Public void dosomething()
{
//instructions
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int len;
int size = 1024;
byte[] bufferFichierEntree = new byte[size];
while ((len = bodyPart.getInputStream().read(bufferFichierEntree, 0, size)) != -1)
{
bos.write(bufferFichierEntree, 0, len);
}
InputStream is = new ByteArrayInputStream(bufferFichierEntree);
}
return a java.lang.OutOfMemoryError: Java heap space and a don t know why ? The only difference is that in the first case i use a function unlike the second case
getInputStreamto know what it's doing.