summaryrefslogtreecommitdiffstats
path: root/core/java/android/os
diff options
context:
space:
mode:
authorBjorn Bringert <bringert@android.com>2009-06-03 04:56:52 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-06-03 04:56:52 -0700
commitb15a5348e6586c143bd7027574f7574433874131 (patch)
tree6759b4399ae10474cce28b6ea80d96b0c19d135c /core/java/android/os
parentc0cbfda0fe0184bbb282bde4d894e2ff210c0e47 (diff)
parentc1823701cc76790494fb622fe58f0942236cd7d0 (diff)
downloadframeworks_base-b15a5348e6586c143bd7027574f7574433874131.zip
frameworks_base-b15a5348e6586c143bd7027574f7574433874131.tar.gz
frameworks_base-b15a5348e6586c143bd7027574f7574433874131.tar.bz2
am c1823701: Handle EOF correctly in MemoryFile input stream.
Merge commit 'c1823701cc76790494fb622fe58f0942236cd7d0' * commit 'c1823701cc76790494fb622fe58f0942236cd7d0': Handle EOF correctly in MemoryFile input stream.
Diffstat (limited to 'core/java/android/os')
-rw-r--r--core/java/android/os/MemoryFile.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/core/java/android/os/MemoryFile.java b/core/java/android/os/MemoryFile.java
index 7e4cf8a..c14925c 100644
--- a/core/java/android/os/MemoryFile.java
+++ b/core/java/android/os/MemoryFile.java
@@ -353,13 +353,22 @@ public class MemoryFile
}
int result = read(mSingleByte, 0, 1);
if (result != 1) {
- throw new IOException("read() failed");
+ return -1;
}
return mSingleByte[0];
}
@Override
public int read(byte buffer[], int offset, int count) throws IOException {
+ if (offset < 0 || count < 0 || offset + count > buffer.length) {
+ // readBytes() also does this check, but we need to do it before
+ // changing count.
+ throw new IndexOutOfBoundsException();
+ }
+ count = Math.min(count, available());
+ if (count < 1) {
+ return -1;
+ }
int result = readBytes(buffer, mOffset, offset, count);
if (result > 0) {
mOffset += result;