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 / November 2005

Tip: Looking for answers? Try searching our database.

OutOfMemoryError

Thread view: 
Marcelo - 07 Nov 2005 22:05 GMT
Dear programmers,

I am having the following message whenever I do a massive retrieve of
images.

The program has some threads that saves an images from the internet to
my hard-disk, however, because I don't know the size of these images, I
have put
int MAX_IMAGE_SIZE = 5000000;

for the buffer.

And obviously I get the error-message

Exception in thread "Thread-17" java.lang.OutOfMemoryError: Java heap space

How can i know the Size of my image before downloading it ? Is it
possible to give a maximum size of 5Mpix without having this problem?

thank you for your advises,

Marcelo
Ben_ - 07 Nov 2005 22:20 GMT
You download them with an HTTP request, I suppose ?

You can get the size with URLConnection.getContentLength (or similar --
depends on the API you use), if the server bothered specifying the length.

Anyway, you can read it and write it progressively in small chunks.  You
need not necessarily keep all the image in a single large buffer in memory,
especially, when you simply have to save the file to disk.
Roedy Green - 08 Nov 2005 02:59 GMT
>How can i know the Size of my image before downloading it ? Is it
>possible to give a maximum size of 5Mpix without having this problem?

There is an http header request that will often tell you the length,
date etc.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 08 Nov 2005 03:00 GMT
>The program has some threads that saves an images from the internet to
>my hard-disk, however, because I don't know the size of these images, I
>have put
>int MAX_IMAGE_SIZE = 5000000;
>
>for the buffer.

see http://mindprod.com/products1.html#FILETRANSFER

it downloads in chunks.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



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



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