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 c925809fdae53cbbf036e75ce90f12759ceee580 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed May 21 09:41:03 2025 -0400 Add org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry.isEmptyStream() --- src/changes/changes.xml | 1 + .../compress/archivers/sevenz/SevenZArchiveEntry.java | 16 ++++++++++++++++ .../commons/compress/archivers/sevenz/SevenZFile.java | 4 ++-- .../compress/archivers/sevenz/SevenZOutputFile.java | 8 ++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2ae057437..98a74dc66 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -127,6 +127,7 @@ The <action> type attribute can be add,update,fix,remove. <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.compressors.CompressorException as the root for all custom exceptions ArchiveException and CompressorException.</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add ArchiveException.ArchiveException(String, Throwable).</action> <action type="add" dev="ggregory" due-to="Gary Gregory">Add ArchiveException.ArchiveException(Throwable).</action> + <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry.isEmptyStream().</action> <!-- UPDATE --> <action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory, sebb">Bump org.apache.commons:commons-parent from 72 to 84 #563, #567, #574, #582, #587, #595, #668.</action> <action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump com.github.luben:zstd-jni from 1.5.6-4 to 1.5.7-3 #565, #578, #601, #616, #630, #640, #642. Version 1.5.7-3 fixes https://github.com/luben/zstd-jni/pull/356</action> diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java index 441e3a232..56bee9585 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java @@ -359,6 +359,9 @@ public int hashCode() { /** * Tests whether there is any content associated with this entry. + * <p> + * Returns true if a content is present. + * </p> * * @return whether there is any content associated with this entry. */ @@ -385,6 +388,19 @@ public boolean isDirectory() { return isDirectory; } + /** + * Tests whether there is any content associated with this entry. + * <p> + * Returns true if a content is absent. + * </p> + * + * @return whether there is any content associated with this entry. + * @since 1.28.0 + */ + public boolean isEmptyStream() { + return !hasStream; + } + /** * Sets the access date. * diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index 0534f1554..9b95d3d03 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -901,7 +901,7 @@ private void calculateStreamMap(final Archive archive) throws IOException { int nextFolderIndex = 0; int nextFolderUnpackStreamIndex = 0; for (int i = 0; i < archive.files.length; i++) { - if (!archive.files[i].hasStream() && nextFolderUnpackStreamIndex == 0) { + if (archive.files[i].isEmptyStream() && nextFolderUnpackStreamIndex == 0) { fileFolderIndex[i] = -1; continue; } @@ -917,7 +917,7 @@ private void calculateStreamMap(final Archive archive) throws IOException { } } fileFolderIndex[i] = nextFolderIndex; - if (!archive.files[i].hasStream()) { + if (archive.files[i].isEmptyStream()) { continue; } ++nextFolderUnpackStreamIndex; diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java index 5ee042ef7..4d0e692bf 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java @@ -541,7 +541,7 @@ private void writeFileAntiItems(final DataOutput header) throws IOException { final BitSet antiItems = new BitSet(0); int antiItemCounter = 0; for (final SevenZArchiveEntry file1 : files) { - if (!file1.hasStream()) { + if (file1.isEmptyStream()) { final boolean isAnti = file1.isAntiItem(); antiItems.set(antiItemCounter++, isAnti); hasAntiItems |= isAnti; @@ -636,7 +636,7 @@ private void writeFileEmptyFiles(final DataOutput header) throws IOException { int emptyStreamCounter = 0; final BitSet emptyFiles = new BitSet(0); for (final SevenZArchiveEntry file1 : files) { - if (!file1.hasStream()) { + if (file1.isEmptyStream()) { final boolean isDir = file1.isDirectory(); emptyFiles.set(emptyStreamCounter++, !isDir); hasEmptyFiles |= !isDir; @@ -655,12 +655,12 @@ private void writeFileEmptyFiles(final DataOutput header) throws IOException { } private void writeFileEmptyStreams(final DataOutput header) throws IOException { - final boolean hasEmptyStreams = files.stream().anyMatch(entry -> !entry.hasStream()); + final boolean hasEmptyStreams = files.stream().anyMatch(SevenZArchiveEntry::isEmptyStream); if (hasEmptyStreams) { header.write(NID.kEmptyStream); final BitSet emptyStreams = new BitSet(files.size()); for (int i = 0; i < files.size(); i++) { - emptyStreams.set(i, !files.get(i).hasStream()); + emptyStreams.set(i, files.get(i).isEmptyStream()); } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream out = new DataOutputStream(baos);