OutputStream from a URLConnection produces an OutOfMemory OutputStream from a URLConnection produc

W

WinstonSmith_101

OutputStream from a URLConnection produces an OutOfMemory Exception on
large files

I need to upload large files (up to 2 gigabytes) to an Apache
webserver. This works fine with smaller files, however as soon as they
go over a certain size, java dumps with a: java.lang.OutOfMemoryError:
Java heap space.

Apparently this is a feature. The error results from HttpURLConnection
returning a ByteArrayOutputStream, so the file is stored in memory
before being send to the webserver - and no amount of flushing is
going to alter that. See e.g.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4212479
- this bug/feature is fairly old and here is suggested a more recent
workaround: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5026745
.. But this too produces an out-of-memory exception with me (and I'm not
sure the users will have the absolutely latest Java version installed)

Is there a way for to get this to work so I can upload larger files
without running out of memory?

Else I'd start experiment with this package: HTTPClient :
http://www.innovation.ch/java/HTTPClient/

Perhaps this can handle larger files. but I already have everything
else working, so I'd be loathe to start to replace it all with a new
library if there was an acceptable way to implement uploads of larger
files just with the standard Java libraries.
 
P

power_generator_set

Winston,

My guess is that one way of solving this would be to throw memory at
your machine;
at least a few gigs. Then you need to modify the initial an maximum
heap
size when you launch your application:

java -Xms3000m -Xmx3000m -classpath rt.jar:someclasspath
YourApplication

If you don't have memory, then I would think about redesigning your
code
to see if you could do it with some object like a BufferedOutputStream
with
a FileWriter.

Morris
Generatormart, LLC.
http://www.generatormart.com
Diesel generator classified ads.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top