The solution provided in android bug n°6066 consist in overriding the std FilterInputStream and then send it to the BitmapFactory.
static class FlushedInputStream extends FilterInputStream {
public FlushedInputStream(InputStream inputStream) {
super(inputStream);
}
@Override
public long skip(long n) throws IOException {
long totalBytesSkipped = 0L;
while (totalBytesSkipped < n) {
long bytesSkipped = in.skip(n - totalBytesSkipped);
if (bytesSkipped == 0L) {
int byteValue = read();
if (byteValue < 0) {
break; // we reached EOF
} else {
bytesSkipped = 1; // we read one byte
}
}
totalBytesSkipped += bytesSkipped;
}
return totalBytesSkipped;
}
}
and then use the decodeStream function:
Bitmap bitmap = BitmapFactory.decodeStream(new FlushedInputStream(inputStream));
The other solution i've found is to simply give a BufferedInputStream to th BitmapFactory:
Bitmap bitmap = BitmapFactory.decodeStream(new BufferedInputStream(inputStream));
These two solutions should do the trick.
More information can be found in the bug report comments : android bug no.6066