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 938fec4c2d5ad84a8bf3f36f201cddef0c05ab1d Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Jan 26 14:55:21 2024 -0500 Revert "Update comment" This reverts commit ea6ea52abb69bc4e261f80cdb4a7c3ffbcc1b06b. --- .../compress/archivers/ArchiveInputStream.java | 20 ++++++++++++++++++-- .../archivers/zip/ZipArchiveInputStream.java | 14 +++++++------- .../apache/commons/compress/utils/FileNameUtils.java | 2 +- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java index a41e38064..446cf3d73 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java @@ -18,13 +18,13 @@ */ package org.apache.commons.compress.archivers; +import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import org.apache.commons.io.Charsets; import org.apache.commons.io.input.NullInputStream; -import org.apache.commons.io.input.ProxyInputStream; /** * Archive input streams <b>MUST</b> override the {@link #read(byte[], int, int)} - or {@link #read()} - method so that reading from the stream generates EOF @@ -44,7 +44,7 @@ import org.apache.commons.io.input.ProxyInputStream; * * @param <E> The type of {@link ArchiveEntry} produced. */ -public abstract class ArchiveInputStream<E extends ArchiveEntry> extends ProxyInputStream { +public abstract class ArchiveInputStream<E extends ArchiveEntry> extends FilterInputStream { private static final int BYTE_MASK = 0xFF; @@ -170,4 +170,20 @@ public abstract class ArchiveInputStream<E extends ArchiveEntry> extends ProxyIn bytesRead -= pushedBack; } + /** + * Reads a byte of data. This method will block until enough input is available. + * + * Simply calls the {@link #read(byte[], int, int)} method. + * + * MUST be overridden if the {@link #read(byte[], int, int)} method is not overridden; may be overridden otherwise. + * + * @return the byte read, or -1 if end of input is reached + * @throws IOException if an I/O error has occurred + */ + @Override + public int read() throws IOException { + final int num = read(single, 0, 1); + return num == -1 ? -1 : single[0] & BYTE_MASK; + } + } diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java index f1392297b..078ad68cf 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java @@ -435,7 +435,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i if (!closed) { closed = true; try { - super.close(); + in.close(); } finally { inf.end(); } @@ -515,7 +515,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i private void drainCurrentEntryData() throws IOException { long remaining = current.entry.getCompressedSize() - current.bytesReadFromStream; while (remaining > 0) { - final long n = super.read(buf.array(), 0, (int) Math.min(buf.capacity(), remaining)); + final long n = in.read(buf.array(), 0, (int) Math.min(buf.capacity(), remaining)); if (n < 0) { throw new EOFException("Truncated ZIP entry: " + ArchiveUtils.sanitize(current.entry.getName())); } @@ -528,7 +528,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i if (closed) { throw new IOException("The stream is closed"); } - final int length = super.read(buf.array()); + final int length = in.read(buf.array()); if (length > 0) { buf.limit(length); count(buf.limit()); @@ -1078,7 +1078,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i * Also updates bytes-read counter. */ private int readOneByte() throws IOException { - final int b = super.read(); + final int b = in.read(); if (b != -1) { count(1); } @@ -1113,7 +1113,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i if (buf.position() >= buf.limit()) { buf.position(0); - final int l = super.read(buf.array()); + final int l = in.read(buf.array()); if (l == -1) { buf.limit(0); throw new IOException("Truncated ZIP file"); @@ -1157,7 +1157,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i final int ddLen = current.usesZip64 ? WORD + 2 * DWORD : 3 * WORD; while (!done) { - final int r = super.read(buf.array(), off, ZipArchiveOutputStream.BUFFER_SIZE - off); + final int r = in.read(buf.array(), off, ZipArchiveOutputStream.BUFFER_SIZE - off); if (r <= 0) { // read the whole archive without ever finding a // central directory @@ -1194,7 +1194,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream<ZipArchiveEntry> i long skipped = 0; while (skipped < value) { final long rem = value - skipped; - final int x = super.read(skipBuf, 0, (int) (skipBuf.length > rem ? rem : skipBuf.length)); + final int x = in.read(skipBuf, 0, (int) (skipBuf.length > rem ? rem : skipBuf.length)); if (x == -1) { return; } diff --git a/src/main/java/org/apache/commons/compress/utils/FileNameUtils.java b/src/main/java/org/apache/commons/compress/utils/FileNameUtils.java index 3df0a3e88..1ec6d747e 100644 --- a/src/main/java/org/apache/commons/compress/utils/FileNameUtils.java +++ b/src/main/java/org/apache/commons/compress/utils/FileNameUtils.java @@ -40,7 +40,7 @@ public class FileNameUtils { * @since 1.22 */ public static String getBaseName(final Path path) { - // TODO Use Commons IO 2.16.0 + // TODO Use Commons IO 2.17.0 if (path == null) { return null; }