HBASE-11012 InputStream is not properly closed in two methods of JarFinder
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1588375 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fb1e2dc8b6
commit
39fb144f17
|
@ -41,8 +41,10 @@ import java.util.zip.ZipOutputStream;
|
|||
*/
|
||||
public class JarFinder {
|
||||
|
||||
private static void copyToZipStream(InputStream is, ZipEntry entry,
|
||||
private static void copyToZipStream(File file, ZipEntry entry,
|
||||
ZipOutputStream zos) throws IOException {
|
||||
InputStream is = new FileInputStream(file);
|
||||
try {
|
||||
zos.putNextEntry(entry);
|
||||
byte[] arr = new byte[4096];
|
||||
int read = is.read(arr);
|
||||
|
@ -50,9 +52,14 @@ public class JarFinder {
|
|||
zos.write(arr, 0, read);
|
||||
read = is.read(arr);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} finally {
|
||||
zos.closeEntry();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void jarDir(File dir, String relativePath, ZipOutputStream zos)
|
||||
throws IOException {
|
||||
|
@ -68,8 +75,7 @@ public class JarFinder {
|
|||
new Manifest().write(new BufferedOutputStream(zos));
|
||||
zos.closeEntry();
|
||||
} else {
|
||||
InputStream is = new FileInputStream(manifestFile);
|
||||
copyToZipStream(is, manifestEntry, zos);
|
||||
copyToZipStream(manifestFile, manifestEntry, zos);
|
||||
}
|
||||
zos.closeEntry();
|
||||
zipDir(dir, relativePath, zos, true);
|
||||
|
@ -96,8 +102,7 @@ public class JarFinder {
|
|||
String path = relativePath + f.getName();
|
||||
if (!path.equals(JarFile.MANIFEST_NAME)) {
|
||||
ZipEntry anEntry = new ZipEntry(path);
|
||||
InputStream is = new FileInputStream(f);
|
||||
copyToZipStream(is, anEntry, zos);
|
||||
copyToZipStream(f, anEntry, zos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue