This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 015a427456b30dbb1c690a21da9286ff8c079d35 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu Nov 2 12:32:34 2023 -0400 Better parameter and local names --- .../apache/commons/compress/archivers/Lister.java | 66 +++++++++++----------- 1 file changed, 34 insertions(+), 32 deletions(-) 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 fb88da40..c769534b 100644 --- a/src/main/java/org/apache/commons/compress/archivers/Lister.java +++ b/src/main/java/org/apache/commons/compress/archivers/Lister.java @@ -33,8 +33,12 @@ import org.apache.commons.compress.archivers.zip.ZipFile; /** * 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> + * <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.1 */ @@ -42,8 +46,7 @@ public final class Lister { private static final ArchiveStreamFactory FACTORY = ArchiveStreamFactory.DEFAULT; - private static ArchiveInputStream createArchiveInputStream(final String[] args, final InputStream inputStream) - throws ArchiveException { + private static ArchiveInputStream createArchiveInputStream(final String[] args, final InputStream inputStream) throws ArchiveException { if (args.length > 1) { return FACTORY.createArchiveInputStream(args[1], inputStream); } @@ -56,40 +59,39 @@ public final class Lister { } } - private static void list7z(final File f) throws IOException { - try (SevenZFile z = new SevenZFile(f)) { - System.out.println("Created " + z); - ArchiveEntry ae; - while ((ae = z.getNextEntry()) != null) { - final String name = ae.getName() == null ? z.getDefaultName() + " (entry name was null)" - : ae.getName(); + private static void list7z(final File file) throws IOException { + try (SevenZFile sevenZFile = new SevenZFile(file)) { + System.out.println("Created " + sevenZFile); + ArchiveEntry entry; + while ((entry = sevenZFile.getNextEntry()) != null) { + final String name = entry.getName() == null ? sevenZFile.getDefaultName() + " (entry name was null)" : entry.getName(); System.out.println(name); } } } private static void listStream(final File file, final String[] args) throws ArchiveException, IOException { - try (final InputStream fis = new BufferedInputStream(Files.newInputStream(file.toPath())); - final ArchiveInputStream ais = createArchiveInputStream(args, fis)) { - System.out.println("Created " + ais.toString()); - ArchiveEntry ae; - while ((ae = ais.getNextEntry()) != null) { - System.out.println(ae.getName()); + try (final InputStream inputStream = new BufferedInputStream(Files.newInputStream(file.toPath())); + final ArchiveInputStream archiveInputStream = createArchiveInputStream(args, inputStream)) { + System.out.println("Created " + archiveInputStream.toString()); + ArchiveEntry entry; + while ((entry = archiveInputStream.getNextEntry()) != null) { + System.out.println(entry.getName()); } } } private static void listZipUsingTarFile(final File file) throws IOException { - try (TarFile t = new TarFile(file)) { - System.out.println("Created " + t); - t.getEntries().forEach(en -> System.out.println(en.getName())); + try (TarFile tarFile = new TarFile(file)) { + System.out.println("Created " + tarFile); + tarFile.getEntries().forEach(en -> System.out.println(en.getName())); } } private static void listZipUsingZipFile(final File file) throws IOException { - try (ZipFile z = new ZipFile(file)) { - System.out.println("Created " + z); - for (final Enumeration<ZipArchiveEntry> en = z.getEntries(); en.hasMoreElements(); ) { + try (ZipFile zipFile = new ZipFile(file)) { + System.out.println("Created " + zipFile); + for (final Enumeration<ZipArchiveEntry> en = zipFile.getEntries(); en.hasMoreElements();) { System.out.println(en.nextElement().getName()); } } @@ -106,7 +108,7 @@ public final class Lister { * * @param args name of the archive and optional argument archive type. * @throws ArchiveException Archiver related Exception. - * @throws IOException an I/O exception. + * @throws IOException an I/O exception. */ public static void main(final String[] args) throws ArchiveException, IOException { if (args == null || args.length == 0) { @@ -115,19 +117,19 @@ public final class Lister { } Objects.requireNonNull(args[0], "args[0]"); System.out.println("Analysing " + args[0]); - final File f = new File(args[0]); - if (!f.isFile()) { - System.err.println(f + " doesn't exist or is a directory"); + final File file = new File(args[0]); + if (!file.isFile()) { + System.err.println(file + " doesn't exist or is a directory"); } - final String format = args.length > 1 ? args[1] : detectFormat(f); + final String format = args.length > 1 ? args[1] : detectFormat(file); if (ArchiveStreamFactory.SEVEN_Z.equalsIgnoreCase(format)) { - list7z(f); + list7z(file); } else if ("zipfile".equals(format)) { - listZipUsingZipFile(f); + listZipUsingZipFile(file); } else if ("tarfile".equals(format)) { - listZipUsingTarFile(f); + listZipUsingTarFile(file); } else { - listStream(f, args); + listStream(file, args); } }