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 b03c5f893a1c18009dcaf91ef65ea25ae20d82c5
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Nov 12 15:23:13 2023 -0500

    Refactor internal sorting by offset
    
    Remove trailing whitespace
---
 .../commons/compress/archivers/zip/ZipFile.java    | 31 +++++++++++++---------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
index f811b9778..351cdc96f 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
@@ -355,7 +355,7 @@ public class ZipFile implements Closeable {
 
     /**
      * Closes a ZIP file quietly; throwing no IOException, does nothing on 
null input.
-     * 
+     *
      * @param zipFile file to close, can be null
      */
     public static void closeQuietly(final ZipFile zipFile) {
@@ -690,7 +690,7 @@ public class ZipFile implements Closeable {
      * <p>
      * May return false if it is set up to use encryption or a compression 
method that hasn't been implemented yet.
      * </p>
-     * 
+     *
      * @since 1.1
      * @param entry the entry
      * @return whether this class is able to read the given entry.
@@ -701,7 +701,7 @@ public class ZipFile implements Closeable {
 
     /**
      * Closes the archive.
-     * 
+     *
      * @throws IOException if an error occurs closing the archive.
      */
     @Override
@@ -756,7 +756,7 @@ public class ZipFile implements Closeable {
 
     /**
      * Ensures that the close method of this ZIP file is called when there are 
no more references to it.
-     * 
+     *
      * @see #close()
      */
     @Override
@@ -836,8 +836,7 @@ public class ZipFile implements Closeable {
      */
     public Enumeration<ZipArchiveEntry> getEntriesInPhysicalOrder() {
         final ZipArchiveEntry[] allEntries = 
entries.toArray(ZipArchiveEntry.EMPTY_ARRAY);
-        Arrays.sort(allEntries, offsetComparator);
-        return Collections.enumeration(Arrays.asList(allEntries));
+        return 
Collections.enumeration(Arrays.asList(sortByOffset(allEntries)));
     }
 
     /**
@@ -848,13 +847,8 @@ public class ZipFile implements Closeable {
      * @since 1.6
      */
     public Iterable<ZipArchiveEntry> getEntriesInPhysicalOrder(final String 
name) {
-        ZipArchiveEntry[] entries = ZipArchiveEntry.EMPTY_ARRAY;
-        final LinkedList<ZipArchiveEntry> linkedList = nameMap.get(name);
-        if (linkedList != null) {
-            entries = linkedList.toArray(entries);
-            Arrays.sort(entries, offsetComparator);
-        }
-        return Arrays.asList(entries);
+        final LinkedList<ZipArchiveEntry> linkedList = 
nameMap.getOrDefault(name, ZipArchiveEntry.EMPTY_LINKED_LIST);
+        return 
Arrays.asList(sortByOffset(linkedList.toArray(ZipArchiveEntry.EMPTY_ARRAY)));
     }
 
     /**
@@ -1415,6 +1409,17 @@ public class ZipFile implements Closeable {
         archive.position(newPosition);
     }
 
+    /**
+     * Sorts entries in place by offset.
+     *
+     * @param allEntries entries to sort
+     * @return the given entries, sorted.
+     */
+    private ZipArchiveEntry[] sortByOffset(final ZipArchiveEntry[] allEntries) 
{
+        Arrays.sort(allEntries, offsetComparator);
+        return allEntries;
+    }
+
     /**
      * Checks whether the archive starts with an LFH. If it doesn't, it may be 
an empty archive.
      */

Reply via email to