mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 14:15:44 +03:00
Merge pull request #9862 from nextcloud/fixLeakedCloseableViolation
Fix LeakedCloseableViolations in getScaledBitmap
This commit is contained in:
commit
c9018f8ba6
2 changed files with 22 additions and 43 deletions
|
@ -1 +1 @@
|
|||
641
|
||||
642
|
||||
|
|
|
@ -106,22 +106,18 @@ public class DiskLruImageCache {
|
|||
|
||||
public Bitmap getScaledBitmap(String key, int width, int height) {
|
||||
Bitmap bitmap = null;
|
||||
DiskLruCache.Snapshot snapshot = null;
|
||||
InputStream inputStream = null;
|
||||
BufferedInputStream buffIn = null;
|
||||
String validKey = convertToValidKey(key);
|
||||
|
||||
try {
|
||||
snapshot = mDiskCache.get(validKey);
|
||||
try (DiskLruCache.Snapshot snapshot = mDiskCache.get(validKey)) {
|
||||
if (snapshot == null) {
|
||||
return null;
|
||||
}
|
||||
inputStream = snapshot.getInputStream(0);
|
||||
if (inputStream != null) {
|
||||
buffIn = new BufferedInputStream(inputStream, IO_BUFFER_SIZE);
|
||||
|
||||
InputStream inputStream = snapshot.getInputStream(0);
|
||||
if (inputStream != null) {
|
||||
// First decode with inJustDecodeBounds=true to check dimensions
|
||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
try (BufferedInputStream buffIn = new BufferedInputStream(inputStream, IO_BUFFER_SIZE)) {
|
||||
options.inScaled = true;
|
||||
options.inPurgeable = true;
|
||||
options.inPreferQualityOverSpeed = false;
|
||||
|
@ -129,11 +125,12 @@ public class DiskLruImageCache {
|
|||
options.inJustDecodeBounds = true;
|
||||
|
||||
BitmapFactory.decodeStream(buffIn, null, options);
|
||||
}
|
||||
|
||||
snapshot = mDiskCache.get(validKey);
|
||||
inputStream = snapshot.getInputStream(0);
|
||||
buffIn = new BufferedInputStream(inputStream, IO_BUFFER_SIZE);
|
||||
try (DiskLruCache.Snapshot snapshot2 = mDiskCache.get(validKey)) {
|
||||
inputStream = snapshot2.getInputStream(0);
|
||||
|
||||
try (BufferedInputStream buffIn = new BufferedInputStream(inputStream, IO_BUFFER_SIZE)) {
|
||||
// Calculate inSampleSize
|
||||
options.inSampleSize = BitmapUtils.calculateSampleFactor(options, width, height);
|
||||
|
||||
|
@ -141,28 +138,10 @@ public class DiskLruImageCache {
|
|||
options.inJustDecodeBounds = false;
|
||||
bitmap = BitmapFactory.decodeStream(buffIn, null, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, e.getMessage(), e);
|
||||
} finally {
|
||||
if (snapshot != null) {
|
||||
snapshot.close();
|
||||
}
|
||||
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
if (buffIn != null) {
|
||||
try {
|
||||
buffIn.close();
|
||||
} catch (IOException e) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
|
Loading…
Reference in a new issue