diff options
| author | Bjorn Bringert <bringert@android.com> | 2010-12-02 11:34:28 +0000 |
|---|---|---|
| committer | Bjorn Bringert <bringert@android.com> | 2010-12-02 11:36:47 +0000 |
| commit | 212799338d7be336e73eb65de3dcd0338a705a11 (patch) | |
| tree | 6501a52a998b90d77fe660a4c0fe4e760f63ca46 | |
| parent | e41bb535a3aefa3f830d828f7f0ebfa6aee60f20 (diff) | |
| download | frameworks_base-212799338d7be336e73eb65de3dcd0338a705a11.zip frameworks_base-212799338d7be336e73eb65de3dcd0338a705a11.tar.gz frameworks_base-212799338d7be336e73eb65de3dcd0338a705a11.tar.bz2 | |
Only decrement mRemaining once in read().
In the old code AssetFileDescriptor.AutoCloseInputStream.read()
called super.read(), which calls read(byte[] buffer, int offset, int count),
which decrements mRemaining. Then read() decremented mRemaining again
after super.read() returned.
I'm extending the CTS tests for AssetFileDescriptor.AutoCloseInputStream
to cover this.
Bug: 3240844
Change-Id: I70b945abc773d3ce5c1317dad23a0d797b31f111
| -rw-r--r-- | core/java/android/content/res/AssetFileDescriptor.java | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/core/java/android/content/res/AssetFileDescriptor.java b/core/java/android/content/res/AssetFileDescriptor.java index 01ae1da..9893133 100644 --- a/core/java/android/content/res/AssetFileDescriptor.java +++ b/core/java/android/content/res/AssetFileDescriptor.java @@ -16,7 +16,6 @@ package android.content.res; -import android.os.MemoryFile; import android.os.Parcel; import android.os.ParcelFileDescriptor; import android.os.Parcelable; @@ -184,14 +183,9 @@ public class AssetFileDescriptor implements Parcelable { @Override public int read() throws IOException { - if (mRemaining >= 0) { - if (mRemaining == 0) return -1; - int res = super.read(); - if (res >= 0) mRemaining--; - return res; - } - - return super.read(); + byte[] buffer = new byte[1]; + int result = read(buffer, 0, 1); + return result == -1 ? -1 : buffer[0] & 0xff; } @Override @@ -209,16 +203,7 @@ public class AssetFileDescriptor implements Parcelable { @Override public int read(byte[] buffer) throws IOException { - if (mRemaining >= 0) { - if (mRemaining == 0) return -1; - int count = buffer.length; - if (count > mRemaining) count = (int)mRemaining; - int res = super.read(buffer, 0, count); - if (res >= 0) mRemaining -= res; - return res; - } - - return super.read(buffer); + return read(buffer, 0, buffer.length); } @Override @@ -231,7 +216,6 @@ public class AssetFileDescriptor implements Parcelable { return res; } - // TODO Auto-generated method stub return super.skip(count); } |
