You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2018/09/21 15:50:55 UTC
commons-compress git commit: make Lister optionally use ZipFile
Repository: commons-compress
Updated Branches:
refs/heads/master 0855aec56 -> ac3d73153
make Lister optionally use ZipFile
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/ac3d7315
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/ac3d7315
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/ac3d7315
Branch: refs/heads/master
Commit: ac3d73153725fa1bce721055c4ac61423570d34c
Parents: 0855aec
Author: Stefan Bodewig <bo...@apache.org>
Authored: Fri Sep 21 17:50:33 2018 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Fri Sep 21 17:50:33 2018 +0200
----------------------------------------------------------------------
.../apache/commons/compress/archivers/Lister.java | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ac3d7315/src/main/java/org/apache/commons/compress/archivers/Lister.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/Lister.java b/src/main/java/org/apache/commons/compress/archivers/Lister.java
index 07a8e9c..481cc30 100644
--- a/src/main/java/org/apache/commons/compress/archivers/Lister.java
+++ b/src/main/java/org/apache/commons/compress/archivers/Lister.java
@@ -23,7 +23,10 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
+import java.util.Enumeration;
import org.apache.commons.compress.archivers.sevenz.SevenZFile;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipFile;
/**
* Simple command line application that lists the contents of an archive.
@@ -49,6 +52,8 @@ public final class Lister {
String format = args.length > 1 ? args[1] : detectFormat(f);
if (ArchiveStreamFactory.SEVEN_Z.equalsIgnoreCase(format)) {
list7z(f);
+ } else if ("zipfile".equals(format)) {
+ listZipUsingZipFile(f);
} else {
listStream(f, args);
}
@@ -89,8 +94,18 @@ public final class Lister {
}
}
+ private static void listZipUsingZipFile(File f) throws ArchiveException, IOException {
+ try (ZipFile z = new ZipFile(f)) {
+ System.out.println("Created " + z.toString());
+ for (Enumeration<ZipArchiveEntry> en = z.getEntries(); en.hasMoreElements(); ) {
+ System.out.println(en.nextElement().getName());
+ }
+ }
+ }
+
private static void usage() {
- System.out.println("Parameters: archive-name [archive-type]");
+ System.out.println("Parameters: archive-name [archive-type]\n");
+ System.out.println("the magic archive-type 'zipfile' prefers ZipFile over ZipArchiveInputStream");
}
}