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 03703d7323b4109bcc77753707477556a33975fd
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Mon Dec 23 08:26:23 2024 -0500

    Don't use deprecated code in TarFile
---
 src/changes/changes.xml                                        |  1 +
 .../org/apache/commons/compress/archivers/tar/TarFile.java     | 10 ++--------
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 03f4dd3c2..5a7d7b3b2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -58,6 +58,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">ZipArchiveOutputStream.close() does not close its underlying output 
stream.</action> 
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">ZipArchiveOutputStream.close() does not close its underlying output 
stream.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Don't use 
deprecated code in TarArchiveInputStream.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Don't use 
deprecated code in TarFile.</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
GzipParameters.setModificationInstant(Instant).</action>
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java
index 694e9eff8..53dbabde4 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java
@@ -36,9 +36,9 @@ import org.apache.commons.compress.archivers.zip.ZipEncoding;
 import org.apache.commons.compress.archivers.zip.ZipEncodingHelper;
 import org.apache.commons.compress.utils.ArchiveUtils;
 import org.apache.commons.compress.utils.BoundedArchiveInputStream;
-import org.apache.commons.compress.utils.BoundedInputStream;
 import org.apache.commons.compress.utils.BoundedSeekableByteChannelInputStream;
 import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
+import org.apache.commons.io.input.BoundedInputStream;
 
 /**
  * Provides random access to Unix archives.
@@ -334,9 +334,7 @@ public class TarFile implements Closeable {
      */
     private void buildSparseInputStreams() throws IOException {
         final List<InputStream> streams = new ArrayList<>();
-
         final List<TarArchiveStructSparse> sparseHeaders = 
currEntry.getOrderedSparseHeaders();
-
         // Stream doesn't need to be closed at all as it doesn't use any 
resources
         final InputStream zeroInputStream = new 
TarArchiveSparseZeroInputStream(); // NOSONAR
         // logical offset into the extracted entry
@@ -348,13 +346,11 @@ public class TarFile implements Closeable {
                 // sparse header says to move backwards inside the extracted 
entry
                 throw new IOException("Corrupted struct sparse detected");
             }
-
             // only store the zero block if it is not empty
             if (zeroBlockSize > 0) {
-                streams.add(new BoundedInputStream(zeroInputStream, 
zeroBlockSize));
+                
streams.add(BoundedInputStream.builder().setInputStream(zeroInputStream).setMaxCount(zeroBlockSize).get());
                 numberOfZeroBytesInSparseEntry += zeroBlockSize;
             }
-
             // only store the input streams with non-zero size
             if (sparseHeader.getNumbytes() > 0) {
                 final long start = currEntry.getDataOffset() + 
sparseHeader.getOffset() - numberOfZeroBytesInSparseEntry;
@@ -364,10 +360,8 @@ public class TarFile implements Closeable {
                 }
                 streams.add(new BoundedSeekableByteChannelInputStream(start, 
sparseHeader.getNumbytes(), archive));
             }
-
             offset = sparseHeader.getOffset() + sparseHeader.getNumbytes();
         }
-
         sparseInputStreams.put(currEntry.getName(), streams);
     }
 

Reply via email to