From df84cec32f3c1f71ea781e5f851724d84c35e620 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Thu, 18 Aug 2011 16:17:19 -0400 Subject: 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 --- luni/src/main/java/java/util/jar/Manifest.java | 2 +- luni/src/main/java/libcore/io/Streams.java | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'luni') 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 { -- cgit v1.1