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.