switch back to BufferedInputStream

// FREEBIE
This commit is contained in:
Jake McGinty 2014-09-30 12:53:34 -07:00
parent 1d7b47c982
commit 2075bba86c
2 changed files with 4 additions and 36 deletions

View File

@ -11,6 +11,7 @@ import android.graphics.Rect;
import android.net.Uri;
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -96,7 +97,7 @@ public class BitmapUtil {
options.inSampleSize = scaler;
options.inJustDecodeBounds = false;
FlushedInputStream is = new FlushedInputStream(data);
BufferedInputStream is = new BufferedInputStream(data);
Bitmap roughThumbnail = BitmapFactory.decodeStream(is, null, options);
try {
is.close();
@ -143,7 +144,7 @@ public class BitmapUtil {
private static BitmapFactory.Options getImageDimensions(InputStream inputStream) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
FlushedInputStream fis = new FlushedInputStream(inputStream);
BufferedInputStream fis = new BufferedInputStream(inputStream);
BitmapFactory.decodeStream(fis, null, options);
try {
fis.close();

View File

@ -1,33 +0,0 @@
package org.thoughtcrime.securesms.util;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Memory-friendly workaround found from https://code.google.com/p/android/issues/detail?id=6066#c23
* to solve decoding problems in bitmaps from InputStreams that don't skip if no more stream is available.
*/
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 inByte = read();
if (inByte < 0) {
break;
} else {
bytesSkipped = 1;
}
}
totalBytesSkipped += bytesSkipped;
}
return totalBytesSkipped;
}
}