summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorJesse Wilson <jessewilson@google.com>2011-08-18 16:17:19 -0400
committerJesse Wilson <jessewilson@google.com>2011-08-18 16:17:19 -0400
commitdf84cec32f3c1f71ea781e5f851724d84c35e620 (patch)
tree4d7d6b9184be424f568880148bea503f44a9735a /luni
parent701cca146e1ac80f3fa58c53223aa7a462078c7c (diff)
downloadlibcore-df84cec32f3c1f71ea781e5f851724d84c35e620.zip
libcore-df84cec32f3c1f71ea781e5f851724d84c35e620.tar.gz
libcore-df84cec32f3c1f71ea781e5f851724d84c35e620.tar.bz2
Fix JarInputStream Manifest parsing.
I recently broke JarInputStream by changing Streams.readFully() to unconditionally close the input stream when it was exhausted. Although most streams won't return data after read() returns -1, both JAR and ZIP streams can return data after a call to get the next entry. Change-Id: I2fcef44aaeae0ac27c9fa5a7a4996c5b1b794964
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/util/jar/Manifest.java2
-rw-r--r--luni/src/main/java/libcore/io/Streams.java21
2 files changed, 15 insertions, 8 deletions
diff --git a/luni/src/main/java/java/util/jar/Manifest.java b/luni/src/main/java/java/util/jar/Manifest.java
index c1c96a1..d46aea3 100644
--- a/luni/src/main/java/java/util/jar/Manifest.java
+++ b/luni/src/main/java/java/util/jar/Manifest.java
@@ -199,7 +199,7 @@ public class Manifest implements Cloneable {
if (is instanceof ByteArrayInputStream) {
buf = exposeByteArrayInputStreamBytes((ByteArrayInputStream) is);
} else {
- buf = Streams.readFully(is);
+ buf = Streams.readFullyNoClose(is);
}
if (buf.length == 0) {
diff --git a/luni/src/main/java/libcore/io/Streams.java b/luni/src/main/java/libcore/io/Streams.java
index ab8795c..cbad4a4 100644
--- a/luni/src/main/java/libcore/io/Streams.java
+++ b/luni/src/main/java/libcore/io/Streams.java
@@ -92,19 +92,26 @@ public final class Streams {
*/
public static byte[] readFully(InputStream in) throws IOException {
try {
- ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int count;
- while ((count = in.read(buffer)) != -1) {
- bytes.write(buffer, 0, count);
- }
- return bytes.toByteArray();
+ return readFullyNoClose(in);
} finally {
in.close();
}
}
/**
+ * Returns a byte[] containing the remainder of 'in'.
+ */
+ public static byte[] readFullyNoClose(InputStream in) throws IOException {
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int count;
+ while ((count = in.read(buffer)) != -1) {
+ bytes.write(buffer, 0, count);
+ }
+ return bytes.toByteArray();
+ }
+
+ /**
* Returns the remainder of 'reader' as a string, closing it when done.
*/
public static String readFully(Reader reader) throws IOException {