Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageLoader - problem with trying to get the image size #32

Open
paulononaka opened this issue May 15, 2011 · 1 comment
Open

ImageLoader - problem with trying to get the image size #32

paulononaka opened this issue May 15, 2011 · 1 comment

Comments

@paulononaka
Copy link

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);  
    }
@yautah
Copy link

yautah commented Jul 20, 2011

yes..it's the same solution for me

: )

should merge in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants