Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
WinstonSmith_101@hotmail.com - 25 Oct 2006 14:01 GMT
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.
Thomas Weidenfeller - 25 Oct 2006 14:17 GMT
> Is there a way for to get this to work so I can upload larger files
> without running out of memory?

http://jakarta.apache.org/commons/httpclient/

/Thomas
Signature

The comp.lang.java.gui FAQ:
http://gd.tuwien.ac.at/faqs/faqs-hierarchy/comp/comp.lang.java.gui/
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

power_generator_set@yahoo.com - 25 Oct 2006 17:45 GMT
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.

> OutputStream from a URLConnection produces an OutOfMemory Exception on
> large files
[quoted text clipped - 24 lines]
> library if there was an acceptable way to implement uploads of larger
> files just with the standard Java libraries.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.