Github user revans2 commented on a diff in the pull request:
https://github.com/apache/storm/pull/822#discussion_r43155803
--- Diff: storm-core/src/jvm/backtype/storm/utils/Utils.java ---
@@ -692,5 +696,65 @@ public static void handleUncaughtException(Throwable
t) {
}
}
}
+
+ /**
+ * Given a File input it will unzip the file in a the unzip directory
+ * passed as the second parameter
+ * @param inFile The zip file as input
+ * @param unzipDir The unzip directory where to unzip the zip file.
+ * @throws IOException
+ */
+ public static void unZip(File inFile, File unzipDir) throws
IOException {
+ Enumeration<? extends ZipEntry> entries;
+ ZipFile zipFile = new ZipFile(inFile);
+
+ try {
+ entries = zipFile.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = entries.nextElement();
+ if (!entry.isDirectory()) {
+ InputStream in = zipFile.getInputStream(entry);
+ try {
+ File file = new File(unzipDir, entry.getName());
+ if (!file.getParentFile().mkdirs()) {
+ if (!file.getParentFile().isDirectory()) {
+ throw new IOException("Mkdirs failed to
create " +
+ file.getParentFile().toString());
+ }
+ }
+ OutputStream out = new FileOutputStream(file);
+ try {
+ byte[] buffer = new byte[8192];
+ int i;
+ while ((i = in.read(buffer)) != -1) {
+ out.write(buffer, 0, i);
+ }
+ } finally {
+ out.close();
+ }
+ } finally {
+ in.close();
+ }
+ }
+ }
+ } finally {
+ zipFile.close();
+ }
+ }
+
+ //Note: Only works for zip files whose uncompressed size is less than
4 GB
+ //Otherwise returns the size module 2^32, per gzip specifications
+ //Returns a long, since that's what file lengths in Java/Clojure
usually are.
--- End diff --
Can we turn this into a javadoc comment?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---