COMPRESS-280 don't call read in TarArchiveInputStream#skip
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/compress/trunk@1591813 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 80a705f..4fc2974 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -83,6 +83,11 @@
encounters a truncated archive while reading from the last
entry.
</action>
+ <action type="fix" date="2014-05-02" issue="COMPRESS-280"
+ due-to="BELUGA BEHR">
+ Adapted TarArchiveInputStream#skip to the modified
+ IOUtils#skip method.
+ </action>
</release>
<release version="1.8" date="2014-03-12"
description="Release 1.8">
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index 6f0c6a4..9cc6b35 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -180,23 +180,28 @@
return (int) (entrySize - entryOffset);
}
+
/**
- * Skip bytes in the input buffer. This skips bytes in the
- * current entry's data, not the entire archive, and will
- * stop at the end of the current entry's data if the number
- * to skip extends beyond that point.
- *
- * @param numToSkip The number of bytes to skip.
- * @return the number actually skipped
- * @throws IOException on error
+ * Skips over and discards <code>n</code> bytes of data from this input
+ * stream. The <code>skip</code> method may, for a variety of reasons, end
+ * up skipping over some smaller number of bytes, possibly <code>0</code>.
+ * This may result from any of a number of conditions; reaching end of file
+ * or end of entry before <code>n</code> bytes have been skipped; are only
+ * two possibilities. The actual number of bytes skipped is returned. If
+ * <code>n</code> is negative, no bytes are skipped.
+ *
+ *
+ * @param n
+ * the number of bytes to be skipped.
+ * @return the actual number of bytes skipped.
+ * @exception IOException
+ * if some other I/O error occurs.
*/
@Override
- public long skip(long numToSkip) throws IOException {
+ public long skip(final long n) throws IOException {
- long available = entrySize - entryOffset;
- numToSkip = Math.min(numToSkip, available);
-
- long skipped = IOUtils.skip(is, numToSkip);
+ final long available = entrySize - entryOffset;
+ final long skipped = is.skip(Math.min(n, available));
count(skipped);
entryOffset += skipped;
return skipped;
@@ -229,7 +234,7 @@
if (currEntry != null) {
/* Skip will only go to the end of the current entry */
- skip(Long.MAX_VALUE);
+ IOUtils.skip(this, Long.MAX_VALUE);
/* skip to the end of the last record */
skipRecordPadding();