You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/03/18 13:16:12 UTC

[commons-compress] branch master updated (a02fcadc -> 9a4b488f)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


    from a02fcadc Code comments
     new 13b20451 No need to initialize to default value
     new 9a4b488f Use generics and lambdas internally

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../compress/archivers/examples/Expander.java      | 24 ++++++++++++----------
 .../commons/compress/archivers/tar/TarFile.java    |  1 -
 2 files changed, 13 insertions(+), 12 deletions(-)


[commons-compress] 02/02: Use generics and lambdas internally

Posted by gg...@apache.org.
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 9a4b488f3d1ac8fa6b5878d690acce374ad566c0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Mar 18 09:16:08 2023 -0400

    Use generics and lambdas internally
    
    Avoids some type casting
---
 .../compress/archivers/examples/Expander.java      | 24 ++++++++++++----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java b/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java
index ed923ddd..ac449ed1 100644
--- a/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java
+++ b/src/main/java/org/apache/commons/compress/archivers/examples/Expander.java
@@ -49,22 +49,24 @@ import org.apache.commons.compress.utils.IOUtils;
  */
 public class Expander {
 
-    private interface ArchiveEntrySupplier {
-        ArchiveEntry getNextReadableEntry() throws IOException;
+    @FunctionalInterface
+    private interface ArchiveEntrySupplier<T extends ArchiveEntry> {
+        T get() throws IOException;
     }
 
-    private interface EntryWriter {
-        void writeEntryDataTo(ArchiveEntry entry, OutputStream out) throws IOException;
+    @FunctionalInterface
+    private interface ArchiveEntryBiConsumer<T extends ArchiveEntry> {
+        void accept(T entry, OutputStream out) throws IOException;
     }
 
     /**
      * @param targetDirectory May be null to simulate output to dev/null on Linux and NUL on Windows.
      */
-    private void expand(final ArchiveEntrySupplier supplier, final EntryWriter writer, final Path targetDirectory)
+    private <T extends ArchiveEntry> void expand(final ArchiveEntrySupplier<T> supplier, final ArchiveEntryBiConsumer<T> writer, final Path targetDirectory)
         throws IOException {
         final boolean nullTarget = targetDirectory == null;
         final Path targetDirPath = nullTarget ? null : targetDirectory.normalize();
-        ArchiveEntry nextEntry = supplier.getNextReadableEntry();
+        T nextEntry = supplier.get();
         while (nextEntry != null) {
             final Path targetPath = nullTarget ? null : targetDirectory.resolve(nextEntry.getName());
             // check if targetDirectory and f are the same path - this may
@@ -82,14 +84,14 @@ public class Expander {
                     throw new IOException("Failed to create directory " + parent);
                 }
                 if (nullTarget) {
-                    writer.writeEntryDataTo(nextEntry, null);
+                    writer.accept(nextEntry, null);
                 } else {
                     try (OutputStream outputStream = Files.newOutputStream(targetPath)) {
-                        writer.writeEntryDataTo(nextEntry, outputStream);
+                        writer.accept(nextEntry, outputStream);
                     }
                 }
             }
-            nextEntry = supplier.getNextReadableEntry();
+            nextEntry = supplier.get();
         }
     }
 
@@ -454,7 +456,7 @@ public class Expander {
         final Iterator<TarArchiveEntry> entryIterator = archive.getEntries().iterator();
         expand(() -> entryIterator.hasNext() ? entryIterator.next() : null,
             (entry, out) -> {
-            try (InputStream in = archive.getInputStream((TarArchiveEntry) entry)) {
+            try (InputStream in = archive.getInputStream(entry)) {
                 IOUtils.copy(in, out);
             }
         }, targetDirectory);
@@ -489,7 +491,7 @@ public class Expander {
             }
             return next;
         }, (entry, out) -> {
-            try (InputStream in = archive.getInputStream((ZipArchiveEntry) entry)) {
+            try (InputStream in = archive.getInputStream(entry)) {
                 IOUtils.copy(in, out);
             }
         }, targetDirectory);


[commons-compress] 01/02: No need to initialize to default value

Posted by gg...@apache.org.
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 13b204513d7fe0871d732aa491b18e428d22e363
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Mar 18 09:04:14 2023 -0400

    No need to initialize to default value
---
 src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java
index 21fbe25a..d2a09451 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java
@@ -306,7 +306,6 @@ public class TarFile implements Closeable {
      */
     public TarFile(final SeekableByteChannel archive, final int blockSize, final int recordSize, final String encoding, final boolean lenient) throws IOException {
         this.archive = archive;
-        this.hasHitEOF = false;
         this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding);
         this.recordSize = recordSize;
         this.recordBuffer = ByteBuffer.allocate(this.recordSize);