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 2022/03/18 20:09:46 UTC
[commons-compress] branch master updated (6436e56 -> 88cb3fb)
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 6436e56 Tests COMPRESS-598.
new 8b54008 [COMPRESS-598] The NullPointerException now carries a simple message.
new 88cb3fb [COMPRESS-598] Refactor commons code.
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:
.../archivers/zip/ZipArchiveInputStream.java | 38 ++++++++++++----------
1 file changed, 20 insertions(+), 18 deletions(-)
[commons-compress] 02/02: [COMPRESS-598] Refactor commons code.
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 88cb3fb8d3908a6c35ad75e1ba2a8cd1a4be98d5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Mar 18 16:09:43 2022 -0400
[COMPRESS-598] Refactor commons code.
---
.../compress/archivers/zip/ZipArchiveInputStream.java | 19 +++++++------------
1 file changed, 7 insertions(+), 12 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 7f05535..7503e2a 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
@@ -550,22 +550,17 @@ public class ZipArchiveInputStream extends ArchiveInputStream implements InputSt
@SuppressWarnings("resource") // checkInputStream() does not allocate.
@Override
public long getCompressedCount() {
- if (current.entry.getMethod() == ZipArchiveOutputStream.STORED) {
+ final int method = current.entry.getMethod();
+ if (method == ZipArchiveOutputStream.STORED) {
return current.bytesRead;
}
- if (current.entry.getMethod() == ZipArchiveOutputStream.DEFLATED) {
+ if (method == ZipArchiveOutputStream.DEFLATED) {
return getBytesInflated();
}
- if (current.entry.getMethod() == ZipMethod.UNSHRINKING.getCode()) {
- return ((InputStreamStatistics) current.checkInputStream()).getCompressedCount();
- }
- if (current.entry.getMethod() == ZipMethod.IMPLODING.getCode()) {
- return ((InputStreamStatistics) current.checkInputStream()).getCompressedCount();
- }
- if (current.entry.getMethod() == ZipMethod.ENHANCED_DEFLATED.getCode()) {
- return ((InputStreamStatistics) current.checkInputStream()).getCompressedCount();
- }
- if (current.entry.getMethod() == ZipMethod.BZIP2.getCode()) {
+ if (method == ZipMethod.UNSHRINKING.getCode()
+ || method == ZipMethod.IMPLODING.getCode()
+ || method == ZipMethod.ENHANCED_DEFLATED.getCode()
+ || method == ZipMethod.BZIP2.getCode()) {
return ((InputStreamStatistics) current.checkInputStream()).getCompressedCount();
}
return -1;
[commons-compress] 01/02: [COMPRESS-598] The NullPointerException now carries a simple message.
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 8b54008d53098078bc284c81dfc323bdc366f9fc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Mar 18 16:08:25 2022 -0400
[COMPRESS-598] The NullPointerException now carries a simple message.
---
.../archivers/zip/ZipArchiveInputStream.java | 25 ++++++++++++++--------
1 file changed, 16 insertions(+), 9 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 b303236..7f05535 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
@@ -18,6 +18,11 @@
*/
package org.apache.commons.compress.archivers.zip;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.SHORT;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
+import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MAGIC;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
@@ -27,6 +32,7 @@ import java.io.PushbackInputStream;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.Arrays;
+import java.util.Objects;
import java.util.zip.CRC32;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
@@ -41,11 +47,6 @@ import org.apache.commons.compress.utils.ArchiveUtils;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.compress.utils.InputStreamStatistics;
-import static org.apache.commons.compress.archivers.zip.ZipConstants.DWORD;
-import static org.apache.commons.compress.archivers.zip.ZipConstants.SHORT;
-import static org.apache.commons.compress.archivers.zip.ZipConstants.WORD;
-import static org.apache.commons.compress.archivers.zip.ZipConstants.ZIP64_MAGIC;
-
/**
* Implements an input stream that can read Zip archives.
*
@@ -546,6 +547,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream implements InputSt
/**
* @since 1.17
*/
+ @SuppressWarnings("resource") // checkInputStream() does not allocate.
@Override
public long getCompressedCount() {
if (current.entry.getMethod() == ZipArchiveOutputStream.STORED) {
@@ -555,16 +557,16 @@ public class ZipArchiveInputStream extends ArchiveInputStream implements InputSt
return getBytesInflated();
}
if (current.entry.getMethod() == ZipMethod.UNSHRINKING.getCode()) {
- return ((UnshrinkingInputStream) current.inputStream).getCompressedCount();
+ return ((InputStreamStatistics) current.checkInputStream()).getCompressedCount();
}
if (current.entry.getMethod() == ZipMethod.IMPLODING.getCode()) {
- return ((ExplodingInputStream) current.inputStream).getCompressedCount();
+ return ((InputStreamStatistics) current.checkInputStream()).getCompressedCount();
}
if (current.entry.getMethod() == ZipMethod.ENHANCED_DEFLATED.getCode()) {
- return ((Deflate64CompressorInputStream) current.inputStream).getCompressedCount();
+ return ((InputStreamStatistics) current.checkInputStream()).getCompressedCount();
}
if (current.entry.getMethod() == ZipMethod.BZIP2.getCode()) {
- return ((BZip2CompressorInputStream) current.inputStream).getCompressedCount();
+ return ((InputStreamStatistics) current.checkInputStream()).getCompressedCount();
}
return -1;
}
@@ -1320,6 +1322,11 @@ public class ZipArchiveInputStream extends ArchiveInputStream implements InputSt
* The input stream decompressing the data for shrunk and imploded entries.
*/
private InputStream inputStream;
+
+ @SuppressWarnings("unchecked") // Caller beware
+ private <T extends InputStream> T checkInputStream() {
+ return (T) Objects.requireNonNull(inputStream, "inputStream");
+ }
}
/**