mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
switch back to BufferedInputStream
// FREEBIE
This commit is contained in:
parent
1d7b47c982
commit
2075bba86c
@ -11,6 +11,7 @@ import android.graphics.Rect;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -96,7 +97,7 @@ public class BitmapUtil {
|
|||||||
options.inSampleSize = scaler;
|
options.inSampleSize = scaler;
|
||||||
options.inJustDecodeBounds = false;
|
options.inJustDecodeBounds = false;
|
||||||
|
|
||||||
FlushedInputStream is = new FlushedInputStream(data);
|
BufferedInputStream is = new BufferedInputStream(data);
|
||||||
Bitmap roughThumbnail = BitmapFactory.decodeStream(is, null, options);
|
Bitmap roughThumbnail = BitmapFactory.decodeStream(is, null, options);
|
||||||
try {
|
try {
|
||||||
is.close();
|
is.close();
|
||||||
@ -143,7 +144,7 @@ public class BitmapUtil {
|
|||||||
private static BitmapFactory.Options getImageDimensions(InputStream inputStream) {
|
private static BitmapFactory.Options getImageDimensions(InputStream inputStream) {
|
||||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||||
options.inJustDecodeBounds = true;
|
options.inJustDecodeBounds = true;
|
||||||
FlushedInputStream fis = new FlushedInputStream(inputStream);
|
BufferedInputStream fis = new BufferedInputStream(inputStream);
|
||||||
BitmapFactory.decodeStream(fis, null, options);
|
BitmapFactory.decodeStream(fis, null, options);
|
||||||
try {
|
try {
|
||||||
fis.close();
|
fis.close();
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user