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


The following commit(s) were added to refs/heads/master by this push:
     new da84b77c3 Reuse commons-io, don't duplicate class BoundedInputStream 
(deprecated class)
da84b77c3 is described below

commit da84b77c32d77f69a9aa0eb427e3a9ba09490188
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Dec 21 22:57:19 2023 -0500

    Reuse commons-io, don't duplicate class BoundedInputStream (deprecated
    class)
---
 src/changes/changes.xml                            |  3 +-
 .../commons/compress/utils/BoundedInputStream.java | 58 +++-------------------
 2 files changed, 8 insertions(+), 53 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ecdf2ce10..7f566515c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -55,7 +55,8 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Reuse 
commons-codec, don't duplicate class PureJavaCrc32C (removed package-private 
class).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Reuse 
commons-codec, don't duplicate class XXHash32 (deprecated class).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Reuse 
commons-io, don't duplicate class Charsets (deprecated class).</action>
-      <action type="fix" dev="ggregory" due-to="Gary Gregory">Reuse 
commons-io, don't duplicate class IOUtils (deprecated class).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Reuse 
commons-io, don't duplicate class IOUtils (deprecated methods).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Reuse 
commons-io, don't duplicate class BoundedInputStream (deprecated 
class).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Reuse 
Arrays.equals(byte[], byte[]) and deprecate ArchiveUtils.isEqual(byte[], 
byte[]).</action>
       <action type="fix" dev="ggregory" due-to="alumi, Gary Gregory">Add a 
null-check for the class loader of OsgiUtils #451.</action>
       <action type="fix" dev="ggregory" due-to="alumi, Gary Gregory">Add a 
null-check in Pack200.newInstance(String, String).</action>
diff --git 
a/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java 
b/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
index 620e227fd..8da853372 100644
--- a/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
+++ b/src/main/java/org/apache/commons/compress/utils/BoundedInputStream.java
@@ -16,8 +16,6 @@
  */
 package org.apache.commons.compress.utils;
 
-import java.io.FilterInputStream;
-import java.io.IOException;
 import java.io.InputStream;
 
 /**
@@ -25,9 +23,10 @@ import java.io.InputStream;
  *
  * @NotThreadSafe
  * @since 1.6
+ * @deprecated Use {@link org.apache.commons.io.input.BoundedInputStream}.
  */
-public class BoundedInputStream extends FilterInputStream {
-    private long bytesRemaining;
+@Deprecated
+public class BoundedInputStream extends 
org.apache.commons.io.input.BoundedInputStream {
 
     /**
      * Creates the stream that will at most read the given amount of bytes 
from the given stream.
@@ -36,14 +35,8 @@ public class BoundedInputStream extends FilterInputStream {
      * @param size the maximum amount of bytes to read
      */
     public BoundedInputStream(final InputStream in, final long size) {
-        super(in);
-        bytesRemaining = size;
-    }
-
-    @Override
-    public void close() {
-        // there isn't anything to close in this stream and the nested
-        // stream is controlled externally
+        super(in, size);
+        setPropagateClose(false);
     }
 
     /**
@@ -53,46 +46,7 @@ public class BoundedInputStream extends FilterInputStream {
      * @since 1.21
      */
     public long getBytesRemaining() {
-        return bytesRemaining;
-    }
-
-    @Override
-    public int read() throws IOException {
-        if (bytesRemaining > 0) {
-            --bytesRemaining;
-            return in.read();
-        }
-        return -1;
-    }
-
-    @Override
-    public int read(final byte[] b, final int off, final int len) throws 
IOException {
-        if (len == 0) {
-            return 0;
-        }
-        if (bytesRemaining == 0) {
-            return -1;
-        }
-        int bytesToRead = len;
-        if (bytesToRead > bytesRemaining) {
-            bytesToRead = (int) bytesRemaining;
-        }
-        final int bytesRead = in.read(b, off, bytesToRead);
-        if (bytesRead >= 0) {
-            bytesRemaining -= bytesRead;
-        }
-        return bytesRead;
+        return getMaxLength() - getCount();
     }
 
-    /**
-     * @since 1.20
-     */
-    @Override
-    public long skip(final long n) throws IOException {
-        final long bytesToSkip = Math.min(bytesRemaining, n);
-        final long bytesSkipped = in.skip(bytesToSkip);
-        bytesRemaining -= bytesSkipped;
-
-        return bytesSkipped;
-    }
 }

Reply via email to