Skip to content

Commit b6e2d13

Browse files
committed
Close image stream outside of DiskCache,save(...)
1 parent bae94bd commit b6e2d13

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

library/src/com/nostra13/universalimageloader/cache/disc/DiscCacheAware.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ public interface DiscCacheAware {
4949

5050
/**
5151
* Saves image stream in disk cache.
52+
* Incoming image stream shouldn't be closed in this method.
5253
*
5354
* @param imageUri Original image URI
54-
* @param imageStream Input stream of image
55+
* @param imageStream Input stream of image (shouldn't be closed in this method)
5556
* @param listener Listener for saving progress, can be ignored if you don't use
5657
* {@linkplain com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener
5758
* progress listener} in ImageLoader calls

library/src/com/nostra13/universalimageloader/cache/disc/impl/BaseDiscCache.java

-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ public boolean save(String imageUri, InputStream imageStream, IoUtils.CopyListen
111111
IoUtils.closeSilently(os);
112112
}
113113
} finally {
114-
IoUtils.closeSilently(imageStream);
115114
if (loaded && !tmpFile.renameTo(imageFile)) {
116115
loaded = false;
117116
}

library/src/com/nostra13/universalimageloader/core/LoadAndDisplayImageTask.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ private boolean tryCacheImageOnDisk() throws TaskCancelledException {
288288

289289
private boolean downloadImage() throws IOException {
290290
InputStream is = getDownloader().getStream(uri, options.getExtraForDownloader());
291-
return configuration.diskCache.save(uri, is, this);
291+
try {
292+
return configuration.diskCache.save(uri, is, this);
293+
} finally {
294+
IoUtils.closeSilently(is);
295+
}
292296
}
293297

294298
/** Decodes image file into Bitmap, resize it and save it back */

0 commit comments

Comments
 (0)