Skip to content

Image is blank after download is finished #29

@yifengj

Description

@yifengj

I found a bug in ignition-support library when using RemoteImageLoader to downloading images. Some images will not download correctly after finished downloading, especially on some mobile networks.

The root cause is in these lines in RemoteImageLoaderJob.java:
int fileSize = connection.getContentLength();
...
byte[] imageData = new byte[fileSize];

            int bytesRead = 0;
            int offset = 0;
            while (bytesRead != -1 && offset < fileSize) {
                bytesRead = istream.read(imageData, offset, fileSize - offset);
                offset += bytesRead;
            }

According to Android documentation of HttpURLConnection, "By default, this implementation of HttpURLConnection requests that servers use gzip compression. Since getContentLength() returns the number of bytes transmitted, you cannot use that method to predict how many bytes can be read from getInputStream().".

So when compression in use, getContentLength() will return bytes less than the total size of image data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions