You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2017/05/10 10:31:17 UTC

commons-compress git commit: readFully's return value is useless, it throws an exception at EOF

Repository: commons-compress
Updated Branches:
  refs/heads/master 4ac67bf32 -> a4b0ee96f


readFully's return value is useless, it throws an exception at EOF


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/a4b0ee96
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/a4b0ee96
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/a4b0ee96

Branch: refs/heads/master
Commit: a4b0ee96fc87effd27a4c0af23835cce3647cc0c
Parents: 4ac67bf
Author: Stefan Bodewig <bo...@apache.org>
Authored: Wed May 10 12:20:12 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Wed May 10 12:20:12 2017 +0200

----------------------------------------------------------------------
 .../archivers/dump/TapeInputStream.java         | 45 +++++++++++---------
 1 file changed, 24 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/a4b0ee96/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java b/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java
index dcc3826..67b383f 100644
--- a/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/dump/TapeInputStream.java
@@ -126,8 +126,12 @@ class TapeInputStream extends FilterInputStream {
             // we need to read from the underlying stream.
             // this will reset readOffset value.
             // return -1 if there's a problem.
-            if ((readOffset == blockSize) && !readBlock(true)) {
-                return -1;
+            if (readOffset == blockSize) {
+                try {
+                    readBlock(true);
+                } catch (ShortFileException sfe) {
+                    return -1;
+                }
             }
 
             int n = 0;
@@ -173,9 +177,12 @@ class TapeInputStream extends FilterInputStream {
             // this will reset readOffset value. We do not perform
             // any decompression if we won't eventually read the data.
             // return -1 if there's a problem.
-            if ((readOffset == blockSize) &&
-                    !readBlock((len - bytes) < blockSize)) {
-                return -1;
+            if (readOffset == blockSize) {
+                try {
+                    readBlock((len - bytes) < blockSize);
+                } catch (ShortFileException sfe) {
+                    return -1;
+                }
             }
 
             long n = 0;
@@ -218,8 +225,12 @@ class TapeInputStream extends FilterInputStream {
         // we need to read from the underlying stream. This
         // isn't a problem since it would be the first step in
         // any subsequent read() anyway.
-        if ((readOffset == blockSize) && !readBlock(true)) {
-            return null;
+        if (readOffset == blockSize) {
+            try {
+                readBlock(true);
+            } catch (ShortFileException sfe) {
+                return null;
+            }
         }
 
         // copy data, increment counters.
@@ -254,21 +265,17 @@ class TapeInputStream extends FilterInputStream {
      *        This is an optimization for longer seeks.
      * @return false if End-Of-File, else true
      */
-    private boolean readBlock(final boolean decompress) throws IOException {
-        boolean success = true;
-
+    private void readBlock(final boolean decompress) throws IOException {
         if (in == null) {
             throw new IOException("input buffer is closed");
         }
 
         if (!isCompressed || (currBlkIdx == -1)) {
             // file is not compressed
-            success = readFully(blockBuffer, 0, blockSize);
+            readFully(blockBuffer, 0, blockSize);
             bytesRead += blockSize;
         } else {
-            if (!readFully(blockBuffer, 0, 4)) {
-                return false;
-            }
+            readFully(blockBuffer, 0, 4);
             bytesRead += 4;
 
             final int h = DumpArchiveUtil.convert32(blockBuffer, 0);
@@ -276,14 +283,14 @@ class TapeInputStream extends FilterInputStream {
 
             if (!compressed) {
                 // file is compressed but this block is not.
-                success = readFully(blockBuffer, 0, blockSize);
+                readFully(blockBuffer, 0, blockSize);
                 bytesRead += blockSize;
             } else {
                 // this block is compressed.
                 final int flags = (h >> 1) & 0x07;
                 int length = (h >> 4) & 0x0FFFFFFF;
                 final byte[] compBuffer = new byte[length];
-                success = readFully(compBuffer, 0, length);
+                readFully(compBuffer, 0, length);
                 bytesRead += length;
 
                 if (!decompress) {
@@ -327,21 +334,17 @@ class TapeInputStream extends FilterInputStream {
 
         currBlkIdx++;
         readOffset = 0;
-
-        return success;
     }
 
     /**
      * Read buffer
      */
-    private boolean readFully(final byte[] b, final int off, final int len)
+    private void readFully(final byte[] b, final int off, final int len)
         throws IOException {
         final int count = IOUtils.readFully(in, b, off, len);
         if (count < len) {
             throw new ShortFileException();
         }
-
-        return true;
     }
 
     /**