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 e1342d9849393dbe75188738b2798ff03b872954 Author: Gary Gregory <[email protected]> AuthorDate: Thu May 5 09:29:36 2022 -0400 Refactor commons code. --- .../compress/utils/ChecksumVerifyingInputStream.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStream.java b/src/main/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStream.java index 89eee317..62eca310 100644 --- a/src/main/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStream.java +++ b/src/main/java/org/apache/commons/compress/utils/ChecksumVerifyingInputStream.java @@ -28,6 +28,7 @@ import java.util.zip.Checksum; * @since 1.7 */ public class ChecksumVerifyingInputStream extends InputStream { + private final InputStream in; private long bytesRemaining; private final long expectedChecksum; @@ -78,9 +79,7 @@ public class ChecksumVerifyingInputStream extends InputStream { checksum.update(ret); --bytesRemaining; } - if (bytesRemaining <= 0 && expectedChecksum != checksum.getValue()) { - throw new IOException("Checksum verification failed"); - } + verify(); return ret; } @@ -111,9 +110,7 @@ public class ChecksumVerifyingInputStream extends InputStream { checksum.update(b, off, ret); bytesRemaining -= ret; } - if (bytesRemaining <= 0 && expectedChecksum != checksum.getValue()) { - throw new IOException("Checksum verification failed"); - } + verify(); return ret; } @@ -122,4 +119,10 @@ public class ChecksumVerifyingInputStream extends InputStream { // Can't really skip, we have to hash everything to verify the checksum return read() >= 0 ? 1 : 0; } + + private void verify() throws IOException { + if (bytesRemaining <= 0 && expectedChecksum != checksum.getValue()) { + throw new IOException("Checksum verification failed"); + } + } }
