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 2024/03/02 01:27:20 UTC

(commons-compress) 01/04: Simplify

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 bdd319eccad59c7b3f01798b17a84bbbd1a8ecc0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Mar 1 20:13:53 2024 -0500

    Simplify
---
 .../org/apache/commons/compress/utils/IOUtils.java | 27 ++++------------------
 1 file changed, 4 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/utils/IOUtils.java b/src/main/java/org/apache/commons/compress/utils/IOUtils.java
index 893d54d88..162bc9d29 100644
--- a/src/main/java/org/apache/commons/compress/utils/IOUtils.java
+++ b/src/main/java/org/apache/commons/compress/utils/IOUtils.java
@@ -272,37 +272,18 @@ public final class IOUtils {
     }
 
     /**
-     * Skips the given number of bytes by repeatedly invoking skip on the given input stream if necessary.
-     * <p>
-     * In a case where the stream's skip() method returns 0 before the requested number of bytes has been skip this implementation will fall back to using the
-     * read() method.
-     * </p>
+     * Skips bytes from an input byte stream.
      * <p>
      * This method will only skip less than the requested number of bytes if the end of the input stream has been reached.
      * </p>
      *
      * @param input     stream to skip bytes in
-     * @param numToSkip the number of bytes to skip
+     * @param toSkip the number of bytes to skip
      * @return the number of bytes actually skipped
      * @throws IOException on error
      */
-    public static long skip(final InputStream input, long numToSkip) throws IOException {
-        final long available = numToSkip;
-        while (numToSkip > 0) {
-            final long skipped = input.skip(numToSkip);
-            if (skipped == 0) {
-                break;
-            }
-            numToSkip -= skipped;
-        }
-        while (numToSkip > 0) {
-            final int read = readFully(input, SKIP_BUF, 0, (int) Math.min(numToSkip, org.apache.commons.io.IOUtils.DEFAULT_BUFFER_SIZE));
-            if (read < 1) {
-                break;
-            }
-            numToSkip -= read;
-        }
-        return available - numToSkip;
+    public static long skip(final InputStream input, long toSkip) throws IOException {
+        return org.apache.commons.io.IOUtils.skip(input, toSkip, org.apache.commons.io.IOUtils::byteArray);
     }
 
     /**