OutOfMemoryError

M

Marcelo

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
 
B

Ben_

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

Roedy Green

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.
 

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,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top