• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAVA HEAP SIZE and files to byte[]-Array

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write the file as the data comes in, store in the database only the name of the file.

Bill
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic