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/04/30 04:33:00 UTC
[2/2] commons-compress git commit: COMPRESS-118 make listing just
another sink for expanding
COMPRESS-118 make listing just another sink for expanding
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/75a7edc7
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/75a7edc7
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/75a7edc7
Branch: refs/heads/master
Commit: 75a7edc742215c3354befe8fc0ec6d4ffe3bd663
Parents: 3355825
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Apr 30 06:32:20 2018 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Apr 30 06:32:20 2018 +0200
----------------------------------------------------------------------
pom.xml | 2 +-
.../compress/archivers/examples/ListerCli.java | 68 ++++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/75a7edc7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c3eff8e..85ee514 100644
--- a/pom.xml
+++ b/pom.xml
@@ -329,7 +329,7 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
<configuration>
<archive>
<manifestEntries>
- <Main-Class>org.apache.commons.compress.archivers.Lister</Main-Class>
+ <Main-Class>org.apache.commons.compress.archivers.examples.ListerCli</Main-Class>
<Extension-Name>org.apache.commons.compress</Extension-Name>
<Automatic-Module-Name>${commons.module.name}</Automatic-Module-Name>
</manifestEntries>
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/75a7edc7/src/main/java/org/apache/commons/compress/archivers/examples/ListerCli.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/ListerCli.java b/src/main/java/org/apache/commons/compress/archivers/examples/ListerCli.java
new file mode 100644
index 0000000..36f6efa
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress/archivers/examples/ListerCli.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.commons.compress.archivers.examples;
+
+import java.io.File;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+
+/**
+ * Simple command line application that lists the contents of an archive.
+ *
+ * <p>The name of the archive must be given as a command line argument.</p>
+ * <p>The optional second argument defines the archive type, in case the format is not recognized.</p>
+ *
+ * @since 1.17
+ */
+public final class ListerCli {
+
+ public static void main(final String[] args) throws Exception {
+ if (args.length == 0) {
+ usage();
+ return;
+ }
+ System.out.println("Analysing " + args[0]);
+ final Sink<ArchiveEntry> sink = new Sink<ArchiveEntry>() {
+ @Override
+ public void consume(ChainPayload<ArchiveEntry> payload) {
+ System.out.println(payload.getEntry().getName());
+ }
+ @Override
+ public void close() {
+ }
+ };
+
+ final File f = new File(args[0]);
+ if (!f.isFile()) {
+ System.err.println(f + " doesn't exist or is a directory");
+ } else if (args.length == 1) {
+ try (ArchiveEntrySource source = ArchiveSources.forFile(f).detectFormat()) {
+ Expand.source(source).to(sink);
+ }
+ } else {
+ try (ArchiveEntrySource source = ArchiveSources.forFile(f).withFormat(args[1])) {
+ Expand.source(source).to(sink);
+ }
+ }
+ }
+
+ private static void usage() {
+ System.out.println("Parameters: archive-name [archive-type]");
+ }
+
+}