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 0df503de8cb080117191e07091c748db5aa33e26
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Feb 17 10:13:46 2024 -0500

    Reuse IOUtils.readRange()
---
 .../compress/harmony/unpack200/SegmentHeader.java  | 28 ++--------------------
 1 file changed, 2 insertions(+), 26 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
 
b/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
index 01b1b12d4..a83057518 100644
--- 
a/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
+++ 
b/src/main/java/org/apache/commons/compress/harmony/unpack200/SegmentHeader.java
@@ -17,13 +17,13 @@
 package org.apache.commons.compress.harmony.unpack200;
 
 import java.io.ByteArrayInputStream;
-import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 
 import org.apache.commons.compress.harmony.pack200.BHSDCodec;
 import org.apache.commons.compress.harmony.pack200.Codec;
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
+import org.apache.commons.compress.utils.IOUtils;
 
 /**
  * SegmentHeader is the header band of a {@link Segment}
@@ -299,36 +299,12 @@ public class SegmentHeader {
         parseClassCounts(in);
 
         if (getBandHeadersSize() > 0) {
-            final byte[] bandHeaders = new byte[getBandHeadersSize()];
-            readFully(in, bandHeaders);
-            setBandHeadersData(bandHeaders);
+            setBandHeadersData(IOUtils.readRange(in, getBandHeadersSize()));
         }
 
         archiveSizeOffset -= in.available();
     }
 
-    /**
-     * Completely reads in a byte array, akin to the implementation in {@link 
java.io.DataInputStream}. TODO Refactor out into a separate InputStream handling
-     * class
-     *
-     * @param in   the input stream to read from
-     * @param data the byte array to read into
-     * @throws IOException if a problem occurs during reading from the 
underlying stream
-     */
-    private void readFully(final InputStream in, final byte[] data) throws 
IOException {
-        int total = in.read(data);
-        if (total == -1) {
-            throw new EOFException("Failed to read any data from input 
stream");
-        }
-        while (total < data.length) {
-            final int delta = in.read(data, total, data.length - total);
-            if (delta == -1) {
-                throw new EOFException("Failed to read some data from input 
stream");
-            }
-            total += delta;
-        }
-    }
-
     /**
      * Sets the major version of this archive.
      *

Reply via email to