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 1a0b598ec Internal refactoring
1a0b598ec is described below
commit 1a0b598ec63b529e75f4c0f0331e7b136598a8eb
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Jan 13 10:45:47 2024 -0500
Internal refactoring
---
.../commons/compress/archivers/zip/ZipFile.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 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 cb4236aef..5be9286f4 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
@@ -144,6 +144,8 @@ public class ZipFile implements Closeable {
}
}
+ private static final EnumSet<StandardOpenOption> READ =
EnumSet.of(StandardOpenOption.READ);
+
private static final int HASH_SIZE = 509;
static final int NIBLET_MASK = 0x0f;
static final int BYTE_SHIFT = 8;
@@ -358,6 +360,17 @@ public class ZipFile implements Closeable {
org.apache.commons.io.IOUtils.closeQuietly(zipFile);
}
+ /**
+ * Creates a new SeekableByteChannel for reading.
+ *
+ * @param path the path to the file to open or create
+ * @return a new seekable byte channel
+ * @throws IOException if an I/O error occurs
+ */
+ private static SeekableByteChannel newReadByteChannel(final Path path)
throws IOException {
+ return Files.newByteChannel(path, READ);
+ }
+
/**
* List of entries in the order they appear inside the central directory.
*/
@@ -477,8 +490,7 @@ public class ZipFile implements Closeable {
* @since 1.19
*/
public ZipFile(final File file, final String encoding, final boolean
useUnicodeExtraFields, final boolean ignoreLocalFileHeader) throws IOException {
- this(Files.newByteChannel(file.toPath(),
EnumSet.of(StandardOpenOption.READ)), file.getAbsolutePath(), encoding,
useUnicodeExtraFields, true,
- ignoreLocalFileHeader);
+ this(newReadByteChannel(file.toPath()), file.getAbsolutePath(),
encoding, useUnicodeExtraFields, true, ignoreLocalFileHeader);
}
/**
@@ -535,8 +547,7 @@ public class ZipFile implements Closeable {
* @since 1.22
*/
public ZipFile(final Path path, final String encoding, final boolean
useUnicodeExtraFields, final boolean ignoreLocalFileHeader) throws IOException {
- this(Files.newByteChannel(path, EnumSet.of(StandardOpenOption.READ)),
path.toAbsolutePath().toString(), encoding, useUnicodeExtraFields, true,
- ignoreLocalFileHeader);
+ this(newReadByteChannel(path), path.toAbsolutePath().toString(),
encoding, useUnicodeExtraFields, true, ignoreLocalFileHeader);
}
/**