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.
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.