wood burning stoves 2.0*
The moose likes Performance and the fly likes JAVA HEAP SIZE and files to byte[]-Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "JAVA HEAP SIZE and files to byte[]-Array" Watch "JAVA HEAP SIZE and files to byte[]-Array" New topic
Author

JAVA HEAP SIZE and files to byte[]-Array

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12783
    
    5
Write the file as the data comes in, store in the database only the name of the file.

Bill
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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.

http://www.coderanch.com/t/449055/Streams/java/JAVA-HEAP-SIZE-files-byte
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAVA HEAP SIZE and files to byte[]-Array