Commit 8ecc6161 authored by User's avatar User Committed by Evan W. Patton

Update AARLibrary.java (#1103)

Fix IO not closed  properly.
parent 053c7b33
...@@ -229,8 +229,6 @@ public class AARLibrary { ...@@ -229,8 +229,6 @@ public class AARLibrary {
*/ */
public void unpackToDirectory(final File path) throws IOException { public void unpackToDirectory(final File path) throws IOException {
ZipFile zip = null; ZipFile zip = null;
InputStream input = null;
OutputStream output = null;
try { try {
zip = new ZipFile(aarPath); zip = new ZipFile(aarPath);
packageName = extractPackageName(zip); packageName = extractPackageName(zip);
...@@ -238,6 +236,8 @@ public class AARLibrary { ...@@ -238,6 +236,8 @@ public class AARLibrary {
if (!basedir.mkdirs()) { if (!basedir.mkdirs()) {
throw new IOException("Unable to create directory for AAR package"); throw new IOException("Unable to create directory for AAR package");
} }
InputStream input = null;
OutputStream output = null;
Enumeration<? extends ZipEntry> i = zip.entries(); Enumeration<? extends ZipEntry> i = zip.entries();
while (i.hasMoreElements()) { while (i.hasMoreElements()) {
ZipEntry entry = i.nextElement(); ZipEntry entry = i.nextElement();
...@@ -245,9 +245,13 @@ public class AARLibrary { ...@@ -245,9 +245,13 @@ public class AARLibrary {
if (entry.isDirectory() && !target.exists() && !target.mkdirs()) { if (entry.isDirectory() && !target.exists() && !target.mkdirs()) {
throw new IOException("Unable to create directory " + path.getAbsolutePath()); throw new IOException("Unable to create directory " + path.getAbsolutePath());
} else if (!entry.isDirectory()) { } else if (!entry.isDirectory()) {
output = new FileOutputStream(target); try {
input = zip.getInputStream(entry); output = new FileOutputStream(target);
IOUtils.copy(input, output); input = zip.getInputStream(entry);
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(input, output);
}
catalog(target); catalog(target);
} }
} }
...@@ -256,8 +260,6 @@ public class AARLibrary { ...@@ -256,8 +260,6 @@ public class AARLibrary {
resdir = null; resdir = null;
} }
} finally { } finally {
IOUtils.closeQuietly(output);
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(zip); IOUtils.closeQuietly(zip);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment