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 2024/02/10 21:31:57 UTC
(commons-compress) branch master updated (260b9071c -> 392cb9ca3)
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 260b9071c Javadoc
new b3e34e89d Use ternary expression
new a662a22c5 Remove unused exceptions
new 436ed771e Remove unused exceptions
new f1ce1241f Javadoc
new 1c17e0c6e Sort members
new e0bb5c312 Use a StringBuilder
new 392cb9ca3 Javadoc
The 7 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:
.../archivers/zip/ExtraFieldParsingBehavior.java | 7 ++--
.../compress/archivers/zip/ExtraFieldUtils.java | 20 ++++--------
.../compress/archivers/zip/ZipArchiveEntry.java | 14 +++-----
.../archivers/zip/ZipArchiveInputStream.java | 38 +++++++++++-----------
.../archivers/zip/ZipSplitOutputStream.java | 22 +++++++------
5 files changed, 46 insertions(+), 55 deletions(-)
(commons-compress) 01/07: Use ternary expression
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 b3e34e89d5c8655e93962f35c83efeb55ddb8f55
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 10 16:15:26 2024 -0500
Use ternary expression
---
.../org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
index 0a2c84260..238642d57 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
@@ -168,10 +168,7 @@ public class ExtraFieldUtils {
*/
public static ZipExtraField createExtraFieldNoDefault(final ZipShort headerId) throws InstantiationException, IllegalAccessException {
final Supplier<ZipExtraField> provider = IMPLEMENTATIONS.get(headerId);
- if (provider != null) {
- return provider.get();
- }
- return null;
+ return provider != null ? provider.get() : null;
}
/**
(commons-compress) 02/07: Remove unused exceptions
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 a662a22c5a6e2adc4619d8161a3a5155b5697cfc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 10 16:18:32 2024 -0500
Remove unused exceptions
Binary compatible
---
.../commons/compress/archivers/zip/ExtraFieldUtils.java | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
index 238642d57..1ca0c66e0 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
@@ -144,10 +144,8 @@ public class ExtraFieldUtils {
*
* @param headerId the header identifier
* @return an instance of the appropriate ExtraField
- * @throws InstantiationException if unable to instantiate the class
- * @throws IllegalAccessException if not allowed to instantiate the class
*/
- public static ZipExtraField createExtraField(final ZipShort headerId) throws InstantiationException, IllegalAccessException {
+ public static ZipExtraField createExtraField(final ZipShort headerId) {
final ZipExtraField field = createExtraFieldNoDefault(headerId);
if (field != null) {
return field;
@@ -158,15 +156,13 @@ public class ExtraFieldUtils {
}
/**
- * Creates an instance of the appropriate ExtraField.
+ * Creates an instance of the appropriate {@link ZipExtraField}.
*
* @param headerId the header identifier
- * @return an instance of the appropriate ExtraField or null if the id is not supported
- * @throws InstantiationException if unable to instantiate the class
- * @throws IllegalAccessException if not allowed to instantiate the class
+ * @return an instance of the appropriate {@link ZipExtraField} or null if the id is not supported
* @since 1.19
*/
- public static ZipExtraField createExtraFieldNoDefault(final ZipShort headerId) throws InstantiationException, IllegalAccessException {
+ public static ZipExtraField createExtraFieldNoDefault(final ZipShort headerId) {
final Supplier<ZipExtraField> provider = IMPLEMENTATIONS.get(headerId);
return provider != null ? provider.get() : null;
}
(commons-compress) 06/07: Use a StringBuilder
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 e0bb5c312caf2a7c2254370fb7a09e2fb5ec5623
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 10 16:30:59 2024 -0500
Use a StringBuilder
- Camel case private method name
- Private method does not throw exception
---
.../compress/archivers/zip/ZipSplitOutputStream.java | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java
index 594927bde..c1c9ccccf 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java
@@ -130,7 +130,7 @@ final class ZipSplitOutputStream extends RandomAccessOutputStream {
* @throws IOException
*/
private Path createNewSplitSegmentFile(final Integer zipSplitSegmentSuffixIndex) throws IOException {
- final Path newFile = getSplitSegmentFilename(zipSplitSegmentSuffixIndex);
+ final Path newFile = getSplitSegmentFileName(zipSplitSegmentSuffixIndex);
if (Files.exists(newFile)) {
throw new IOException("split ZIP segment " + newFile + " already exists");
@@ -163,21 +163,19 @@ final class ZipSplitOutputStream extends RandomAccessOutputStream {
return currentSplitSegmentIndex;
}
- private Path getSplitSegmentFilename(final Integer zipSplitSegmentSuffixIndex) throws IOException {
+ private Path getSplitSegmentFileName(final Integer zipSplitSegmentSuffixIndex) {
final int newZipSplitSegmentSuffixIndex = zipSplitSegmentSuffixIndex == null ? currentSplitSegmentIndex + 2 : zipSplitSegmentSuffixIndex;
final String baseName = FileNameUtils.getBaseName(zipFile);
- String extension = ".z";
+ final StringBuilder extension = new StringBuilder(".z");
if (newZipSplitSegmentSuffixIndex <= 9) {
- extension += "0" + newZipSplitSegmentSuffixIndex;
+ extension.append("0").append(newZipSplitSegmentSuffixIndex);
} else {
- extension += newZipSplitSegmentSuffixIndex;
+ extension.append(newZipSplitSegmentSuffixIndex);
}
final Path parent = zipFile.getParent();
final String dir = Objects.nonNull(parent) ? parent.toAbsolutePath().toString() : ".";
- final Path newFile = zipFile.getFileSystem().getPath(dir, baseName + extension);
-
- return newFile;
+ return zipFile.getFileSystem().getPath(dir, baseName + extension.toString());
}
/**
(commons-compress) 04/07: Javadoc
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 f1ce1241faedc4eea7fd8d9951f7512346eaa956
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 10 16:23:27 2024 -0500
Javadoc
Format tweak
---
.../compress/archivers/zip/ExtraFieldParsingBehavior.java | 7 +++----
.../commons/compress/archivers/zip/ZipArchiveEntry.java | 12 ++++--------
2 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldParsingBehavior.java b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldParsingBehavior.java
index 30cf205d1..dade47944 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldParsingBehavior.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldParsingBehavior.java
@@ -24,9 +24,9 @@ import java.util.zip.ZipException;
* @since 1.19
*/
public interface ExtraFieldParsingBehavior extends UnparseableExtraFieldBehavior {
+
/**
* Creates an instance of ZipExtraField for the given id.
- *
* <p>
* A good default implementation would be {@link ExtraFieldUtils#createExtraField}.
* </p>
@@ -34,14 +34,13 @@ public interface ExtraFieldParsingBehavior extends UnparseableExtraFieldBehavior
* @param headerId the id for the extra field
* @return an instance of ZipExtraField, must not be {@code null}
* @throws ZipException if an error occurs
- * @throws InstantiationException if unable to instantiate the class
- * @throws IllegalAccessException if not allowed to instantiate the class
+ * @throws InstantiationException if unable to instantiate the class, not thrown by Commons Compress.
+ * @throws IllegalAccessException if not allowed to instantiate the class, not thrown by Commons Compress.
*/
ZipExtraField createExtraField(ZipShort headerId) throws ZipException, InstantiationException, IllegalAccessException;
/**
* Fills in the extra field data for a single extra field.
- *
* <p>
* A good default implementation would be {@link ExtraFieldUtils#fillExtraField}.
* </p>
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
index 71ed48aae..17e7383a0 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
@@ -1104,8 +1104,7 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry implements ArchiveEn
}
}
- private ZipExtraField[] parseExtraFields(final byte[] data, final boolean local,
- final ExtraFieldParsingBehavior parsingBehavior) throws ZipException {
+ private ZipExtraField[] parseExtraFields(final byte[] data, final boolean local, final ExtraFieldParsingBehavior parsingBehavior) throws ZipException {
if (extraFieldFactory != null) {
return ExtraFieldUtils.parse(data, local, new ExtraFieldParsingBehavior() {
@Override
@@ -1115,16 +1114,13 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry implements ArchiveEn
}
@Override
- public ZipExtraField fill(final ZipExtraField field,
- final byte[] data, final int off, final int len,
- final boolean local) throws ZipException {
+ public ZipExtraField fill(final ZipExtraField field, final byte[] data, final int off, final int len, final boolean local) throws ZipException {
return parsingBehavior.fill(field, data, off, len, local);
}
@Override
- public ZipExtraField onUnparseableExtraField(
- final byte[] data, final int off, final int len,
- final boolean local, final int claimedLength) throws ZipException {
+ public ZipExtraField onUnparseableExtraField(final byte[] data, final int off, final int len, final boolean local, final int claimedLength)
+ throws ZipException {
return parsingBehavior.onUnparseableExtraField(data, off, len, local, claimedLength);
}
});
(commons-compress) 05/07: Sort members
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 1c17e0c6ef4107f74fc5de2a8ae7a3982ba977ee
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 10 16:23:53 2024 -0500
Sort members
---
.../archivers/zip/ZipArchiveInputStream.java | 38 +++++++++++-----------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
index d3b493fd6..3171c0182 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
@@ -366,16 +366,6 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i
buf.limit(0);
}
- /**
- * Enable custom extra fields factory.
- * @param extraFieldSupport the lookup function based on extra field header id.
- * @return the archive.
- */
- public ZipArchiveInputStream setExtraFieldSupport(final Function<ZipShort, ZipExtraField> extraFieldSupport) {
- this.extraFieldSupport = extraFieldSupport;
- return this;
- }
-
/**
* Checks whether the current buffer contains the signature of a "data descriptor", "local file header" or "central directory
* entry".
@@ -1101,6 +1091,15 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i
readFully(b, 0);
}
+ private void readFully(final byte[] b, final int off) throws IOException {
+ final int len = b.length - off;
+ final int count = IOUtils.readFully(in, b, off, len);
+ count(count);
+ if (count < len) {
+ throw new EOFException();
+ }
+ }
+
// End of Central Directory Record
// end of central dir signature WORD
// number of this disk SHORT
@@ -1118,15 +1117,6 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i
// .ZIP file comment up to 64KB
//
- private void readFully(final byte[] b, final int off) throws IOException {
- final int len = b.length - off;
- final int count = IOUtils.readFully(in, b, off, len);
- count(count);
- if (count < len) {
- throw new EOFException();
- }
- }
-
/**
* Reads bytes by reading from the underlying stream rather than the (potentially inflating) archive stream - which {@link #read} would do.
*
@@ -1261,6 +1251,16 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i
throw new IllegalArgumentException();
}
+ /**
+ * Enable custom extra fields factory.
+ * @param extraFieldSupport the lookup function based on extra field header id.
+ * @return the archive.
+ */
+ public ZipArchiveInputStream setExtraFieldSupport(final Function<ZipShort, ZipExtraField> extraFieldSupport) {
+ this.extraFieldSupport = extraFieldSupport;
+ return this;
+ }
+
/**
* Skips over and discards value bytes of data from this input stream.
* <p>
(commons-compress) 07/07: Javadoc
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 392cb9ca313665f50af196cc1c26d66bc1ff28ac
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 10 16:31:51 2024 -0500
Javadoc
---
.../commons/compress/archivers/zip/ZipSplitOutputStream.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java
index c1c9ccccf..17b75ddea 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java
@@ -120,10 +120,13 @@ final class ZipSplitOutputStream extends RandomAccessOutputStream {
* <p>
* 8.3.3 Split ZIP files are typically written to the same location and are subject to name collisions if the spanned name format is used since each segment
* will reside on the same drive. To avoid name collisions, split archives are named as follows.
+ * </p>
* <p>
* Segment 1 = filename.z01 Segment n-1 = filename.z(n-1) Segment n = filename.zip
+ * </p>
* <p>
* NOTE: The ZIP split segment begin from 1,2,3,... , and we're creating a new segment, so the new segment suffix should be (currentSplitSegmentIndex + 2)
+ * </p>
*
* @param zipSplitSegmentSuffixIndex
* @return
@@ -214,6 +217,7 @@ final class ZipSplitOutputStream extends RandomAccessOutputStream {
* <p>
* 4.4.1.5 The end of central directory record and the Zip64 end of central directory locator record MUST reside on the same disk when splitting or spanning
* an archive.
+ * </p>
*
* @param unsplittableContentSize
* @throws IllegalArgumentException
@@ -236,7 +240,7 @@ final class ZipSplitOutputStream extends RandomAccessOutputStream {
}
/**
- * Write the data to ZIP split segments, if the remaining space of current split segment is not enough, then a new split segment should be created
+ * Writes the data to ZIP split segments, if the remaining space of current split segment is not enough, then a new split segment should be created
*
* @param b data to write
* @param off offset of the start of data in param b
@@ -309,7 +313,7 @@ final class ZipSplitOutputStream extends RandomAccessOutputStream {
}
/**
- * Write the ZIP split signature (0x08074B50) to the head of the first ZIP split segment
+ * Writes the ZIP split signature (0x08074B50) to the head of the first ZIP split segment
*
* @throws IOException
*/
(commons-compress) 03/07: Remove unused exceptions
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 436ed771ef9eb1816a136ef0ff575cb49839db39
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 10 16:20:26 2024 -0500
Remove unused exceptions
Binary compatible
---
.../org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java | 3 ++-
.../org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
index 1ca0c66e0..2a6b7f6d8 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
@@ -350,8 +350,9 @@ public class ExtraFieldUtils {
*/
public static ZipExtraField[] parse(final byte[] data, final boolean local, final UnparseableExtraField onUnparseableData) throws ZipException {
return parse(data, local, new ExtraFieldParsingBehavior() {
+
@Override
- public ZipExtraField createExtraField(final ZipShort headerId) throws ZipException, InstantiationException, IllegalAccessException {
+ public ZipExtraField createExtraField(final ZipShort headerId) {
return ExtraFieldUtils.createExtraField(headerId);
}
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
index b362b3676..71ed48aae 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
@@ -180,7 +180,7 @@ public class ZipArchiveEntry extends java.util.zip.ZipEntry implements ArchiveEn
}
@Override
- public ZipExtraField createExtraField(final ZipShort headerId) throws ZipException, InstantiationException, IllegalAccessException {
+ public ZipExtraField createExtraField(final ZipShort headerId) {
return ExtraFieldUtils.createExtraField(headerId);
}