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 2016/03/23 17:39:57 UTC
commons-compress git commit: tar specific Lister
Repository: commons-compress
Updated Branches:
refs/heads/master a5eca5683 -> 02e0f9ae6
tar specific Lister
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/02e0f9ae
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/02e0f9ae
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/02e0f9ae
Branch: refs/heads/master
Commit: 02e0f9ae63a1d1db2d4c644ddbaa0a18e6b748fa
Parents: a5eca56
Author: Stefan Bodewig <bo...@apache.org>
Authored: Wed Mar 23 17:39:32 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Wed Mar 23 17:39:32 2016 +0100
----------------------------------------------------------------------
.../compress/archivers/tar/TarLister.java | 79 ++++++++++++++++++++
1 file changed, 79 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/02e0f9ae/src/test/java/org/apache/commons/compress/archivers/tar/TarLister.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarLister.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarLister.java
new file mode 100644
index 0000000..ce78e7e
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarLister.java
@@ -0,0 +1,79 @@
+/*
+ * 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.tar;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+/**
+ * Simple command line application that lists the contents of a tar archive.
+ *
+ * <p>The name of the archive must be given as a command line argument.</p>
+ * <p>The optional second argument specifies the encoding to assume for file names.</p>
+ *
+ * @since 1.11
+ */
+public final class TarLister {
+
+ public static void main(String[] args) throws Exception {
+ if (args.length == 0) {
+ usage();
+ return;
+ }
+ System.out.println("Analysing " + args[0]);
+ File f = new File(args[0]);
+ if (!f.isFile()) {
+ System.err.println(f + " doesn't exist or is a directory");
+ }
+ InputStream fis = new BufferedInputStream(new FileInputStream(f));
+ TarArchiveInputStream ais;
+ if (args.length > 1) {
+ ais = new TarArchiveInputStream(fis, args[1]);
+ } else {
+ ais = new TarArchiveInputStream(fis);
+ }
+ System.out.println("Created " + ais.toString());
+ TarArchiveEntry ae;
+ while((ae=ais.getNextTarEntry()) != null){
+ log(ae);
+ }
+ ais.close();
+ fis.close();
+ }
+
+ private static void usage() {
+ System.out.println("Parameters: archive-name [encoding]");
+ }
+
+ private static void log(TarArchiveEntry ae) {
+ System.out.print(ae.getName());
+ if (ae.isSymbolicLink() || ae.isLink()) {
+ if (ae.isSymbolicLink()) {
+ System.out.print(" -> ");
+ } else {
+ System.out.print(" link to ");
+ }
+ System.out.print(ae.getLinkName());
+ }
+ System.out.println();
+ }
+
+}