From 2075bba86c90a59f2e027c3045607f67a1e41817 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Tue, 30 Sep 2014 12:53:34 -0700 Subject: [PATCH] switch back to BufferedInputStream // FREEBIE --- .../securesms/util/BitmapUtil.java | 7 ++-- .../securesms/util/FlushedInputStream.java | 33 ------------------- 2 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 src/org/thoughtcrime/securesms/util/FlushedInputStream.java diff --git a/src/org/thoughtcrime/securesms/util/BitmapUtil.java b/src/org/thoughtcrime/securesms/util/BitmapUtil.java index a8111d6e37..3ec53d1a28 100644 --- a/src/org/thoughtcrime/securesms/util/BitmapUtil.java +++ b/src/org/thoughtcrime/securesms/util/BitmapUtil.java @@ -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,8 +97,8 @@ public class BitmapUtil { options.inSampleSize = scaler; options.inJustDecodeBounds = false; - FlushedInputStream is = new FlushedInputStream(data); - Bitmap roughThumbnail = BitmapFactory.decodeStream(is, null, options); + BufferedInputStream is = new BufferedInputStream(data); + Bitmap roughThumbnail = BitmapFactory.decodeStream(is, null, options); try { is.close(); } catch (IOException ioe) { @@ -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(); diff --git a/src/org/thoughtcrime/securesms/util/FlushedInputStream.java b/src/org/thoughtcrime/securesms/util/FlushedInputStream.java deleted file mode 100644 index 3f6636a59f..0000000000 --- a/src/org/thoughtcrime/securesms/util/FlushedInputStream.java +++ /dev/null @@ -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; - } -}