droid-fu icon indicating copy to clipboard operation
droid-fu copied to clipboard

ImageLoader - problem with trying to get the image size

Open paulononaka opened this issue 13 years ago • 1 comments

Not always a image's server setting a "Content-Length" header in the response message, so ImageLoader class can't download it. The method retrieveImageData() is expecting the size:

    int fileSize = connection.getContentLength();
    if (fileSize < 0) {
        return null;
    }
    //...
    while (bytesRead != -1 && offset < fileSize) {
        bytesRead = istream.read(imageData, offset, fileSize - offset);
        imageData.write(buffer, offset, len)
        offset += bytesRead;
    }

I suggest using the ByteArrayOutputStream class:

    ByteArrayOutputStream imageData = new ByteArrayOutputStream();
    BufferedInputStream istream = new BufferedInputStream(connection.getInputStream());
    int bytesRead = 0;
    int bufferSize = 1024;
    byte[] buffer = new byte[bufferSize];
    while ((bytesRead = istream.read(buffer)) != -1) {  
        imageData.write(buffer, 0, bytesRead);  
    }

paulononaka avatar May 15 '11 03:05 paulononaka

yes..it's the same solution for me

: )

should merge in master

yautah avatar Jul 20 '11 09:07 yautah