Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 85 to 88 #707.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-lang3 from 3.18.0 to 3.19.0.</action>
<!-- REMOVE -->
<action type="remove" dev="pkarwasz" due-to="Piotr P. Karwasz">Deprecate IOUtils.readFully and IOUtils.skip.</action>
</release>
<release version="1.28.0" date="2025-07-26" description="This is a feature and maintenance release. Java 8 or later is required.">
<!-- FIX -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.compress.utils.Sets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;

/**
Expand Down Expand Up @@ -218,7 +218,7 @@ public static String detect(final InputStream in) throws ArchiveException {
in.mark(signature.length);
int signatureLength = -1;
try {
signatureLength = IOUtils.readFully(in, signature);
signatureLength = IOUtils.read(in, signature);
in.reset();
} catch (final IOException e) {
throw new ArchiveException("Failure reading signature.", (Throwable) e);
Expand Down Expand Up @@ -247,7 +247,7 @@ public static String detect(final InputStream in) throws ArchiveException {
final byte[] dumpsig = new byte[DUMP_SIGNATURE_SIZE];
in.mark(dumpsig.length);
try {
signatureLength = IOUtils.readFully(in, dumpsig);
signatureLength = IOUtils.read(in, dumpsig);
in.reset();
} catch (final IOException e) {
throw new ArchiveException("IOException while reading dump signature", (Throwable) e);
Expand All @@ -259,7 +259,7 @@ public static String detect(final InputStream in) throws ArchiveException {
final byte[] tarHeader = new byte[TAR_HEADER_SIZE];
in.mark(tarHeader.length);
try {
signatureLength = IOUtils.readFully(in, tarHeader);
signatureLength = IOUtils.read(in, tarHeader);
in.reset();
} catch (final IOException e) {
throw new ArchiveException("IOException while reading tar signature", (Throwable) e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.utils.ArchiveUtils;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.compress.utils.ParsingUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;

/**
Expand Down Expand Up @@ -214,7 +214,7 @@ private long asLong(final byte[] byteArray, final int offset, final int len) thr
private void checkTrailer() throws IOException {
// Check and skip the record trailer
final byte[] expectedTrailer = ArchiveUtils.toAsciiBytes(ArArchiveEntry.TRAILER);
final byte[] actualTrailer = IOUtils.readRange(in, expectedTrailer.length);
final byte[] actualTrailer = org.apache.commons.compress.utils.IOUtils.readRange(in, expectedTrailer.length);
if (actualTrailer.length < expectedTrailer.length) {
throw new EOFException(String.format(
"Premature end of ar archive: Invalid or incomplete trailer for entry '%s'.",
Expand Down Expand Up @@ -248,7 +248,7 @@ public void close() throws IOException {
*/
private String getBSDLongName(final String bsdLongName) throws IOException {
final int nameLen = checkEntryNameLength(ParsingUtils.parseIntValue(bsdLongName.substring(BSD_LONGNAME_PREFIX_LEN)));
final byte[] name = IOUtils.readRange(in, nameLen);
final byte[] name = org.apache.commons.compress.utils.IOUtils.readRange(in, nameLen);
final int read = name.length;
count(read);
if (read != nameLen) {
Expand Down Expand Up @@ -389,7 +389,7 @@ public ArArchiveEntry getNextEntry() throws IOException {
* @throws IOException if an I/O error occurs while reading the stream or if the record is malformed.
*/
private byte[] getRecord() throws IOException {
final int read = IOUtils.readFully(in, metaData);
final int read = IOUtils.read(in, metaData);
count(read);
if (read == 0) {
return null;
Expand Down Expand Up @@ -442,7 +442,7 @@ private ArArchiveEntry parseEntry(final byte[] headerBuf) throws IOException {

@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(b, off, len);
IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Expand Down Expand Up @@ -474,7 +474,7 @@ private byte[] readGNUStringTable(final ArArchiveEntry entry) throws IOException
throw new ArchiveException("Invalid GNU string table entry size: " + entry.getLength());
}
final int size = (int) entry.getLength();
final byte[] namebuffer = IOUtils.readRange(in, size);
final byte[] namebuffer = org.apache.commons.compress.utils.IOUtils.readRange(in, size);
final int read = namebuffer.length;
if (read < size) {
throw new EOFException("Premature end of ar archive: Truncated or incomplete GNU string table.");
Expand All @@ -490,7 +490,7 @@ private byte[] readGNUStringTable(final ArArchiveEntry entry) throws IOException
*/
private void skipGlobalSignature() throws IOException {
final byte[] expectedMagic = ArArchiveEntry.HEADER_BYTES;
final byte[] actualMagic = IOUtils.readRange(in, expectedMagic.length);
final byte[] actualMagic = org.apache.commons.compress.utils.IOUtils.readRange(in, expectedMagic.length);
count(actualMagic.length);
if (expectedMagic.length != actualMagic.length) {
throw new EOFException(String.format("Premature end of ar archive: Incomplete global header (expected %d bytes, got %d).", expectedMagic.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.utils.ArchiveUtils;
import org.apache.commons.io.EndianUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.BoundedInputStream;
import org.apache.commons.io.input.ChecksumInputStream;

Expand Down Expand Up @@ -226,7 +227,7 @@ private byte[] findMainHeader() throws IOException {
final int basicHeaderSize = readSwappedUnsignedShort();
// At least two bytes are required for the null-terminated name and comment
if (MIN_FIRST_HEADER_SIZE + 2 <= basicHeaderSize && basicHeaderSize <= MAX_BASIC_HEADER_SIZE) {
basicHeaderBytes = org.apache.commons.io.IOUtils.toByteArray(in, basicHeaderSize);
basicHeaderBytes = IOUtils.toByteArray(in, basicHeaderSize);
count(basicHeaderSize);
if (checkCRC32(basicHeaderBytes)) {
return basicHeaderBytes;
Expand Down Expand Up @@ -262,7 +263,7 @@ public ArjArchiveEntry getNextEntry() throws IOException {
if (currentInputStream != null) {
// return value ignored as IOUtils.skip ensures the stream is drained completely
final InputStream input = currentInputStream;
org.apache.commons.io.IOUtils.skip(input, Long.MAX_VALUE);
IOUtils.skip(input, Long.MAX_VALUE);
currentInputStream.close();
currentLocalFileHeader = null;
currentInputStream = null;
Expand Down Expand Up @@ -307,7 +308,7 @@ public ArjArchiveEntry getNextEntry() throws IOException {

@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(b, off, len);
IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Expand Down Expand Up @@ -352,7 +353,7 @@ private byte[] readHeader() throws IOException {
if (basicHeaderSize < MIN_FIRST_HEADER_SIZE + 2 || basicHeaderSize > MAX_BASIC_HEADER_SIZE) {
throw new ArchiveException("Corrupted ARJ archive: Invalid ARJ header size %,d", basicHeaderSize);
}
final byte[] basicHeaderBytes = org.apache.commons.io.IOUtils.toByteArray(in, basicHeaderSize);
final byte[] basicHeaderBytes = IOUtils.toByteArray(in, basicHeaderSize);
count(basicHeaderSize);
if (!checkCRC32(basicHeaderBytes)) {
throw new ArchiveException("Corrupted ARJ archive: Invalid ARJ header CRC32 checksum");
Expand Down Expand Up @@ -402,7 +403,7 @@ private LocalFileHeader readLocalFileHeader() throws IOException {
final ArrayList<byte[]> extendedHeaders = new ArrayList<>();
int extendedHeaderSize;
while ((extendedHeaderSize = readSwappedUnsignedShort()) > 0) {
final byte[] extendedHeaderBytes = org.apache.commons.io.IOUtils.toByteArray(in, extendedHeaderSize);
final byte[] extendedHeaderBytes = IOUtils.toByteArray(in, extendedHeaderSize);
count(extendedHeaderSize);
if (!checkCRC32(extendedHeaderBytes)) {
throw new ArchiveException("Corrupted ARJ archive: Extended header CRC32 verification failure");
Expand Down Expand Up @@ -448,7 +449,7 @@ private MainHeader readMainHeader(final boolean selfExtracting) throws IOExcepti
}
final int extendedHeaderSize = readSwappedUnsignedShort();
if (extendedHeaderSize > 0) {
header.extendedHeaderBytes = org.apache.commons.io.IOUtils.toByteArray(in, extendedHeaderSize);
header.extendedHeaderBytes = IOUtils.toByteArray(in, extendedHeaderSize);
count(extendedHeaderSize);
if (!checkCRC32(header.extendedHeaderBytes)) {
throw new ArchiveException("Corrupted ARJ archive: Extended header CRC32 verification failure");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
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.IOUtils;
import org.apache.commons.compress.utils.ParsingUtils;
import org.apache.commons.io.IOUtils;

/**
* CpioArchiveInputStream is a stream for reading cpio streams. All formats of cpio are supported (old ASCII, old binary, new portable format and the new
Expand Down Expand Up @@ -386,7 +386,7 @@ public CpioArchiveEntry getNextEntry() throws IOException {
*/
@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(b, off, len);
IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Expand Down Expand Up @@ -443,7 +443,7 @@ private String readEntryName(int lengthWithNull) throws IOException {
}

private int readFully(final byte[] b, final int off, final int len) throws IOException {
final int count = IOUtils.readFully(in, b, off, len);
final int count = IOUtils.read(in, b, off, len);
count(count);
if (count < len) {
throw new EOFException();
Expand Down Expand Up @@ -558,7 +558,7 @@ private CpioArchiveEntry readOldBinaryEntry(final boolean swapHalfWord) throws I
}

private byte[] readRange(final int len) throws IOException {
final byte[] b = IOUtils.readRange(in, len);
final byte[] b = org.apache.commons.compress.utils.IOUtils.readRange(in, len);
count(b.length);
if (b.length < len) {
throw new EOFException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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.IOUtils;
import org.apache.commons.io.IOUtils;

/**
* The DumpArchiveInputStream reads a Unix dump archive as an InputStream. Methods are provided to position at each successive entry in the archive, and the
Expand Down Expand Up @@ -400,7 +400,7 @@ public DumpArchiveSummary getSummary() {
*/
@Override
public int read(final byte[] buf, int off, int len) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(buf, off, len);
IOUtils.checkFromIndexSize(buf, off, len);
if (len == 0) {
return 0;
}
Expand Down Expand Up @@ -527,7 +527,7 @@ private void readDirectoryEntry(DumpArchiveEntry entry) throws IOException {
final int datalen = DumpArchiveConstants.TP_SIZE * entry.getHeaderCount();

if (blockBuffer.length < datalen) {
blockBuffer = IOUtils.readRange(raw, datalen);
blockBuffer = org.apache.commons.compress.utils.IOUtils.readRange(raw, datalen);
if (blockBuffer.length != datalen) {
throw new EOFException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.zip.Inflater;

import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.io.IOUtils;

/**
* Filter stream that mimics a physical tape drive capable of compressing the data stream.
Expand Down Expand Up @@ -130,7 +130,7 @@ public int read() throws IOException {
*/
@Override
public int read(final byte[] b, int off, final int len) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(b, off, len);
IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Expand Down Expand Up @@ -245,14 +245,14 @@ private void readBlock(final boolean decompress) throws IOException {
* @throws IOException Thrown if an I/O error occurs.
*/
private void readFully(final byte[] b, final int off, final int len) throws IOException {
final int count = IOUtils.readFully(in, b, off, len);
final int count = IOUtils.read(in, b, off, len);
if (count < len) {
throw new ShortFileException();
}
}

private byte[] readRange(final int len) throws IOException {
final byte[] ret = IOUtils.readRange(in, len);
final byte[] ret = org.apache.commons.compress.utils.IOUtils.readRange(in, len);
if (ret.length < len) {
throw new ShortFileException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.compress.utils.IOUtils;

/**
* Provides a high level API for creating archives.
Expand All @@ -61,7 +60,7 @@ private static class ArchiverFileVisitor<O extends ArchiveOutputStream<E>, E ext
private ArchiverFileVisitor(final O target, final Path directory, final LinkOption... linkOptions) {
this.outputStream = target;
this.directory = directory;
this.linkOptions = linkOptions == null ? IOUtils.EMPTY_LINK_OPTIONS : linkOptions.clone();
this.linkOptions = linkOptions == null ? org.apache.commons.compress.utils.IOUtils.EMPTY_LINK_OPTIONS : linkOptions.clone();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveFile;
import org.apache.commons.compress.utils.ArchiveUtils;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.compress.utils.InputStreamStatistics;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.function.IOStream;
import org.apache.commons.io.input.BoundedInputStream;
import org.apache.commons.io.input.ChecksumInputStream;
Expand Down Expand Up @@ -1104,7 +1104,7 @@ private InputStream getCurrentStream() throws IOException {
// streams to get access to an entry. We defer this until really needed
// so that entire blocks can be skipped without wasting time for decompression.
try (InputStream stream = deferredBlockStreams.remove(0)) {
org.apache.commons.io.IOUtils.skip(stream, Long.MAX_VALUE, org.apache.commons.io.IOUtils::byteArray);
IOUtils.skip(stream, Long.MAX_VALUE);
}
compressedBytesReadFromCurrentEntry = 0;
}
Expand Down Expand Up @@ -1297,16 +1297,15 @@ private long[] longArray(final int size) throws MemoryLimitException {
* @throws IOException if an I/O error occurs
*/
private ByteBuffer mapNextHeader(final StartHeader startHeader) throws IOException {
MemoryLimitException.checkKiB(bytesToKiB(startHeader.nextHeaderSize), Math.min(bytesToKiB(org.apache.commons.io.IOUtils.SOFT_MAX_ARRAY_LENGTH),
maxMemoryLimitKiB));
MemoryLimitException.checkKiB(bytesToKiB(startHeader.nextHeaderSize), Math.min(bytesToKiB(IOUtils.SOFT_MAX_ARRAY_LENGTH), maxMemoryLimitKiB));
// startHeader is already within the channel's bounds
if (channel instanceof FileChannel) {
final FileChannel fileChannel = (FileChannel) channel;
return fileChannel.map(FileChannel.MapMode.READ_ONLY, startHeader.position(), startHeader.nextHeaderSize).order(ByteOrder.LITTLE_ENDIAN);
}
channel.position(startHeader.position());
final ByteBuffer buf = ByteBuffer.allocate(startHeader.nextHeaderSize).order(ByteOrder.LITTLE_ENDIAN);
readFully(buf);
readFully(buf, "next header");
return buf;
}

Expand Down Expand Up @@ -1435,7 +1434,7 @@ private ByteBuffer readEncodedHeader(final ByteBuffer header, final Archive arch
// @formatter:on
}
final int unpackSize = toNonNegativeInt("header", folder.getUnpackSize());
final byte[] nextHeader = IOUtils.readRange(inputStreamStack, unpackSize);
final byte[] nextHeader = org.apache.commons.compress.utils.IOUtils.readRange(inputStreamStack, unpackSize);
if (nextHeader.length < unpackSize) {
throw new ArchiveException("Premature end of stream");
}
Expand Down Expand Up @@ -1681,10 +1680,13 @@ Folder readFolder(final ByteBuffer header) throws IOException {
return folder;
}

private void readFully(final ByteBuffer buf) throws IOException {
buf.rewind();
org.apache.commons.io.IOUtils.read(channel, buf);
buf.flip();
private void readFully(final ByteBuffer buf, final String description) throws IOException {
try {
IOUtils.readFully(channel, buf);
buf.flip();
} catch (final EOFException e) {
throw new ArchiveException("Truncated 7z archive: end of file reached while reading %s.", description);
}
}

private void readHeader(final ByteBuffer header, final Archive archive) throws IOException {
Expand Down Expand Up @@ -1713,7 +1715,7 @@ private void readHeader(final ByteBuffer header, final Archive archive) throws I

private Archive readHeaders(final byte[] password) throws IOException {
final ByteBuffer startHeader = ByteBuffer.allocate(SIGNATURE_HEADER_SIZE).order(ByteOrder.LITTLE_ENDIAN);
readFully(startHeader);
readFully(startHeader, "signature header");
final byte[] signature = new byte[SIGNATURE.length];
startHeader.get(signature);
if (!Arrays.equals(signature, SIGNATURE)) {
Expand Down
Loading