Loading graphics/java/android/graphics/ImageDecoder.java +19 −7 Original line number Diff line number Diff line Loading @@ -148,7 +148,7 @@ public final class ImageDecoder implements AutoCloseable { throw new FileNotFoundException(mUri.toString()); } return createFromStream(is); return createFromStream(is, true); } final FileDescriptor fd = assetFd.getFileDescriptor(); Loading @@ -160,7 +160,7 @@ public final class ImageDecoder implements AutoCloseable { Os.lseek(fd, offset, SEEK_SET); decoder = nCreate(fd); } catch (ErrnoException e) { decoder = createFromStream(new FileInputStream(fd)); decoder = createFromStream(new FileInputStream(fd), true); } } finally { if (decoder == null) { Loading @@ -180,7 +180,7 @@ public final class ImageDecoder implements AutoCloseable { try { Os.lseek(fd, 0, SEEK_CUR); } catch (ErrnoException e) { return createFromStream(stream); return createFromStream(stream, true); } ImageDecoder decoder = null; Loading @@ -191,13 +191,15 @@ public final class ImageDecoder implements AutoCloseable { IoUtils.closeQuietly(stream); } else { decoder.mInputStream = stream; decoder.mOwnsInputStream = true; } } return decoder; } @NonNull private static ImageDecoder createFromStream(@NonNull InputStream is) throws IOException { private static ImageDecoder createFromStream(@NonNull InputStream is, boolean closeInputStream) throws IOException { // Arbitrary size matches BitmapFactory. byte[] storage = new byte[16 * 1024]; ImageDecoder decoder = null; Loading @@ -205,9 +207,12 @@ public final class ImageDecoder implements AutoCloseable { decoder = nCreate(is, storage); } finally { if (decoder == null) { if (closeInputStream) { IoUtils.closeQuietly(is); } } else { decoder.mInputStream = is; decoder.mOwnsInputStream = closeInputStream; decoder.mTempStorage = storage; } } Loading @@ -215,6 +220,9 @@ public final class ImageDecoder implements AutoCloseable { return decoder; } /** * For backwards compatibility, this does *not* close the InputStream. */ private static class InputStreamSource extends Source { InputStreamSource(Resources res, InputStream is, int inputDensity) { if (is == null) { Loading Loading @@ -244,7 +252,7 @@ public final class ImageDecoder implements AutoCloseable { } InputStream is = mInputStream; mInputStream = null; return createFromStream(is); return createFromStream(is, false); } } } Loading Loading @@ -293,6 +301,7 @@ public final class ImageDecoder implements AutoCloseable { IoUtils.closeQuietly(is); } else { decoder.mInputStream = is; decoder.mOwnsInputStream = true; } } return decoder; Loading Loading @@ -436,6 +445,7 @@ public final class ImageDecoder implements AutoCloseable { // Objects for interacting with the input. private InputStream mInputStream; private boolean mOwnsInputStream; private byte[] mTempStorage; private AssetFileDescriptor mAssetFd; private final AtomicBoolean mClosed = new AtomicBoolean(); Loading Loading @@ -811,7 +821,9 @@ public final class ImageDecoder implements AutoCloseable { nClose(mNativePtr); mNativePtr = 0; if (mOwnsInputStream) { IoUtils.closeQuietly(mInputStream); } IoUtils.closeQuietly(mAssetFd); mInputStream = null; Loading Loading
graphics/java/android/graphics/ImageDecoder.java +19 −7 Original line number Diff line number Diff line Loading @@ -148,7 +148,7 @@ public final class ImageDecoder implements AutoCloseable { throw new FileNotFoundException(mUri.toString()); } return createFromStream(is); return createFromStream(is, true); } final FileDescriptor fd = assetFd.getFileDescriptor(); Loading @@ -160,7 +160,7 @@ public final class ImageDecoder implements AutoCloseable { Os.lseek(fd, offset, SEEK_SET); decoder = nCreate(fd); } catch (ErrnoException e) { decoder = createFromStream(new FileInputStream(fd)); decoder = createFromStream(new FileInputStream(fd), true); } } finally { if (decoder == null) { Loading @@ -180,7 +180,7 @@ public final class ImageDecoder implements AutoCloseable { try { Os.lseek(fd, 0, SEEK_CUR); } catch (ErrnoException e) { return createFromStream(stream); return createFromStream(stream, true); } ImageDecoder decoder = null; Loading @@ -191,13 +191,15 @@ public final class ImageDecoder implements AutoCloseable { IoUtils.closeQuietly(stream); } else { decoder.mInputStream = stream; decoder.mOwnsInputStream = true; } } return decoder; } @NonNull private static ImageDecoder createFromStream(@NonNull InputStream is) throws IOException { private static ImageDecoder createFromStream(@NonNull InputStream is, boolean closeInputStream) throws IOException { // Arbitrary size matches BitmapFactory. byte[] storage = new byte[16 * 1024]; ImageDecoder decoder = null; Loading @@ -205,9 +207,12 @@ public final class ImageDecoder implements AutoCloseable { decoder = nCreate(is, storage); } finally { if (decoder == null) { if (closeInputStream) { IoUtils.closeQuietly(is); } } else { decoder.mInputStream = is; decoder.mOwnsInputStream = closeInputStream; decoder.mTempStorage = storage; } } Loading @@ -215,6 +220,9 @@ public final class ImageDecoder implements AutoCloseable { return decoder; } /** * For backwards compatibility, this does *not* close the InputStream. */ private static class InputStreamSource extends Source { InputStreamSource(Resources res, InputStream is, int inputDensity) { if (is == null) { Loading Loading @@ -244,7 +252,7 @@ public final class ImageDecoder implements AutoCloseable { } InputStream is = mInputStream; mInputStream = null; return createFromStream(is); return createFromStream(is, false); } } } Loading Loading @@ -293,6 +301,7 @@ public final class ImageDecoder implements AutoCloseable { IoUtils.closeQuietly(is); } else { decoder.mInputStream = is; decoder.mOwnsInputStream = true; } } return decoder; Loading Loading @@ -436,6 +445,7 @@ public final class ImageDecoder implements AutoCloseable { // Objects for interacting with the input. private InputStream mInputStream; private boolean mOwnsInputStream; private byte[] mTempStorage; private AssetFileDescriptor mAssetFd; private final AtomicBoolean mClosed = new AtomicBoolean(); Loading Loading @@ -811,7 +821,9 @@ public final class ImageDecoder implements AutoCloseable { nClose(mNativePtr); mNativePtr = 0; if (mOwnsInputStream) { IoUtils.closeQuietly(mInputStream); } IoUtils.closeQuietly(mAssetFd); mInputStream = null; Loading