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


The following commit(s) were added to refs/heads/master by this push:
     new 924c5eff7 Use NIO internally in Lister
924c5eff7 is described below

commit 924c5eff788bfab8cbdac7e35d69fbf68035da65
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Feb 1 12:14:19 2024 -0500

    Use NIO internally in Lister
---
 .../apache/commons/compress/archivers/Lister.java  | 25 +++++++++++-----------
 1 file changed, 13 insertions(+), 12 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 dc7f5d3a8..856402865 100644
--- a/src/main/java/org/apache/commons/compress/archivers/Lister.java
+++ b/src/main/java/org/apache/commons/compress/archivers/Lister.java
@@ -18,10 +18,11 @@
 package org.apache.commons.compress.archivers;
 
 import java.io.BufferedInputStream;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Enumeration;
 import java.util.Locale;
 import java.util.Objects;
@@ -55,14 +56,14 @@ public final class Lister {
         return FACTORY.createArchiveInputStream(inputStream);
     }
 
-    private static String detectFormat(final File file) throws 
ArchiveException, IOException {
-        try (InputStream inputStream = new 
BufferedInputStream(Files.newInputStream(file.toPath()))) {
+    private static String detectFormat(final Path file) throws 
ArchiveException, IOException {
+        try (InputStream inputStream = new 
BufferedInputStream(Files.newInputStream(file))) {
             return ArchiveStreamFactory.detect(inputStream);
         }
     }
 
-    private static void list7z(final File file) throws IOException {
-        try (SevenZFile sevenZFile = SevenZFile.builder().setFile(file).get()) 
{
+    private static void list7z(final Path file) throws IOException {
+        try (SevenZFile sevenZFile = SevenZFile.builder().setPath(file).get()) 
{
             println("Created " + sevenZFile);
             ArchiveEntry entry;
             while ((entry = sevenZFile.getNextEntry()) != null) {
@@ -71,8 +72,8 @@ public final class Lister {
         }
     }
 
-    private static void listStream(final File file, final String[] args) 
throws ArchiveException, IOException {
-        try (InputStream inputStream = new 
BufferedInputStream(Files.newInputStream(file.toPath()));
+    private static void listStream(final Path file, final String[] args) 
throws ArchiveException, IOException {
+        try (InputStream inputStream = new 
BufferedInputStream(Files.newInputStream(file));
                 ArchiveInputStream<?> archiveInputStream = 
createArchiveInputStream(args, inputStream)) {
             println("Created " + archiveInputStream.toString());
             ArchiveEntry entry;
@@ -82,15 +83,15 @@ public final class Lister {
         }
     }
 
-    private static void listZipUsingTarFile(final File file) throws 
IOException {
+    private static void listZipUsingTarFile(final Path file) throws 
IOException {
         try (TarFile tarFile = new TarFile(file)) {
             println("Created " + tarFile);
             tarFile.getEntries().forEach(Lister::println);
         }
     }
 
-    private static void listZipUsingZipFile(final File file) throws 
IOException {
-        try (ZipFile zipFile = ZipFile.builder().setFile(file).get()) {
+    private static void listZipUsingZipFile(final Path file) throws 
IOException {
+        try (ZipFile zipFile = ZipFile.builder().setPath(file).get()) {
             println("Created " + zipFile);
             for (final Enumeration<ZipArchiveEntry> en = zipFile.getEntries(); 
en.hasMoreElements();) {
                 println(en.nextElement());
@@ -118,8 +119,8 @@ public final class Lister {
         }
         Objects.requireNonNull(args[0], "args[0]");
         println("Analysing " + args[0]);
-        final File file = new File(args[0]);
-        if (!file.isFile()) {
+        final Path file = Paths.get(args[0]);
+        if (!Files.isRegularFile(file)) {
             System.err.println(file + " doesn't exist or is a directory");
         }
         final String format = (args.length > 1 ? args[1] : 
detectFormat(file)).toLowerCase(Locale.ROOT);

Reply via email to