Repository: commons-compress
Updated Branches:
  refs/heads/master 2b8171bd3 -> 7a10230e1


reduce API surface by removing filter from signatures


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/848be9d9
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/848be9d9
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/848be9d9

Branch: refs/heads/master
Commit: 848be9d922bd9d803e6a1ebf58fedc1d357ef930
Parents: 2b8171b
Author: Stefan Bodewig <[email protected]>
Authored: Mon May 7 21:42:31 2018 +0200
Committer: Stefan Bodewig <[email protected]>
Committed: Mon May 7 21:46:13 2018 +0200

----------------------------------------------------------------------
 .../commons/compress/archivers/Archiver.java    | 119 ++----------
 .../commons/compress/archivers/Expander.java    | 184 ++-----------------
 2 files changed, 31 insertions(+), 272 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/848be9d9/src/main/java/org/apache/commons/compress/archivers/Archiver.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/Archiver.java 
b/src/main/java/org/apache/commons/compress/archivers/Archiver.java
index 798591e..291d301 100644
--- a/src/main/java/org/apache/commons/compress/archivers/Archiver.java
+++ b/src/main/java/org/apache/commons/compress/archivers/Archiver.java
@@ -20,7 +20,6 @@ package org.apache.commons.compress.archivers;
 
 import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileFilter;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -42,13 +41,6 @@ import org.apache.commons.compress.utils.IOUtils;
  */
 public class Archiver {
 
-    private static final FileFilter ACCEPT_ALL = new FileFilter() {
-        @Override
-        public boolean accept(File f) {
-            return true;
-        }
-    };
-
     private interface ArchiveEntryCreator {
         ArchiveEntry create(File f, String entryName) throws IOException;
     }
@@ -74,33 +66,15 @@ public class Archiver {
      * @throws ArchiveException if the archive cannot be created for other 
reasons
      */
     public void create(String format, File target, File directory) throws 
IOException, ArchiveException {
-        create(format, target, directory, ACCEPT_ALL);
-    }
-
-    /**
-     * Creates an archive {@code target} using the format {@code
-     * format} by recursively including all files and directories in
-     * {@code directory} that are accepted by {@code filter}.
-     *
-     * @param format the archive format. This uses the same format as
-     * accepted by {@link ArchiveStreamFactory}.
-     * @param target the file to write the new archive to.
-     * @param directory the directory that contains the files to archive.
-     * @param filter selects the files and directories to include inside the 
archive.
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be created for other 
reasons
-     */
-    public void create(String format, File target, File directory, FileFilter 
filter)
-        throws IOException, ArchiveException {
         if (prefersSeekableByteChannel(format)) {
             try (SeekableByteChannel c = FileChannel.open(target.toPath(), 
StandardOpenOption.WRITE,
                 StandardOpenOption.CREATE, 
StandardOpenOption.TRUNCATE_EXISTING)) {
-                create(format, c, directory, filter);
+                create(format, c, directory);
             }
             return;
         }
         try (OutputStream o = Files.newOutputStream(target.toPath())) {
-            create(format, o, directory, filter);
+            create(format, o, directory);
         }
     }
 
@@ -117,25 +91,7 @@ public class Archiver {
      * @throws ArchiveException if the archive cannot be created for other 
reasons
      */
     public void create(String format, OutputStream target, File directory) 
throws IOException, ArchiveException {
-        create(format, target, directory, ACCEPT_ALL);
-    }
-
-    /**
-     * Creates an archive {@code target} using the format {@code
-     * format} by recursively including all files and directories in
-     * {@code directory} that are accepted by {@code filter}.
-     *
-     * @param format the archive format. This uses the same format as
-     * accepted by {@link ArchiveStreamFactory}.
-     * @param target the stream to write the new archive to.
-     * @param directory the directory that contains the files to archive.
-     * @param filter selects the files and directories to include inside the 
archive.
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be created for other 
reasons
-     */
-    public void create(String format, OutputStream target, File directory, 
FileFilter filter)
-        throws IOException, ArchiveException {
-        create(new ArchiveStreamFactory().createArchiveOutputStream(format, 
target), directory, filter);
+        create(new ArchiveStreamFactory().createArchiveOutputStream(format, 
target), directory);
     }
 
     /**
@@ -152,30 +108,12 @@ public class Archiver {
      */
     public void create(String format, SeekableByteChannel target, File 
directory)
         throws IOException, ArchiveException {
-        create(format, target, directory, ACCEPT_ALL);
-    }
-
-    /**
-     * Creates an archive {@code target} using the format {@code
-     * format} by recursively including all files and directories in
-     * {@code directory} that are accepted by {@code filter}.
-     *
-     * @param format the archive format. This uses the same format as
-     * accepted by {@link ArchiveStreamFactory}.
-     * @param target the channel to write the new archive to.
-     * @param directory the directory that contains the files to archive.
-     * @param filter selects the files and directories to include inside the 
archive.
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be created for other 
reasons
-     */
-    public void create(String format, SeekableByteChannel target, File 
directory, FileFilter filter)
-        throws IOException, ArchiveException {
         if (!prefersSeekableByteChannel(format)) {
-            create(format, Channels.newOutputStream(target), directory, 
filter);
+            create(format, Channels.newOutputStream(target), directory);
         } else if (ArchiveStreamFactory.ZIP.equalsIgnoreCase(format)) {
-            create(new ZipArchiveOutputStream(target), directory, filter);
+            create(new ZipArchiveOutputStream(target), directory);
         } else if (ArchiveStreamFactory.SEVEN_Z.equalsIgnoreCase(format)) {
-            create(new SevenZOutputFile(target), directory, filter);
+            create(new SevenZOutputFile(target), directory);
         } else {
             throw new ArchiveException("don't know how to handle format " + 
format);
         }
@@ -190,24 +128,9 @@ public class Archiver {
      * @throws IOException if an I/O error occurs
      * @throws ArchiveException if the archive cannot be created for other 
reasons
      */
-    public void create(ArchiveOutputStream target, File directory) throws 
IOException, ArchiveException {
-        create(target, directory, ACCEPT_ALL);
-    }
-
-    /**
-     * Creates an archive {@code target} by recursively including all
-     * files and directories in {@code directory} that are accepted by
-     * {@code filter}.
-     *
-     * @param target the stream to write the new archive to.
-     * @param directory the directory that contains the files to archive.
-     * @param filter selects the files and directories to include inside the 
archive.
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be created for other 
reasons
-     */
-    public void create(final ArchiveOutputStream target, File directory, 
FileFilter filter)
+    public void create(final ArchiveOutputStream target, File directory)
         throws IOException, ArchiveException {
-        create(directory, filter, new ArchiveEntryCreator() {
+        create(directory, new ArchiveEntryCreator() {
             public ArchiveEntry create(File f, String entryName) throws 
IOException {
                 return target.createArchiveEntry(f, entryName);
             }
@@ -237,21 +160,7 @@ public class Archiver {
      * @throws IOException if an I/O error occurs
      */
     public void create(final SevenZOutputFile target, File directory) throws 
IOException {
-        create(target, directory, ACCEPT_ALL);
-    }
-
-    /**
-     * Creates an archive {@code target} by recursively including all
-     * files and directories in {@code directory} that are accepted by
-     * {@code filter}.
-     *
-     * @param target the file to write the new archive to.
-     * @param directory the directory that contains the files to archive.
-     * @param filter selects the files and directories to include inside the 
archive.
-     * @throws IOException if an I/O error occurs
-     */
-    public void create(final SevenZOutputFile target, File directory, 
FileFilter filter) throws IOException {
-        create(directory, filter, new ArchiveEntryCreator() {
+        create(directory, new ArchiveEntryCreator() {
             public ArchiveEntry create(File f, String entryName) throws 
IOException {
                 return target.createArchiveEntry(f, entryName);
             }
@@ -282,15 +191,15 @@ public class Archiver {
         return ArchiveStreamFactory.ZIP.equalsIgnoreCase(format) || 
ArchiveStreamFactory.SEVEN_Z.equalsIgnoreCase(format);
     }
 
-    private void create(File directory, FileFilter filter, ArchiveEntryCreator 
creator, ArchiveEntryConsumer consumer,
+    private void create(File directory, ArchiveEntryCreator creator, 
ArchiveEntryConsumer consumer,
         Finisher finisher) throws IOException {
-        create("", directory, filter, creator, consumer);
+        create("", directory, creator, consumer);
         finisher.finish();
     }
 
-    private void create(String prefix, File directory, FileFilter filter, 
ArchiveEntryCreator creator, ArchiveEntryConsumer consumer)
+    private void create(String prefix, File directory, ArchiveEntryCreator 
creator, ArchiveEntryConsumer consumer)
         throws IOException {
-        File[] children = directory.listFiles(filter);
+        File[] children = directory.listFiles();
         if (children == null) {
             return;
         }
@@ -298,7 +207,7 @@ public class Archiver {
             String entryName = prefix + f.getName() + (f.isDirectory() ? "/" : 
"");
             consumer.accept(f, creator.create(f, entryName));
             if (f.isDirectory()) {
-                create(entryName, f, filter, creator, consumer);
+                create(entryName, f, creator, consumer);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/848be9d9/src/main/java/org/apache/commons/compress/archivers/Expander.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/Expander.java 
b/src/main/java/org/apache/commons/compress/archivers/Expander.java
index f726de7..1575e10 100644
--- a/src/main/java/org/apache/commons/compress/archivers/Expander.java
+++ b/src/main/java/org/apache/commons/compress/archivers/Expander.java
@@ -42,23 +42,6 @@ import org.apache.commons.compress.utils.IOUtils;
  * @since 1.17
  */
 public class Expander {
-    /**
-     * Used to filter the entries to be extracted.
-     */
-    public interface ArchiveEntryFilter {
-        /**
-         * @return true if the entry shall be expanded
-         * @param entry the entry to test
-         */
-        boolean accept(ArchiveEntry entry);
-    }
-
-    private static final ArchiveEntryFilter ACCEPT_ALL = new 
ArchiveEntryFilter() {
-        @Override
-        public boolean accept(ArchiveEntry e) {
-            return true;
-        }
-    };
 
     private interface ArchiveEntrySupplier {
         ArchiveEntry getNextReadableEntry() throws IOException;
@@ -79,66 +62,32 @@ public class Expander {
      * @throws ArchiveException if the archive cannot be read for other reasons
      */
     public void expand(File archive, File targetDirectory) throws IOException, 
ArchiveException {
-        expand(archive, targetDirectory, ACCEPT_ALL);
-    }
-
-    /**
-     * Expands {@code archive} into {@code targetDirectory}.
-     *
-     * @param archive the file to expand
-     * @param targetDirectory the directory to write to
-     * @param format the archive format. This uses the same format as
-     * accepted by {@link ArchiveStreamFactory}.
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be read for other reasons
-     */
-    public void expand(String format, File archive, File targetDirectory) 
throws IOException, ArchiveException {
-        expand(format, archive, targetDirectory, ACCEPT_ALL);
-    }
-
-    /**
-     * Expands {@code archive} into {@code targetDirectory}, using
-     * only the entries accepted by the {@code filter}.
-     *
-     * <p>Tries to auto-detect the archive's format.</p>
-     *
-     * @param archive the file to expand
-     * @param targetDirectory the directory to write to
-     * @param filter selects the entries to expand
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be read for other reasons
-     */
-    public void expand(File archive, File targetDirectory, ArchiveEntryFilter 
filter)
-        throws IOException, ArchiveException {
         String format = null;
         try (InputStream i = new 
BufferedInputStream(Files.newInputStream(archive.toPath()))) {
             format = new ArchiveStreamFactory().detect(i);
         }
-        expand(format, archive, targetDirectory, filter);
+        expand(format, archive, targetDirectory);
     }
 
     /**
-     * Expands {@code archive} into {@code targetDirectory}, using
-     * only the entries accepted by the {@code filter}.
+     * Expands {@code archive} into {@code targetDirectory}.
      *
      * @param archive the file to expand
      * @param targetDirectory the directory to write to
      * @param format the archive format. This uses the same format as
      * accepted by {@link ArchiveStreamFactory}.
-     * @param filter selects the entries to expand
      * @throws IOException if an I/O error occurs
      * @throws ArchiveException if the archive cannot be read for other reasons
      */
-    public void expand(String format, File archive, File targetDirectory, 
ArchiveEntryFilter filter)
-        throws IOException, ArchiveException {
+    public void expand(String format, File archive, File targetDirectory) 
throws IOException, ArchiveException {
         if (prefersSeekableByteChannel(format)) {
             try (SeekableByteChannel c = FileChannel.open(archive.toPath(), 
StandardOpenOption.READ)) {
-                expand(format, c, targetDirectory, filter);
+                expand(format, c, targetDirectory);
             }
             return;
         }
         try (InputStream i = new 
BufferedInputStream(Files.newInputStream(archive.toPath()))) {
-            expand(format, i, targetDirectory, filter);
+            expand(format, i, targetDirectory);
         }
     }
 
@@ -153,7 +102,7 @@ public class Expander {
      * @throws ArchiveException if the archive cannot be read for other reasons
      */
     public void expand(InputStream archive, File targetDirectory) throws 
IOException, ArchiveException {
-        expand(archive, targetDirectory, ACCEPT_ALL);
+        expand(new ArchiveStreamFactory().createArchiveInputStream(archive), 
targetDirectory);
     }
 
     /**
@@ -168,41 +117,7 @@ public class Expander {
      */
     public void expand(String format, InputStream archive, File 
targetDirectory)
         throws IOException, ArchiveException {
-        expand(format, archive, targetDirectory, ACCEPT_ALL);
-    }
-
-    /**
-     * Expands {@code archive} into {@code targetDirectory}, using
-     * only the entries accepted by the {@code filter}.
-     *
-     * <p>Tries to auto-detect the archive's format.</p>
-     *
-     * @param archive the file to expand
-     * @param targetDirectory the directory to write to
-     * @param filter selects the entries to expand
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be read for other reasons
-     */
-    public void expand(InputStream archive, File targetDirectory, 
ArchiveEntryFilter filter)
-        throws IOException, ArchiveException {
-        expand(new ArchiveStreamFactory().createArchiveInputStream(archive), 
targetDirectory, filter);
-    }
-
-    /**
-     * Expands {@code archive} into {@code targetDirectory}, using
-     * only the entries accepted by the {@code filter}.
-     *
-     * @param archive the file to expand
-     * @param targetDirectory the directory to write to
-     * @param format the archive format. This uses the same format as
-     * accepted by {@link ArchiveStreamFactory}.
-     * @param filter selects the entries to expand
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be read for other reasons
-     */
-    public void expand(String format, InputStream archive, File 
targetDirectory, ArchiveEntryFilter filter)
-        throws IOException, ArchiveException {
-        expand(new ArchiveStreamFactory().createArchiveInputStream(format, 
archive), targetDirectory, filter);
+        expand(new ArchiveStreamFactory().createArchiveInputStream(format, 
archive), targetDirectory);
     }
 
     /**
@@ -217,29 +132,12 @@ public class Expander {
      */
     public void expand(String format, SeekableByteChannel archive, File 
targetDirectory)
         throws IOException, ArchiveException {
-        expand(format, archive, targetDirectory, ACCEPT_ALL);
-    }
-
-    /**
-     * Expands {@code archive} into {@code targetDirectory}, using
-     * only the entries accepted by the {@code filter}.
-     *
-     * @param archive the file to expand
-     * @param targetDirectory the directory to write to
-     * @param format the archive format. This uses the same format as
-     * accepted by {@link ArchiveStreamFactory}.
-     * @param filter selects the entries to expand
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be read for other reasons
-     */
-    public void expand(String format, SeekableByteChannel archive, File 
targetDirectory, ArchiveEntryFilter filter)
-        throws IOException, ArchiveException {
         if (!prefersSeekableByteChannel(format)) {
-            expand(format, Channels.newInputStream(archive), targetDirectory, 
filter);
+            expand(format, Channels.newInputStream(archive), targetDirectory);
         } else if (ArchiveStreamFactory.ZIP.equalsIgnoreCase(format)) {
-            expand(new ZipFile(archive), targetDirectory, filter);
+            expand(new ZipFile(archive), targetDirectory);
         } else if (ArchiveStreamFactory.SEVEN_Z.equalsIgnoreCase(format)) {
-            expand(new SevenZFile(archive), targetDirectory, filter);
+            expand(new SevenZFile(archive), targetDirectory);
         } else {
             throw new ArchiveException("don't know how to handle format " + 
format);
         }
@@ -253,22 +151,7 @@ public class Expander {
      * @throws IOException if an I/O error occurs
      * @throws ArchiveException if the archive cannot be read for other reasons
      */
-    public void expand(ArchiveInputStream archive, File targetDirectory)
-        throws IOException, ArchiveException {
-        expand(archive, targetDirectory, ACCEPT_ALL);
-    }
-
-    /**
-     * Expands {@code archive} into {@code targetDirectory}, using
-     * only the entries accepted by the {@code filter}.
-     *
-     * @param archive the file to expand
-     * @param targetDirectory the directory to write to
-     * @param filter selects the entries to expand
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be read for other reasons
-     */
-    public void expand(final ArchiveInputStream archive, File targetDirectory, 
ArchiveEntryFilter filter)
+    public void expand(final ArchiveInputStream archive, File targetDirectory)
         throws IOException, ArchiveException {
         expand(new ArchiveEntrySupplier() {
             @Override
@@ -284,7 +167,7 @@ public class Expander {
             public void writeEntryDataTo(ArchiveEntry entry, OutputStream out) 
throws IOException {
                 IOUtils.copy(archive, out);
             }
-        }, targetDirectory, filter);
+        }, targetDirectory);
     }
 
     /**
@@ -295,22 +178,7 @@ public class Expander {
      * @throws IOException if an I/O error occurs
      * @throws ArchiveException if the archive cannot be read for other reasons
      */
-    public void expand(ZipFile archive, File targetDirectory)
-        throws IOException, ArchiveException {
-        expand(archive, targetDirectory, ACCEPT_ALL);
-    }
-
-    /**
-     * Expands {@code archive} into {@code targetDirectory}, using
-     * only the entries accepted by the {@code filter}.
-     *
-     * @param archive the file to expand
-     * @param targetDirectory the directory to write to
-     * @param filter selects the entries to expand
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be read for other reasons
-     */
-    public void expand(final ZipFile archive, File targetDirectory, 
ArchiveEntryFilter filter)
+    public void expand(final ZipFile archive, File targetDirectory)
         throws IOException, ArchiveException {
         final Enumeration<ZipArchiveEntry> entries = archive.getEntries();
         expand(new ArchiveEntrySupplier() {
@@ -329,7 +197,7 @@ public class Expander {
                     IOUtils.copy(in, out);
                 }
             }
-        }, targetDirectory, filter);
+        }, targetDirectory);
     }
 
     /**
@@ -340,22 +208,7 @@ public class Expander {
      * @throws IOException if an I/O error occurs
      * @throws ArchiveException if the archive cannot be read for other reasons
      */
-    public void expand(SevenZFile archive, File targetDirectory)
-        throws IOException, ArchiveException {
-        expand(archive, targetDirectory, ACCEPT_ALL);
-    }
-
-    /**
-     * Expands {@code archive} into {@code targetDirectory}, using
-     * only the entries accepted by the {@code filter}.
-     *
-     * @param archive the file to expand
-     * @param targetDirectory the directory to write to
-     * @param filter selects the entries to expand
-     * @throws IOException if an I/O error occurs
-     * @throws ArchiveException if the archive cannot be read for other reasons
-     */
-    public void expand(final SevenZFile archive, File targetDirectory, 
ArchiveEntryFilter filter)
+    public void expand(final SevenZFile archive, File targetDirectory)
         throws IOException, ArchiveException {
         expand(new ArchiveEntrySupplier() {
             @Override
@@ -373,21 +226,18 @@ public class Expander {
                     count += n;
                 }
             }
-        }, targetDirectory, filter);
+        }, targetDirectory);
     }
 
     private boolean prefersSeekableByteChannel(String format) {
         return ArchiveStreamFactory.ZIP.equalsIgnoreCase(format) || 
ArchiveStreamFactory.SEVEN_Z.equalsIgnoreCase(format);
     }
 
-    private void expand(ArchiveEntrySupplier supplier, EntryWriter writer, 
File targetDirectory, ArchiveEntryFilter filter)
+    private void expand(ArchiveEntrySupplier supplier, EntryWriter writer, 
File targetDirectory)
         throws IOException {
         String targetDirPath = targetDirectory.getCanonicalPath();
         ArchiveEntry nextEntry = supplier.getNextReadableEntry();
         while (nextEntry != null) {
-            if (!filter.accept(nextEntry)) {
-                continue;
-            }
             File f = new File(targetDirectory, nextEntry.getName());
             if (!f.getCanonicalPath().startsWith(targetDirPath)) {
                 throw new IOException("expanding " + nextEntry.getName()

Reply via email to