clcron / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
1 stars 0 forks source link

ByteStreams.toByteArray(inputStream); and java.lang.OutOfMemoryError: Java heap space #551

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. When you want to create an array of bytes from the stream for files over 300 
megabytes in size using the function ByteStreams.toByteArray (InputStream), 
gets the output exception: java.lang.OutOfMemoryError: Java heap space

What version of the product are you using? On what operating system?
guava-r08.jar. Windows 7 64-bit and windows XP 32-bit. Eclipse Helios JEE SR1

Please provide any additional information below.
PrintScreen in attachment.

Original issue reported on code.google.com by ptr.nowi...@gmail.com on 18 Feb 2011 at 3:42

Attachments:

GoogleCodeExporter commented 9 years ago
This doesn't have anything to do with ByteStreams.toByteArray. 300 MB is 
generally too much to be loading into memory, and it isn't necessary at all in 
your example. What you should be doing is this:

    CRC32 crc32 = new CRC32();
    File file = new File("test.zip");
    long checksum = ByteStreams.getChecksum(
        Files.newInputStreamSupplier(file), crc32);

Original comment by cgdec...@gmail.com on 18 Feb 2011 at 4:32

GoogleCodeExporter commented 9 years ago
Thanks, problem solved.

Original comment by ptr.nowi...@gmail.com on 18 Feb 2011 at 5:43

GoogleCodeExporter commented 9 years ago

Original comment by cgdec...@gmail.com on 18 Feb 2011 at 9:46

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09