From 90fcf3599d8450e64e6788504972419cc7184d5a Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Fri, 23 Jan 2015 10:09:59 +0000 Subject: Don't discard directory entries in jar files. This is a structural change, and breaks code that looks up directory resource names (icu4j for example). This change also includes a minor cosmetic change to use a while() loop instead of for(;;). bug: 19108324 (cherry picked from commit 7736e8ff04c2974edd9de9ca150f12dc601b005d) Change-Id: Ifcbc60cc7808334cdfdd4f27bf137a8f6455117d --- .../com/android/dx/cf/direct/ClassPathOpener.java | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/dx/src/com/android/dx/cf/direct/ClassPathOpener.java b/dx/src/com/android/dx/cf/direct/ClassPathOpener.java index c9fe275cd..26fbca029 100644 --- a/dx/src/com/android/dx/cf/direct/ClassPathOpener.java +++ b/dx/src/com/android/dx/cf/direct/ClassPathOpener.java @@ -242,9 +242,6 @@ public class ClassPathOpener { */ private boolean processArchive(File file) throws IOException { ZipFile zip = new ZipFile(file); - ByteArrayOutputStream baos = new ByteArrayOutputStream(40000); - byte[] buf = new byte[20000]; - boolean any = false; ArrayList entriesList = Collections.list(zip.entries()); @@ -259,28 +256,31 @@ public class ClassPathOpener { consumer.onProcessArchiveStart(file); + ByteArrayOutputStream baos = new ByteArrayOutputStream(40000); + byte[] buf = new byte[20000]; + boolean any = false; + for (ZipEntry one : entriesList) { - if (one.isDirectory()) { - continue; - } + final boolean isDirectory = one.isDirectory(); String path = one.getName(); if (filter.accept(path)) { - InputStream in = zip.getInputStream(one); - - baos.reset(); - for (;;) { - int amt = in.read(buf); - if (amt < 0) { - break; + final byte[] bytes; + if (!isDirectory) { + InputStream in = zip.getInputStream(one); + + baos.reset(); + int read; + while ((read = in.read(buf)) != -1) { + baos.write(buf, 0, read); } - baos.write(buf, 0, amt); + in.close(); + bytes = baos.toByteArray(); + } else { + bytes = new byte[0]; } - in.close(); - - byte[] bytes = baos.toByteArray(); any |= consumer.processFileBytes(path, one.getTime(), bytes); } } -- cgit v1.2.3