Forums Register Login

JAVA HEAP SIZE and files to byte[]-Array

+Pie Number of slices to send: Send
Hello,

I have a WAR-Application.

I have a site in which Users can upload files (java.io.File).

These files are converted into a byte[]-Array to store it as a BLOB in the database. All works fine. But when the file is larger than the maximum JAVA HEAP SIZE than this error occurs:



I use the Apaches Commons "FileUtils.readFileToByteArray()"-Method to convert from File to byte[]. Also, the Apaches "IOUtils.toByteArray(new FileInputStream(myfile)))" returns a java.lang.OutOfMemoryError.

I know, I have to set the "Java heap space" to a higher value, but this is not always possible.

Is there a way to handle such big files without exceeding the "Java heap space".

I also tried this http://balusc.blogspot.com/2007/07/fileservlet.html, but without success.

Is there a way, maybe with the new NIO-API to handle such scenarios in a performant way?
+Pie Number of slices to send: Send
Write the file as the data comes in, store in the database only the name of the file.

Bill
+Pie Number of slices to send: Send
yes,

indeed, this would be the simplest solution (by the way, and this way I would be able to upload more than 2GB)

however, I guess, my problem is more I/O-specific. So I would like to move that topic under category:

I/O and Streams

to find a solution for converting files into byte[] via java.io or java.nio without exceeding or editing the heap-size.

https://coderanch.com/t/449055/Streams/java/JAVA-HEAP-SIZE-files-byte
I can't beleive you just said that. Now I need to calm down with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 5725 times.
Similar Threads
exception while Read very large file > 300 MB
exception while Read very large file > 300 MB
Problem in using java to Store 1GB+ files in a MySQL database
Write and Update CSV files
file downloading concept
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 05:06:54.