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
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,9 @@ private ArArchiveEntry parseEntry(final byte[] headerBuf) throws IOException {
}
}

/*
* (non-Javadoc)
*
* @see InputStream#read(byte[], int, int)
*/
@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,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);
if (len == 0) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,17 @@ public CpioArchiveEntry getNextEntry() throws IOException {
* @param off the start offset of the data
* @param len the maximum number of bytes read
* @return the actual number of bytes read, or -1 if the end of the entry is reached
* @throws NullPointerException if b is null
* @throws IndexOutOfBoundsException if {@code off} or {@code len} are negative, or if {@code off + len} is greater than {@code b.length}.
* @throws IOException if an I/O error has occurred or if a CPIO file error has occurred
*/
@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
checkOpen();
if (off < 0 || len < 0 || off > b.length - len) {
throw new IndexOutOfBoundsException();
}
org.apache.commons.io.IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
checkOpen();
if (entry == null || entryEOF) {
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipEncoding;
import org.apache.commons.compress.archivers.zip.ZipEncodingHelper;
import org.apache.commons.io.IOUtils;

/**
* CpioArchiveOutputStream is a stream for writing CPIO streams. All formats of CPIO are supported (old ASCII, old binary, new portable format and the new
Expand Down Expand Up @@ -313,17 +314,17 @@ public void putArchiveEntry(final CpioArchiveEntry entry) throws IOException {
* @param b the data to be written
* @param off the start offset in the data
* @param len the number of bytes that are written
* @throws NullPointerException if b is null
* @throws IndexOutOfBoundsException if {@code off} or {@code len} are negative, or if {@code off + len} is greater than {@code b.length}.
* @throws IOException if an I/O error has occurred or if a CPIO file error has occurred
*/
@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
checkOpen();
if (off < 0 || len < 0 || off > b.length - len) {
throw new IndexOutOfBoundsException();
}
IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return;
}
checkOpen();
if (this.entry == null) {
throw new ArchiveException("No current CPIO entry");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,18 +390,13 @@ public DumpArchiveSummary getSummary() {
}

/**
* Reads bytes from the current dump archive entry.
* {@inheritDoc}
*
* This method is aware of the boundaries of the current entry in the archive and will deal with them as if they were this stream's start and EOF.
*
* @param buf The buffer into which to place bytes read.
* @param off The offset at which to place bytes read.
* @param len The number of bytes to read.
* @return The number of bytes read, or -1 at EOF.
* @throws IOException on error
* <p>This method is aware of the boundaries of the current entry in the archive and will deal with them as if they were this stream's start and EOF.</p>
*/
@Override
public int read(final byte[] buf, int off, int len) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(buf, off, len);
if (len == 0) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public int read() throws IOException {
* </p>
*
* @param len length to read, must be a multiple of the stream's record size.
* @throws IOException Thrown if an I/O error occurs.
*/
@Override
public int read(final byte[] b, int off, final int len) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

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

final class AES256SHA256Decoder extends AbstractCoder {

Expand Down Expand Up @@ -169,6 +170,7 @@ private void flushBuffer() throws IOException {

@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
IOUtils.checkFromIndexSize(b, off, len);
int gap = len + count > cipherBlockSize ? cipherBlockSize - count : len;
System.arraycopy(b, off, cipherBlockBuffer, count, gap);
count += gap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;

import org.apache.commons.io.IOUtils;

final class BoundedSeekableByteChannelInputStream extends InputStream {
private static final int MAX_BUF_LEN = 8192;
private final ByteBuffer buffer;
Expand Down Expand Up @@ -63,9 +65,18 @@ public int read() throws IOException {
* <p>
* This implementation may return 0 if the underlying {@link SeekableByteChannel} is non-blocking and currently hasn't got any bytes available.
* </p>
*
* @param b the buffer into which the data is read.
* @param off the start offset in array b at which the data is written.
* @param len the maximum number of bytes to read.
* @return the total number of bytes read into the buffer, or -1 if EOF is reached.
* @throws NullPointerException if b is null.
* @throws IndexOutOfBoundsException if {@code off} or {@code len} are negative, or if {@code off + len} is greater than {@code b.length}.
* @throws IOException if an I/O error occurs.
*/
@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.file.attribute.FileTimes;
import org.apache.commons.io.output.CountingOutputStream;

Expand Down Expand Up @@ -87,6 +88,7 @@ public void write(final byte[] b) throws IOException {

@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
IOUtils.checkFromIndexSize(b, off, len);
if (len > BUF_SIZE) {
channel.write(ByteBuffer.wrap(b, off, len));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,14 @@ public boolean markSupported() {
* @param offset The offset at which to place bytes read.
* @param numToRead The number of bytes to read.
* @return The number of bytes read, or -1 at EOF.
* @throws NullPointerException if {@code buf} is null
* @throws IndexOutOfBoundsException if {@code offset} or {@code numToRead} are negative,
* or if {@code offset + numToRead} is greater than {@code buf.length}.
* @throws IOException on error
*/
@Override
public int read(final byte[] buf, final int offset, int numToRead) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(buf, offset, numToRead);
if (numToRead == 0) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.commons.compress.archivers.zip.ZipEncodingHelper;
import org.apache.commons.compress.utils.FixedLengthBlockOutputStream;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.file.attribute.FileTimes;
import org.apache.commons.io.output.CountingOutputStream;
import org.apache.commons.lang3.ArrayFill;
Expand Down Expand Up @@ -627,10 +628,14 @@ private void transferModTime(final TarArchiveEntry from, final TarArchiveEntry t
* @param wBuf The buffer to write to the archive.
* @param wOffset The offset in the buffer from which to get bytes.
* @param numToWrite The number of bytes to write.
* @throws NullPointerException if {@code wBuf} is null
* @throws IndexOutOfBoundsException if {@code wOffset} or {@code numToWrite} are negative,
* or if {@code wOffset + numToWrite} is greater than {@code wBuf.length}.
* @throws IOException on error
*/
@Override
public void write(final byte[] wBuf, final int wOffset, final int numToWrite) throws IOException {
IOUtils.checkFromIndexSize(wBuf, wOffset, numToWrite);
if (!haveUnclosedEntry) {
throw new IllegalStateException("No current tar entry");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
*/
package org.apache.commons.compress.archivers.tar;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

import org.apache.commons.io.IOUtils;

/**
* This is an InputStream that always return 0, this is used when reading the "holes" of a sparse file
Expand All @@ -35,6 +39,16 @@ public int read() {
return 0;
}

@Override
public int read(byte[] b, int off, int len) throws IOException {
IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Arrays.fill(b, off, off + len, (byte) 0);
return len;
}

/**
* Returns the input.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ private void pushback(final byte[] buf, final int offset, final int length) thro

@Override
public int read(final byte[] buffer, final int offset, final int length) throws IOException {
org.apache.commons.io.IOUtils.checkFromIndexSize(buffer, offset, length);
if (length == 0) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.ArrayUtils;

/**
Expand Down Expand Up @@ -1568,10 +1569,14 @@ private int versionNeededToExtractMethod(final int zipMethod) {
* @param b the byte array to write.
* @param offset the start position to write from.
* @param length the number of bytes to write.
* @throws NullPointerException if {@code b} is null
* @throws IndexOutOfBoundsException if {@code offset} or {@code length} are negative,
* or if {@code offset + length} is greater than {@code b.length}.
* @throws IOException on error.
*/
@Override
public void write(final byte[] b, final int offset, final int length) throws IOException {
IOUtils.checkFromIndexSize(b, offset, length);
if (entry == null) {
throw new IllegalStateException("No current entry");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.TreeMap;

import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.file.PathUtils;

/**
Expand Down Expand Up @@ -252,10 +253,14 @@ public void write(final byte[] b) throws IOException {
* @param b data to write
* @param off offset of the start of data in param b
* @param len the length of data to write
* @throws NullPointerException if {@code b} is null
* @throws IndexOutOfBoundsException if {@code off} or {@code len} are negative,
* or if {@code off + len} is greater than {@code b.length}.
* @throws IOException if an I/O error occurs.
*/
@Override
public void write(final byte[] b, final int off, final int len) throws IOException {
IOUtils.checkFromIndexSize(b, off, len);
if (len <= 0) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.commons.compress.compressors.CompressorInputStream;
import org.apache.commons.compress.utils.BitInputStream;
import org.apache.commons.compress.utils.InputStreamStatistics;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.CloseShieldInputStream;

/**
Expand Down Expand Up @@ -712,28 +713,15 @@ public int read() throws IOException {
throw new CompressorException("Stream closed");
}

/*
* (non-Javadoc)
*
* @see InputStream#read(byte[], int, int)
*/
@Override
public int read(final byte[] dest, final int offs, final int len) throws IOException {
if (offs < 0) {
throw new IndexOutOfBoundsException("offs(" + offs + ") < 0.");
}
if (len < 0) {
throw new IndexOutOfBoundsException("len(" + len + ") < 0.");
}
if (offs + len > dest.length) {
throw new IndexOutOfBoundsException("offs(" + offs + ") + len(" + len + ") > dest.length(" + dest.length + ").");
IOUtils.checkFromIndexSize(dest, offs, len);
if (len == 0) {
return 0;
}
if (this.bin == null) {
throw new CompressorException("Stream closed");
}
if (len == 0) {
return 0;
}

final int hi = offs + len;
int destOffs = offs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Arrays;

import org.apache.commons.compress.compressors.CompressorOutputStream;
import org.apache.commons.io.IOUtils;

/**
* An output stream that compresses into the BZip2 format into another stream.
Expand Down Expand Up @@ -1149,15 +1150,7 @@ private void sendMTFValues7() throws IOException {

@Override
public void write(final byte[] buf, int offs, final int len) throws IOException {
if (offs < 0) {
throw new IndexOutOfBoundsException("offs(" + offs + ") < 0.");
}
if (len < 0) {
throw new IndexOutOfBoundsException("len(" + len + ") < 0.");
}
if (offs + len > buf.length) {
throw new IndexOutOfBoundsException("offs(" + offs + ") + len(" + len + ") > buf.length(" + buf.length + ").");
}
IOUtils.checkFromIndexSize(buf, offs, len);
checkOpen();
for (final int hi = offs + len; offs < hi;) {
write0(buf[offs++]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,8 @@ public int read() throws IOException {
return ret;
}

/** {@inheritDoc} */
@Override
public int read(final byte[] buf, final int off, final int len) throws IOException {
if (len == 0) {
return 0;
}
final int ret = in.read(buf, off, len);
count(ret);
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ public int read() throws IOException {
}
}

/**
* @throws java.io.EOFException if the underlying stream is exhausted before the end of deflated data was reached.
*/
@Override
public int read(final byte[] b, final int off, final int len) throws IOException {
IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ public int read() throws IOException {
*/
@Override
public int read(final byte[] b, int off, int len) throws IOException {
IOUtils.checkFromIndexSize(b, off, len);
if (len == 0) {
return 0;
}
Expand Down
Loading
Loading