diff options
author | Elliott Hughes <enh@google.com> | 2013-06-24 15:17:50 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-06-24 15:17:50 -0700 |
commit | 325ff8c68ed5e530e9e1d487b9e2e6d8f8e2bd37 (patch) | |
tree | d280f9844356cd3654ac8a4bee24308a90dd68da /luni | |
parent | cfc2202995730d853a0b2f77e4fa956158e64c3f (diff) | |
download | libcore-325ff8c68ed5e530e9e1d487b9e2e6d8f8e2bd37.zip libcore-325ff8c68ed5e530e9e1d487b9e2e6d8f8e2bd37.tar.gz libcore-325ff8c68ed5e530e9e1d487b9e2e6d8f8e2bd37.tar.bz2 |
Clean up the #read javadoc.
By being more consistent in parameter naming, we can inherit more javadoc.
Also fix a couple of javadoc warnings in KnownFailure and DataInputStream.
Change-Id: I778f40469404fb50c51cdb1068970974f923180c
Diffstat (limited to 'luni')
34 files changed, 207 insertions, 515 deletions
diff --git a/luni/src/main/java/java/io/BufferedInputStream.java b/luni/src/main/java/java/io/BufferedInputStream.java index d45595b..5a810e7 100644 --- a/luni/src/main/java/java/io/BufferedInputStream.java +++ b/luni/src/main/java/java/io/BufferedInputStream.java @@ -242,35 +242,14 @@ public class BufferedInputStream extends FilterInputStream { return -1; } - /** - * Reads at most {@code byteCount} bytes from this stream and stores them in - * byte array {@code buffer} starting at offset {@code offset}. Returns the - * number of bytes actually read or -1 if no bytes were read and the end of - * the stream was encountered. If all the buffered bytes have been used, a - * mark has not been set and the requested number of bytes is larger than - * the receiver's buffer size, this implementation bypasses the buffer and - * simply places the results directly into {@code buffer}. - * - * @param buffer - * the byte array in which to store the bytes read. - * @return the number of bytes actually read or -1 if end of stream. - * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code byteCount < 0}, or if - * {@code offset + byteCount} is greater than the size of - * {@code buffer}. - * @throws IOException - * if the stream is already closed or another IOException - * occurs. - */ - @Override - public synchronized int read(byte[] buffer, int offset, int byteCount) throws IOException { + @Override public synchronized int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { // Use local ref since buf may be invalidated by an unsynchronized // close() byte[] localBuf = buf; if (localBuf == null) { throw streamClosed(); } - Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); if (byteCount == 0) { return 0; } @@ -283,12 +262,12 @@ public class BufferedInputStream extends FilterInputStream { if (pos < count) { /* There are bytes available in the buffer. */ int copylength = count - pos >= byteCount ? byteCount : count - pos; - System.arraycopy(localBuf, pos, buffer, offset, copylength); + System.arraycopy(localBuf, pos, buffer, byteOffset, copylength); pos += copylength; if (copylength == byteCount || localIn.available() == 0) { return copylength; } - offset += copylength; + byteOffset += copylength; required = byteCount - copylength; } else { required = byteCount; @@ -301,7 +280,7 @@ public class BufferedInputStream extends FilterInputStream { * buffer, simply read the bytes directly bypassing the buffer. */ if (markpos == -1 && required >= localBuf.length) { - read = localIn.read(buffer, offset, required); + read = localIn.read(buffer, byteOffset, required); if (read == -1) { return required == byteCount ? -1 : byteCount - required; } @@ -318,7 +297,7 @@ public class BufferedInputStream extends FilterInputStream { } read = count - pos >= required ? required : count - pos; - System.arraycopy(localBuf, pos, buffer, offset, read); + System.arraycopy(localBuf, pos, buffer, byteOffset, read); pos += read; } required -= read; @@ -328,7 +307,7 @@ public class BufferedInputStream extends FilterInputStream { if (localIn.available() == 0) { return byteCount - required; } - offset += read; + byteOffset += read; } } diff --git a/luni/src/main/java/java/io/BufferedReader.java b/luni/src/main/java/java/io/BufferedReader.java index f8a36d3..c72e798 100644 --- a/luni/src/main/java/java/io/BufferedReader.java +++ b/luni/src/main/java/java/io/BufferedReader.java @@ -267,7 +267,7 @@ public class BufferedReader extends Reader { } /** - * Reads at most {@code length} characters from this reader and stores them + * Reads up to {@code length} characters from this reader and stores them * at {@code offset} in the character array {@code buffer}. Returns the * number of characters actually read or -1 if the end of the source reader * has been reached. If all the buffered characters have been used, a mark @@ -275,20 +275,8 @@ public class BufferedReader extends Reader { * this readers buffer size, BufferedReader bypasses the buffer and simply * places the results directly into {@code buffer}. * - * @param buffer - * the character array to store the characters read. - * @param offset - * the initial position in {@code buffer} to store the chars read - * from this reader. - * @param length - * the maximum number of characters to read, must be - * non-negative. - * @return number of characters read or -1 if the end of the source reader - * has been reached. * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code length < 0}, or if - * {@code offset + length} is greater than the size of - * {@code buffer}. + * if {@code offset < 0 || length < 0 || offset + length > buffer.length}. * @throws IOException * if this reader is closed or some other I/O error occurs. */ diff --git a/luni/src/main/java/java/io/ByteArrayInputStream.java b/luni/src/main/java/java/io/ByteArrayInputStream.java index 0a8c453..7a6cc50 100644 --- a/luni/src/main/java/java/io/ByteArrayInputStream.java +++ b/luni/src/main/java/java/io/ByteArrayInputStream.java @@ -141,41 +141,19 @@ public class ByteArrayInputStream extends InputStream { return pos < count ? buf[pos++] & 0xFF : -1; } - /** - * Reads at most {@code len} bytes from this stream and stores - * them in byte array {@code b} starting at {@code offset}. This - * implementation reads bytes from the source byte array. - * - * @param buffer - * the byte array in which to store the bytes read. - * @param offset - * the initial position in {@code b} to store the bytes read from - * this stream. - * @param length - * the maximum number of bytes to store in {@code b}. - * @return the number of bytes actually read or -1 if no bytes were read and - * the end of the stream was encountered. - * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code length < 0}, or if - * {@code offset + length} is greater than the size of - * {@code b}. - * @throws NullPointerException - * if {@code b} is {@code null}. - */ - @Override - public synchronized int read(byte[] buffer, int offset, int length) { - Arrays.checkOffsetAndCount(buffer.length, offset, length); + @Override public synchronized int read(byte[] buffer, int byteOffset, int byteCount) { + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); // Are there any bytes available? if (this.pos >= this.count) { return -1; } - if (length == 0) { + if (byteCount == 0) { return 0; } - int copylen = this.count - pos < length ? this.count - pos : length; - System.arraycopy(this.buf, pos, buffer, offset, copylen); + int copylen = this.count - pos < byteCount ? this.count - pos : byteCount; + System.arraycopy(this.buf, pos, buffer, byteOffset, copylen); pos += copylen; return copylen; } diff --git a/luni/src/main/java/java/io/CharArrayReader.java b/luni/src/main/java/java/io/CharArrayReader.java index 366efcf..c5baa32 100644 --- a/luni/src/main/java/java/io/CharArrayReader.java +++ b/luni/src/main/java/java/io/CharArrayReader.java @@ -184,34 +184,23 @@ public class CharArrayReader extends Reader { } /** - * Reads at most {@code count} characters from this CharArrayReader and - * stores them at {@code offset} in the character array {@code buf}. + * Reads up to {@code count} characters from this CharArrayReader and + * stores them at {@code offset} in the character array {@code buffer}. * Returns the number of characters actually read or -1 if the end of reader * was encountered. * - * @param buffer - * the character array to store the characters read. - * @param offset - * the initial position in {@code buffer} to store the characters - * read from this reader. - * @param len - * the maximum number of characters to read. - * @return number of characters read or -1 if the end of the reader has been - * reached. * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code len < 0}, or if - * {@code offset + len} is bigger than the size of - * {@code buffer}. + * if {@code offset < 0 || count < 0 || offset + count > buffer.length}. * @throws IOException * if this reader is closed. */ @Override - public int read(char[] buffer, int offset, int len) throws IOException { - Arrays.checkOffsetAndCount(buffer.length, offset, len); + public int read(char[] buffer, int offset, int count) throws IOException { + Arrays.checkOffsetAndCount(buffer.length, offset, count); synchronized (lock) { checkNotClosed(); if (pos < this.count) { - int bytesRead = pos + len > this.count ? this.count - pos : len; + int bytesRead = pos + count > this.count ? this.count - pos : count; System.arraycopy(this.buf, pos, buffer, offset, bytesRead); pos += bytesRead; return bytesRead; diff --git a/luni/src/main/java/java/io/DataInputStream.java b/luni/src/main/java/java/io/DataInputStream.java index 7826852..3b1a6d0 100644 --- a/luni/src/main/java/java/io/DataInputStream.java +++ b/luni/src/main/java/java/io/DataInputStream.java @@ -59,29 +59,8 @@ public class DataInputStream extends FilterInputStream implements DataInput { return super.read(buffer); } - /** - * Reads at most {@code length} bytes from this stream and stores them in - * the byte array {@code buffer} starting at {@code offset}. Returns the - * number of bytes that have been read or -1 if no bytes have been read and - * the end of the stream has been reached. - * - * @param buffer - * the byte array in which to store the bytes read. - * @param offset - * the initial position in {@code buffer} to store the bytes - * read from this stream. - * @param length - * the maximum number of bytes to store in {@code buffer}. - * @return the number of bytes that have been read or -1 if the end of the - * stream has been reached. - * @throws IOException - * if a problem occurs while reading from this stream. - * @see DataOutput#write(byte[]) - * @see DataOutput#write(byte[], int, int) - */ - @Override - public final int read(byte[] buffer, int offset, int length) throws IOException { - return in.read(buffer, offset, length); + @Override public final int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + return in.read(buffer, byteOffset, byteCount); } public final boolean readBoolean() throws IOException { @@ -125,6 +104,10 @@ public class DataInputStream extends FilterInputStream implements DataInput { return Memory.peekInt(scratch, 0, ByteOrder.BIG_ENDIAN); } + /** + * @deprecated This method cannot be trusted to convert bytes to characters correctly. + * Wrap this stream with a {@link BufferedReader} instead. + */ @Deprecated public final String readLine() throws IOException { StringBuilder line = new StringBuilder(80); // Typical line length diff --git a/luni/src/main/java/java/io/FilterInputStream.java b/luni/src/main/java/java/io/FilterInputStream.java index 2bf13e2..4092cd4 100644 --- a/luni/src/main/java/java/io/FilterInputStream.java +++ b/luni/src/main/java/java/io/FilterInputStream.java @@ -114,28 +114,8 @@ public class FilterInputStream extends InputStream { return in.read(); } - /** - * Reads at most {@code count} bytes from this stream and stores them in the - * byte array {@code buffer} starting at {@code offset}. Returns the number - * of bytes actually read or -1 if no bytes have been read and the end of - * this stream has been reached. This implementation reads bytes from the - * filtered stream. - * - * @param buffer - * the byte array in which to store the bytes read. - * @param offset - * the initial position in {@code buffer} to store the bytes - * read from this stream. - * @param count - * the maximum number of bytes to store in {@code buffer}. - * @return the number of bytes actually read or -1 if the end of the - * filtered stream has been reached while reading. - * @throws IOException - * if this stream is closed or another I/O error occurs. - */ - @Override - public int read(byte[] buffer, int offset, int count) throws IOException { - return in.read(buffer, offset, count); + @Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + return in.read(buffer, byteOffset, byteCount); } /** diff --git a/luni/src/main/java/java/io/FilterReader.java b/luni/src/main/java/java/io/FilterReader.java index 43beb8c..e93fe9c 100644 --- a/luni/src/main/java/java/io/FilterReader.java +++ b/luni/src/main/java/java/io/FilterReader.java @@ -116,20 +116,11 @@ public abstract class FilterReader extends Reader { } /** - * Reads at most {@code count} characters from the filtered reader and stores them + * Reads up to {@code count} characters from the filtered reader and stores them * in the byte array {@code buffer} starting at {@code offset}. Returns the * number of characters actually read or -1 if no characters were read and * the end of the filtered reader was encountered. * - * @param buffer - * the char array in which to store the characters read. - * @param offset - * the initial position in {@code buffer} to store the characters - * read from this reader. - * @param count - * the maximum number of characters to store in {@code buffer}. - * @return the number of characters actually read or -1 if the end of the - * filtered reader has been reached while reading. * @throws IOException * if an error occurs while reading from this reader. */ diff --git a/luni/src/main/java/java/io/InputStream.java b/luni/src/main/java/java/io/InputStream.java index 561e057..973382e 100644 --- a/luni/src/main/java/java/io/InputStream.java +++ b/luni/src/main/java/java/io/InputStream.java @@ -150,7 +150,6 @@ public abstract class InputStream extends Object implements Closeable { * reached. Blocks until one byte has been read, the end of the source * stream is detected or an exception is thrown. * - * @return the byte read or -1 if the end of stream has been reached. * @throws IOException * if the stream is closed or another IOException occurs. */ @@ -164,28 +163,19 @@ public abstract class InputStream extends Object implements Closeable { } /** - * Reads at most {@code length} bytes from this stream and stores them in - * the byte array {@code b} starting at {@code offset}. - * - * @param buffer - * the byte array in which to store the bytes read. - * @param offset - * the initial position in {@code buffer} to store the bytes read - * from this stream. - * @param length - * the maximum number of bytes to store in {@code b}. - * @return the number of bytes actually read or -1 if the end of the stream - * has been reached. + * Reads up to {@code byteCount} bytes from this stream and stores them in + * the byte array {@code buffer} starting at {@code byteOffset}. + * Returns the number of bytes actually read or -1 if the end of the stream + * has been reached. + * * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code length < 0}, or if - * {@code offset + length} is greater than the length of - * {@code b}. + * if {@code byteOffset < 0 || byteCount < 0 || byteOffset + byteCount > buffer.length}. * @throws IOException * if the stream is closed or another IOException occurs. */ - public int read(byte[] buffer, int offset, int length) throws IOException { - Arrays.checkOffsetAndCount(buffer.length, offset, length); - for (int i = 0; i < length; i++) { + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); + for (int i = 0; i < byteCount; ++i) { int c; try { if ((c = read()) == -1) { @@ -197,9 +187,9 @@ public abstract class InputStream extends Object implements Closeable { } throw e; } - buffer[offset + i] = (byte) c; + buffer[byteOffset + i] = (byte) c; } - return length; + return byteCount; } /** diff --git a/luni/src/main/java/java/io/InputStreamReader.java b/luni/src/main/java/java/io/InputStreamReader.java index d3650dc..f474ab9 100644 --- a/luni/src/main/java/java/io/InputStreamReader.java +++ b/luni/src/main/java/java/io/InputStreamReader.java @@ -185,42 +185,31 @@ public class InputStreamReader extends Reader { } /** - * Reads at most {@code length} characters from this reader and stores them - * at position {@code offset} in the character array {@code buf}. Returns + * Reads up to {@code count} characters from this reader and stores them + * at position {@code offset} in the character array {@code buffer}. Returns * the number of characters actually read or -1 if the end of the reader has * been reached. The bytes are either obtained from converting bytes in this * reader's buffer or by first filling the buffer from the source * InputStream and then reading from the buffer. * - * @param buffer - * the array to store the characters read. - * @param offset - * the initial position in {@code buf} to store the characters - * read from this reader. - * @param length - * the maximum number of characters to read. - * @return the number of characters read or -1 if the end of the reader has - * been reached. * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code length < 0}, or if - * {@code offset + length} is greater than the length of - * {@code buf}. + * if {@code offset < 0 || count < 0 || offset + count > buffer.length}. * @throws IOException * if this reader is closed or some other I/O error occurs. */ @Override - public int read(char[] buffer, int offset, int length) throws IOException { + public int read(char[] buffer, int offset, int count) throws IOException { synchronized (lock) { if (!isOpen()) { throw new IOException("InputStreamReader is closed"); } - Arrays.checkOffsetAndCount(buffer.length, offset, length); - if (length == 0) { + Arrays.checkOffsetAndCount(buffer.length, offset, count); + if (count == 0) { return 0; } - CharBuffer out = CharBuffer.wrap(buffer, offset, length); + CharBuffer out = CharBuffer.wrap(buffer, offset, count); CoderResult result = CoderResult.UNDERFLOW; // bytes.remaining() indicates number of bytes in buffer diff --git a/luni/src/main/java/java/io/LineNumberInputStream.java b/luni/src/main/java/java/io/LineNumberInputStream.java index 69d870d..de6584e 100644 --- a/luni/src/main/java/java/io/LineNumberInputStream.java +++ b/luni/src/main/java/java/io/LineNumberInputStream.java @@ -138,38 +138,27 @@ public class LineNumberInputStream extends FilterInputStream { } /** - * Reads at most {@code length} bytes from the filtered stream and stores - * them in the byte array {@code buffer} starting at {@code offset}. + * Reads up to {@code byteCount} bytes from the filtered stream and stores + * them in the byte array {@code buffer} starting at {@code byteOffset}. * Returns the number of bytes actually read or -1 if no bytes have been * read and the end of this stream has been reached. - * <p> - * The line number count is incremented if a line terminator is encountered. + * + * <p>The line number count is incremented if a line terminator is encountered. * Recognized line terminator sequences are {@code '\r'}, {@code '\n'} and * {@code "\r\n"}. Line terminator sequences are always translated into * {@code '\n'}. * - * @param buffer - * the array in which to store the bytes read. - * @param offset - * the initial position in {@code buffer} to store the bytes read - * from this stream. - * @param length - * the maximum number of bytes to store in {@code buffer}. - * @return the number of bytes actually read or -1 if the end of the - * filtered stream has been reached while reading. * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code length < 0}, or if - * {@code offset + length} is greater than the length of - * {@code buffer}. + * if {@code byteOffset < 0 || byteCount < 0 || byteOffset + byteCount > buffer.length}. * @throws IOException * if this stream is closed or another IOException occurs. * @throws NullPointerException - * if {@code buffer} is {@code null}. + * if {@code buffer == null}. */ @Override - public int read(byte[] buffer, int offset, int length) throws IOException { - Arrays.checkOffsetAndCount(buffer.length, offset, length); - for (int i = 0; i < length; i++) { + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); + for (int i = 0; i < byteCount; ++i) { int currentChar; try { currentChar = read(); @@ -182,9 +171,9 @@ public class LineNumberInputStream extends FilterInputStream { if (currentChar == -1) { return i == 0 ? -1 : i; } - buffer[offset + i] = (byte) currentChar; + buffer[byteOffset + i] = (byte) currentChar; } - return length; + return byteCount; } /** diff --git a/luni/src/main/java/java/io/LineNumberReader.java b/luni/src/main/java/java/io/LineNumberReader.java index 03d02a2..5295e77 100644 --- a/luni/src/main/java/java/io/LineNumberReader.java +++ b/luni/src/main/java/java/io/LineNumberReader.java @@ -132,24 +132,15 @@ public class LineNumberReader extends BufferedReader { } /** - * Reads at most {@code count} characters from the source reader and stores + * Reads up to {@code count} characters from the source reader and stores * them in the character array {@code buffer} starting at {@code offset}. * Returns the number of characters actually read or -1 if no characters * have been read and the end of this reader has been reached. - * <p> - * The line number count is incremented if a line terminator is encountered. + * + * <p>The line number count is incremented if a line terminator is encountered. * Recognized line terminator sequences are {@code '\r'}, {@code '\n'} and * {@code "\r\n"}. * - * @param buffer - * the array in which to store the characters read. - * @param offset - * the initial position in {@code buffer} to store the characters - * read from this reader. - * @param count - * the maximum number of characters to store in {@code buffer}. - * @return the number of characters actually read or -1 if the end of the - * source reader has been reached while reading. * @throws IOException * if this reader is closed or another IOException occurs. */ diff --git a/luni/src/main/java/java/io/ObjectInput.java b/luni/src/main/java/java/io/ObjectInput.java index e892071..0c137c0 100644 --- a/luni/src/main/java/java/io/ObjectInput.java +++ b/luni/src/main/java/java/io/ObjectInput.java @@ -56,35 +56,24 @@ public interface ObjectInput extends DataInput, AutoCloseable { /** * Reads bytes from this stream into the byte array {@code buffer}. Blocks - * while waiting for input. + * while waiting for input. Returns the number of bytes read, + * or -1 if the end of this stream has been reached. * - * @param buffer - * the array in which to store the bytes read. - * @return the number of bytes read or -1 if the end of this stream has been - * reached. * @throws IOException * if this stream is closed or another I/O error occurs. */ public int read(byte[] buffer) throws IOException; /** - * Reads at most {@code count} bytes from this stream and stores them in - * byte array {@code buffer} starting at offset {@code count}. Blocks while - * waiting for input. + * Reads up to {@code byteCount} bytes from this stream and stores them in + * byte array {@code buffer} starting at offset {@code byteOffset}. Blocks while + * waiting for input. Returns the number of bytes read or -1 if the end of this stream has been + * reached. * - * @param buffer - * the array in which to store the bytes read. - * @param offset - * the initial position in {@code buffer} to store the bytes read - * from this stream. - * @param count - * the maximum number of bytes to store in {@code buffer}. - * @return the number of bytes read or -1 if the end of this stream has been - * reached. * @throws IOException * if this stream is closed or another I/O error occurs. */ - public int read(byte[] buffer, int offset, int count) throws IOException; + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException; /** * Reads the next object from this stream. diff --git a/luni/src/main/java/java/io/ObjectInputStream.java b/luni/src/main/java/java/io/ObjectInputStream.java index 8b684f0..35f6fc1 100644 --- a/luni/src/main/java/java/io/ObjectInputStream.java +++ b/luni/src/main/java/java/io/ObjectInputStream.java @@ -531,38 +531,13 @@ public class ObjectInputStream extends InputStream implements ObjectInput, Objec return primitiveData.read(); } - /** - * Reads at most {@code length} bytes from the source stream and stores them - * in byte array {@code buffer} starting at offset {@code count}. Blocks - * until {@code count} bytes have been read, the end of the source stream is - * detected or an exception is thrown. - * - * @param buffer - * the array in which to store the bytes read. - * @param offset - * the initial position in {@code buffer} to store the bytes - * read from the source stream. - * @param length - * the maximum number of bytes to store in {@code buffer}. - * @return the number of bytes read or -1 if the end of the source input - * stream has been reached. - * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code length < 0}, or if - * {@code offset + length} is greater than the length of - * {@code buffer}. - * @throws IOException - * if an error occurs while reading from this stream. - * @throws NullPointerException - * if {@code buffer} is {@code null}. - */ - @Override - public int read(byte[] buffer, int offset, int length) throws IOException { - Arrays.checkOffsetAndCount(buffer.length, offset, length); - if (length == 0) { + @Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); + if (byteCount == 0) { return 0; } checkReadPrimitiveTypes(); - return primitiveData.read(buffer, offset, length); + return primitiveData.read(buffer, byteOffset, byteCount); } /** diff --git a/luni/src/main/java/java/io/PipedInputStream.java b/luni/src/main/java/java/io/PipedInputStream.java index 739fb98..2c27695 100644 --- a/luni/src/main/java/java/io/PipedInputStream.java +++ b/luni/src/main/java/java/io/PipedInputStream.java @@ -256,20 +256,20 @@ public class PipedInputStream extends InputStream { } /** - * Reads at most {@code byteCount} bytes from this stream and stores them in the - * byte array {@code bytes} starting at {@code offset}. Blocks until at + * Reads up to {@code byteCount} bytes from this stream and stores them in the + * byte array {@code bytes} starting at {@code byteOffset}. Blocks until at * least one byte has been read, the end of the stream is detected or an * exception is thrown. - * <p> - * Separate threads should be used to read from a {@code PipedInputStream} + * + * <p>Separate threads should be used to read from a {@code PipedInputStream} * and to write to the connected {@link PipedOutputStream}. If the same * thread is used, a deadlock may occur. * - * @return the number of bytes actually read or -1 if the end of the stream - * has been reached. + * <p>Returns the number of bytes actually read or -1 if the end of the stream + * has been reached. + * * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code byteCount < 0}, or if {@code - * offset + byteCount} is greater than the size of {@code bytes}. + * if {@code byteOffset < 0 || byteCount < 0 || byteOffset + byteCount > bytes.length}. * @throws InterruptedIOException * if the thread reading from this stream is interrupted. * @throws IOException @@ -279,9 +279,8 @@ public class PipedInputStream extends InputStream { * @throws NullPointerException * if {@code bytes} is {@code null}. */ - @Override - public synchronized int read(byte[] bytes, int offset, int byteCount) throws IOException { - Arrays.checkOffsetAndCount(bytes.length, offset, byteCount); + @Override public synchronized int read(byte[] bytes, int byteOffset, int byteCount) throws IOException { + Arrays.checkOffsetAndCount(bytes.length, byteOffset, byteCount); if (byteCount == 0) { return 0; } @@ -324,7 +323,7 @@ public class PipedInputStream extends InputStream { if (out >= in) { int leftInBuffer = buffer.length - out; int length = leftInBuffer < byteCount ? leftInBuffer : byteCount; - System.arraycopy(buffer, out, bytes, offset, length); + System.arraycopy(buffer, out, bytes, byteOffset, length); out += length; if (out == buffer.length) { out = 0; @@ -342,7 +341,7 @@ public class PipedInputStream extends InputStream { int leftInBuffer = in - out; int leftToCopy = byteCount - totalCopied; int length = leftToCopy < leftInBuffer ? leftToCopy : leftInBuffer; - System.arraycopy(buffer, out, bytes, offset + totalCopied, length); + System.arraycopy(buffer, out, bytes, byteOffset + totalCopied, length); out += length; if (out == in) { // empty buffer diff --git a/luni/src/main/java/java/io/PipedReader.java b/luni/src/main/java/java/io/PipedReader.java index 8450a34..908505d 100644 --- a/luni/src/main/java/java/io/PipedReader.java +++ b/luni/src/main/java/java/io/PipedReader.java @@ -199,28 +199,21 @@ public class PipedReader extends Reader { } /** - * Reads at most {@code count} characters from this reader and stores them + * Reads up to {@code count} characters from this reader and stores them * in the character array {@code buffer} starting at {@code offset}. If * there is no data in the pipe, this method blocks until at least one byte * has been read, the end of the reader is detected or an exception is * thrown. - * <p> - * Separate threads should be used to read from a {@code PipedReader} and to + * + * <p>Separate threads should be used to read from a {@code PipedReader} and to * write to the connected {@link PipedWriter}. If the same thread is used, a * deadlock may occur. * - * @param buffer - * the character array in which to store the characters read. - * @param offset - * the initial position in {@code bytes} to store the characters - * read from this reader. - * @param count - * the maximum number of characters to store in {@code buffer}. - * @return the number of characters read or -1 if the end of the reader has - * been reached. + * <p>Returns the number of characters read or -1 if the end of the reader has + * been reached. + * * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code count < 0}, or if {@code - * offset + count} is greater than the size of {@code buffer}. + * if {@code offset < 0 || count < 0 || offset + count > buffer.length}. * @throws InterruptedIOException * if the thread reading from this reader is interrupted. * @throws IOException @@ -228,8 +221,7 @@ public class PipedReader extends Reader { * the thread writing to the connected writer is no longer * alive. */ - @Override - public synchronized int read(char[] buffer, int offset, int count) throws IOException { + @Override public synchronized int read(char[] buffer, int offset, int count) throws IOException { if (!isConnected) { throw new IOException("Pipe not connected"); } diff --git a/luni/src/main/java/java/io/PushbackInputStream.java b/luni/src/main/java/java/io/PushbackInputStream.java index fa0df85..d7bebb1 100644 --- a/luni/src/main/java/java/io/PushbackInputStream.java +++ b/luni/src/main/java/java/io/PushbackInputStream.java @@ -147,42 +147,31 @@ public class PushbackInputStream extends FilterInputStream { } /** - * Reads at most {@code length} bytes from this stream and stores them in - * the byte array {@code buffer} starting at {@code offset}. Bytes are read + * Reads up to {@code byteCount} bytes from this stream and stores them in + * the byte array {@code buffer} starting at {@code byteOffset}. Bytes are read * from the pushback buffer first, then from the source stream if more bytes - * are required. Blocks until {@code count} bytes have been read, the end of - * the source stream is detected or an exception is thrown. + * are required. Blocks until {@code byteCount} bytes have been read, the end of + * the source stream is detected or an exception is thrown. Returns the number of bytes read, + * or -1 if the end of the source stream has been reached. * - * @param buffer - * the array in which to store the bytes read from this stream. - * @param offset - * the initial position in {@code buffer} to store the bytes read - * from this stream. - * @param length - * the maximum number of bytes to store in {@code buffer}. - * @return the number of bytes read or -1 if the end of the source stream - * has been reached. * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code length < 0}, or if - * {@code offset + length} is greater than the length of - * {@code buffer}. + * if {@code byteOffset < 0 || byteCount < 0 || byteOffset + byteCount > buffer.length}. * @throws IOException * if this stream is closed or another I/O error occurs while * reading from this stream. * @throws NullPointerException - * if {@code buffer} is {@code null}. + * if {@code buffer == null}. */ @Override - public int read(byte[] buffer, int offset, int length) throws IOException { + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { if (buf == null) { throw streamClosed(); } - Arrays.checkOffsetAndCount(buffer.length, offset, length); - int copiedBytes = 0, copyLength = 0, newOffset = offset; + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); + int copiedBytes = 0, copyLength = 0, newOffset = byteOffset; // Are there pushback bytes available? if (pos < buf.length) { - copyLength = (buf.length - pos >= length) ? length : buf.length - - pos; + copyLength = (buf.length - pos >= byteCount) ? byteCount : buf.length - pos; System.arraycopy(buf, pos, buffer, newOffset, copyLength); newOffset += copyLength; copiedBytes += copyLength; @@ -190,10 +179,10 @@ public class PushbackInputStream extends FilterInputStream { pos += copyLength; } // Have we copied enough? - if (copyLength == length) { - return length; + if (copyLength == byteCount) { + return byteCount; } - int inCopied = in.read(buffer, newOffset, length - copiedBytes); + int inCopied = in.read(buffer, newOffset, byteCount - copiedBytes); if (inCopied > 0) { return inCopied + copiedBytes; } diff --git a/luni/src/main/java/java/io/PushbackReader.java b/luni/src/main/java/java/io/PushbackReader.java index 2e3cf83..59e6644 100644 --- a/luni/src/main/java/java/io/PushbackReader.java +++ b/luni/src/main/java/java/io/PushbackReader.java @@ -155,26 +155,15 @@ public class PushbackReader extends FilterReader { } /** - * Reads at most {@code length} bytes from this reader and stores them in - * byte array {@code buffer} starting at {@code offset}. Characters are + * Reads up to {@code count} characters from this reader and stores them in + * character array {@code buffer} starting at {@code offset}. Characters are * read from the pushback buffer first, then from the source reader if more * bytes are required. Blocks until {@code count} characters have been read, * the end of the source reader is detected or an exception is thrown. + * Returns the number of bytes read or -1 if the end of the source reader has been reached. * - * @param buffer - * the array in which to store the characters read from this - * reader. - * @param offset - * the initial position in {@code buffer} to store the characters - * read from this reader. - * @param count - * the maximum number of bytes to store in {@code buffer}. - * @return the number of bytes read or -1 if the end of the source reader - * has been reached. * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code count < 0}, or if - * {@code offset + count} is greater than the length of - * {@code buffer}. + * if {@code offset < 0 || count < 0 || offset + count > buffer.length}. * @throws IOException * if this reader is closed or another I/O error occurs while * reading from this reader. diff --git a/luni/src/main/java/java/io/RandomAccessFile.java b/luni/src/main/java/java/io/RandomAccessFile.java index dde779e..a60da3e 100644 --- a/luni/src/main/java/java/io/RandomAccessFile.java +++ b/luni/src/main/java/java/io/RandomAccessFile.java @@ -260,11 +260,9 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable { * byte array {@code buffer}. The maximum number of bytes read corresponds * to the size of {@code buffer}. Blocks until at least one byte has been * read, the end of the file is detected, or an exception is thrown. + * Returns the number of bytes actually read or -1 if the end of the file + * has been reached. See also {@link #readFully}. * - * @param buffer - * the byte array in which to store the bytes read. - * @return the number of bytes actually read or -1 if the end of the file - * has been reached. * @throws IOException * if this file is closed or another I/O error occurs. */ @@ -273,16 +271,15 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable { } /** - * Reads at most {@code byteCount} bytes from the current position in this file + * Reads up to {@code byteCount} bytes from the current position in this file * and stores them in the byte array {@code buffer} starting at {@code * byteOffset}. Blocks until at least one byte has been * read, the end of the file is detected, or an exception is thrown. + * Returns the number of bytes actually read or -1 if the end of the stream has been reached. + * See also {@link #readFully}. * - * @return the number of bytes actually read or -1 if the end of the stream - * has been reached. * @throws IndexOutOfBoundsException - * if {@code byteOffset < 0} or {@code byteCount < 0}, or if {@code - * byteOffset + byteCount} is greater than the size of {@code buffer}. + * if {@code byteOffset < 0 || byteCount < 0 || byteOffset + byteCount > buffer.length}. * @throws IOException * if this file is closed or another I/O error occurs. */ diff --git a/luni/src/main/java/java/io/Reader.java b/luni/src/main/java/java/io/Reader.java index e947d08..8ef9a7c 100644 --- a/luni/src/main/java/java/io/Reader.java +++ b/luni/src/main/java/java/io/Reader.java @@ -131,39 +131,26 @@ public abstract class Reader implements Readable, Closeable { /** * Reads characters from this reader and stores them in the character array - * {@code buf} starting at offset 0. Returns the number of characters + * {@code buffer} starting at offset 0. Returns the number of characters * actually read or -1 if the end of the reader has been reached. * - * @param buf - * character array to store the characters read. - * @return the number of characters read or -1 if the end of the reader has - * been reached. * @throws IOException * if this reader is closed or some other I/O error occurs. */ - public int read(char[] buf) throws IOException { - return read(buf, 0, buf.length); + public int read(char[] buffer) throws IOException { + return read(buffer, 0, buffer.length); } /** - * Reads at most {@code count} characters from this reader and stores them - * at {@code offset} in the character array {@code buf}. Returns the number + * Reads up to {@code count} characters from this reader and stores them + * at {@code offset} in the character array {@code buffer}. Returns the number * of characters actually read or -1 if the end of the reader has been * reached. * - * @param buf - * the character array to store the characters read. - * @param offset - * the initial position in {@code buffer} to store the characters - * read from this reader. - * @param count - * the maximum number of characters to read. - * @return the number of characters read or -1 if the end of the reader has - * been reached. * @throws IOException * if this reader is closed or some other I/O error occurs. */ - public abstract int read(char[] buf, int offset, int count) throws IOException; + public abstract int read(char[] buffer, int offset, int count) throws IOException; /** * Indicates whether this reader is ready to be read without blocking. diff --git a/luni/src/main/java/java/io/SequenceInputStream.java b/luni/src/main/java/java/io/SequenceInputStream.java index 8333834..a328167 100644 --- a/luni/src/main/java/java/io/SequenceInputStream.java +++ b/luni/src/main/java/java/io/SequenceInputStream.java @@ -146,15 +146,15 @@ public class SequenceInputStream extends InputStream { } /** - * Reads at most {@code count} bytes from this sequence of input streams and - * stores them in the byte array {@code buffer} starting at {@code offset}. + * Reads up to {@code byteCount} bytes from this sequence of input streams and + * stores them in the byte array {@code buffer} starting at {@code byteOffset}. * Blocks only until at least 1 byte has been read, the end of the stream * has been reached, or an exception is thrown. * <p> * This SequenceInputStream shows the same behavior as other InputStreams. * To do this it will read only as many bytes as a call to read on the * current substream returns. If that call does not return as many bytes as - * requested by {@code count}, it will not retry to read more on its own + * requested by {@code byteCount}, it will not retry to read more on its own * because subsequent reads might block. This would violate the rule that * it will only block until at least one byte has been read. * <p> @@ -162,32 +162,21 @@ public class SequenceInputStream extends InputStream { * will close that substream and start with the next one. If there are no * more substreams it will return -1. * - * @param buffer - * the array in which to store the bytes read. - * @param offset - * the initial position in {@code buffer} to store the bytes read - * from this stream. - * @param count - * the maximum number of bytes to store in {@code buffer}. - * @return the number of bytes actually read; -1 if this sequence of streams - * is closed or if the end of the last stream in the sequence has - * been reached. * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code count < 0}, or if {@code - * offset + count} is greater than the size of {@code buffer}. + * if {@code byteOffset < 0 || byteCount < 0 || byteOffset + byteCount > buffer.length}. * @throws IOException * if an I/O error occurs. * @throws NullPointerException - * if {@code buffer} is {@code null}. + * if {@code buffer == null}. */ @Override - public int read(byte[] buffer, int offset, int count) throws IOException { + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { if (in == null) { return -1; } - Arrays.checkOffsetAndCount(buffer.length, offset, count); + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); while (in != null) { - int result = in.read(buffer, offset, count); + int result = in.read(buffer, byteOffset, byteCount); if (result >= 0) { return result; } diff --git a/luni/src/main/java/java/io/StringBufferInputStream.java b/luni/src/main/java/java/io/StringBufferInputStream.java index 686fd83..fb3fb73 100644 --- a/luni/src/main/java/java/io/StringBufferInputStream.java +++ b/luni/src/main/java/java/io/StringBufferInputStream.java @@ -78,39 +78,18 @@ public class StringBufferInputStream extends InputStream { return pos < count ? buffer.charAt(pos++) & 0xFF : -1; } - /** - * Reads at most {@code length} bytes from the source string and stores them - * in the byte array {@code b} starting at {@code offset}. - * - * @param buffer - * the byte array in which to store the bytes read. - * @param offset - * the initial position in {@code b} to store the bytes read from - * this stream. - * @param length - * the maximum number of bytes to store in {@code b}. - * @return the number of bytes actually read or -1 if the end of the source - * string has been reached. - * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code length < 0}, or if - * {@code offset + length} is greater than the length of - * {@code b}. - * @throws NullPointerException - * if {@code b} is {@code null}. - */ - @Override - public synchronized int read(byte[] buffer, int offset, int length) { + @Override public synchronized int read(byte[] buffer, int byteOffset, int byteCount) { if (buffer == null) { throw new NullPointerException("buffer == null"); } - Arrays.checkOffsetAndCount(buffer.length, offset, length); - if (length == 0) { + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); + if (byteCount == 0) { return 0; } - int copylen = count - pos < length ? count - pos : length; - for (int i = 0; i < copylen; i++) { - buffer[offset + i] = (byte) this.buffer.charAt(pos + i); + int copylen = count - pos < byteCount ? count - pos : byteCount; + for (int i = 0; i < copylen; ++i) { + buffer[byteOffset + i] = (byte) this.buffer.charAt(pos + i); } pos += copylen; return copylen; diff --git a/luni/src/main/java/java/io/StringReader.java b/luni/src/main/java/java/io/StringReader.java index 5579d62..ebe6c83 100644 --- a/luni/src/main/java/java/io/StringReader.java +++ b/luni/src/main/java/java/io/StringReader.java @@ -131,39 +131,29 @@ public class StringReader extends Reader { } /** - * Reads at most {@code len} characters from the source string and stores - * them at {@code offset} in the character array {@code buf}. Returns the + * Reads up to {@code count} characters from the source string and stores + * them at {@code offset} in the character array {@code buffer}. Returns the * number of characters actually read or -1 if the end of the source string * has been reached. * - * @param buf - * the character array to store the characters read. - * @param offset - * the initial position in {@code buffer} to store the characters - * read from this reader. - * @param len - * the maximum number of characters to read. - * @return the number of characters read or -1 if the end of the reader has - * been reached. * @throws IndexOutOfBoundsException - * if {@code offset < 0} or {@code len < 0}, or if - * {@code offset + len} is greater than the size of {@code buf}. + if {@code offset < 0 || count < 0 || offset + count > buffer.length}. * @throws IOException * if this reader is closed. */ @Override - public int read(char[] buf, int offset, int len) throws IOException { + public int read(char[] buffer, int offset, int count) throws IOException { synchronized (lock) { checkNotClosed(); - Arrays.checkOffsetAndCount(buf.length, offset, len); - if (len == 0) { + Arrays.checkOffsetAndCount(buffer.length, offset, count); + if (count == 0) { return 0; } if (pos == this.count) { return -1; } - int end = pos + len > this.count ? this.count : pos + len; - str.getChars(pos, end, buf, offset); + int end = pos + count > this.count ? this.count : pos + count; + str.getChars(pos, end, buffer, offset); int read = end - pos; pos = end; return read; diff --git a/luni/src/main/java/java/net/PlainSocketImpl.java b/luni/src/main/java/java/net/PlainSocketImpl.java index e247ac3..18942d6 100644 --- a/luni/src/main/java/java/net/PlainSocketImpl.java +++ b/luni/src/main/java/java/net/PlainSocketImpl.java @@ -236,8 +236,8 @@ public class PlainSocketImpl extends SocketImpl { return Streams.readSingleByte(this); } - @Override public int read(byte[] buffer, int offset, int byteCount) throws IOException { - return socketImpl.read(buffer, offset, byteCount); + @Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + return socketImpl.read(buffer, byteOffset, byteCount); } } diff --git a/luni/src/main/java/java/nio/SocketChannelImpl.java b/luni/src/main/java/java/nio/SocketChannelImpl.java index 4093be2..714005f 100644 --- a/luni/src/main/java/java/nio/SocketChannelImpl.java +++ b/luni/src/main/java/java/nio/SocketChannelImpl.java @@ -669,12 +669,12 @@ class SocketChannelImpl extends SocketChannel implements FileDescriptorChannel { } @Override - public int read(byte[] buffer, int offset, int byteCount) throws IOException { - Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); if (!channel.isBlocking()) { throw new IllegalBlockingModeException(); } - ByteBuffer buf = ByteBuffer.wrap(buffer, offset, byteCount); + ByteBuffer buf = ByteBuffer.wrap(buffer, byteOffset, byteCount); return channel.read(buf); } } diff --git a/luni/src/main/java/java/nio/channels/Channels.java b/luni/src/main/java/java/nio/channels/Channels.java index b59eeac..e354743 100644 --- a/luni/src/main/java/java/nio/channels/Channels.java +++ b/luni/src/main/java/java/nio/channels/Channels.java @@ -216,8 +216,8 @@ public final class Channels { return Streams.readSingleByte(this); } - @Override public synchronized int read(byte[] target, int offset, int length) throws IOException { - ByteBuffer buffer = ByteBuffer.wrap(target, offset, length); + @Override public synchronized int read(byte[] target, int byteOffset, int byteCount) throws IOException { + ByteBuffer buffer = ByteBuffer.wrap(target, byteOffset, byteCount); checkBlocking(channel); return channel.read(buffer); } diff --git a/luni/src/main/java/java/security/DigestInputStream.java b/luni/src/main/java/java/security/DigestInputStream.java index e7d97ca..655c11f 100644 --- a/luni/src/main/java/java/security/DigestInputStream.java +++ b/luni/src/main/java/java/security/DigestInputStream.java @@ -96,33 +96,26 @@ public class DigestInputStream extends FilterInputStream { } /** - * Reads {@code len} bytes into the specified {@code byte[]}, starting from - * the specified offset. Updates the digest if this function is + * Reads up to {@code byteCount} bytes into {@code buffer}, starting at + * {@code byteOffset}. Updates the digest if this function is * {@link #on(boolean)}. - * <p> - * This operation is blocking. * - * @param b - * the byte array in which to store the bytes - * @param off - * the initial position in {@code b} to store the bytes read from - * this stream - * @param len - * the maximum number of bytes to store in {@code b} - * @return the number of bytes actually read or -1 if the end of the - * filtered stream has been reached while reading + * <p>This operation is blocking. + * + * <p>Returns the number of bytes actually read or -1 if the end of the + * filtered stream has been reached while reading. + * * @throws IOException * if reading the source stream causes an {@code IOException} */ @Override - public int read(byte[] b, int off, int len) throws IOException { - // read next up to len bytes - int bytesRead = in.read(b, off, len); + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + int bytesRead = in.read(buffer, byteOffset, byteCount); // update digest only if // - digest functionality is on // - eos has not been reached if (isOn && (bytesRead != -1)) { - digest.update(b, off, bytesRead); + digest.update(buffer, byteOffset, bytesRead); } // return number of bytes read return bytesRead; diff --git a/luni/src/main/java/java/util/jar/JarFile.java b/luni/src/main/java/java/util/jar/JarFile.java index 0b270bc..c4276e8 100644 --- a/luni/src/main/java/java/util/jar/JarFile.java +++ b/luni/src/main/java/java/util/jar/JarFile.java @@ -98,18 +98,18 @@ public class JarFile extends ZipFile { } @Override - public int read(byte[] buf, int off, int nbytes) throws IOException { + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { if (done) { return -1; } if (count > 0) { - int r = super.read(buf, off, nbytes); + int r = super.read(buffer, byteOffset, byteCount); if (r != -1) { int size = r; if (count < size) { size = (int) count; } - entry.write(buf, off, size); + entry.write(buffer, byteOffset, size); count -= size; } else { count = 0; diff --git a/luni/src/main/java/java/util/jar/JarInputStream.java b/luni/src/main/java/java/util/jar/JarInputStream.java index 03f765f..5e08b5d 100644 --- a/luni/src/main/java/java/util/jar/JarInputStream.java +++ b/luni/src/main/java/java/util/jar/JarInputStream.java @@ -130,25 +130,18 @@ public class JarInputStream extends ZipInputStream { } /** - * Reads up to {@code length} of decompressed data and stores it in - * {@code buffer} starting at {@code offset}. + * Reads up to {@code byteCount} bytes of decompressed data and stores it in + * {@code buffer} starting at {@code byteOffset}. Returns the number of uncompressed bytes read. * - * @param buffer - * Buffer to store into - * @param offset - * offset in buffer to store at - * @param length - * number of bytes to store - * @return Number of uncompressed bytes read * @throws IOException * if an IOException occurs. */ @Override - public int read(byte[] buffer, int offset, int length) throws IOException { + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { if (mEntry != null) { return -1; } - int r = super.read(buffer, offset, length); + int r = super.read(buffer, byteOffset, byteCount); if (verStream != null && !eos) { if (r == -1) { eos = true; @@ -168,7 +161,7 @@ public class JarInputStream extends ZipInputStream { } } } else { - verStream.write(buffer, offset, r); + verStream.write(buffer, byteOffset, r); } } return r; diff --git a/luni/src/main/java/java/util/zip/CheckedInputStream.java b/luni/src/main/java/java/util/zip/CheckedInputStream.java index 454098b..da6c635 100644 --- a/luni/src/main/java/java/util/zip/CheckedInputStream.java +++ b/luni/src/main/java/java/util/zip/CheckedInputStream.java @@ -68,35 +68,26 @@ public class CheckedInputStream extends java.io.FilterInputStream { } /** - * Reads up to n bytes of data from the underlying input stream, storing it - * into {@code buf}, starting at offset {@code off}. The checksum is + * Reads up to {@code byteCount} bytes of data from the underlying input stream, storing it + * into {@code buffer}, starting at offset {@code byteOffset}. The checksum is * updated with the bytes read. + * Returns the number of bytes actually read or {@code -1} if arrived at the + * end of the filtered stream while reading the data. * - * @param buf - * the byte array in which to store the bytes read. - * @param off - * the initial position in {@code buf} to store the bytes read - * from this stream. - * @param nbytes - * the maximum number of bytes to store in {@code buf}. - * @return the number of bytes actually read or {@code -1} if arrived at the - * end of the filtered stream while reading the data. * @throws IOException * if this stream is closed or some I/O error occurs. */ @Override - public int read(byte[] buf, int off, int nbytes) throws IOException { - int x = in.read(buf, off, nbytes); - if (x != -1) { - check.update(buf, off, x); + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + int bytesRead = in.read(buffer, byteOffset, byteCount); + if (bytesRead != -1) { + check.update(buffer, byteOffset, bytesRead); } - return x; + return bytesRead; } /** * Returns the checksum calculated on the stream read so far. - * - * @return the updated checksum. */ public Checksum getChecksum() { return check; diff --git a/luni/src/main/java/java/util/zip/DeflaterInputStream.java b/luni/src/main/java/java/util/zip/DeflaterInputStream.java index d854fec..f987e39 100644 --- a/luni/src/main/java/java/util/zip/DeflaterInputStream.java +++ b/luni/src/main/java/java/util/zip/DeflaterInputStream.java @@ -106,14 +106,14 @@ public class DeflaterInputStream extends FilterInputStream { } /** - * Reads compressed data into a byte buffer. The result will be bytes of compressed + * Reads up to {@code byteCount} bytes of compressed data into a byte buffer. The result will be bytes of compressed * data corresponding to an uncompressed byte or bytes read from the underlying stream. - * @return the number of bytes read or -1 if the end of the compressed input - * stream has been reached. + * Returns the number of bytes read or -1 if the end of the compressed input + * stream has been reached. */ - @Override public int read(byte[] buffer, int offset, int byteCount) throws IOException { + @Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { checkClosed(); - Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); if (byteCount == 0) { return 0; } @@ -137,7 +137,7 @@ public class DeflaterInputStream extends FilterInputStream { if (bytesDeflated == -1) { break; } - System.arraycopy(buf, 0, buffer, offset + count, bytesDeflated); + System.arraycopy(buf, 0, buffer, byteOffset + count, bytesDeflated); count += bytesDeflated; } if (count == 0) { diff --git a/luni/src/main/java/java/util/zip/GZIPInputStream.java b/luni/src/main/java/java/util/zip/GZIPInputStream.java index fd73acc..08599ea 100644 --- a/luni/src/main/java/java/util/zip/GZIPInputStream.java +++ b/luni/src/main/java/java/util/zip/GZIPInputStream.java @@ -148,29 +148,25 @@ public class GZIPInputStream extends InflaterInputStream { super.close(); } - /** - * Reads and decompresses GZIP data from the underlying stream into the - * given buffer. - */ @Override - public int read(byte[] buffer, int offset, int byteCount) throws IOException { + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { if (closed) { throw new IOException("Stream is closed"); } if (eos) { return -1; } - Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); int bytesRead; try { - bytesRead = super.read(buffer, offset, byteCount); + bytesRead = super.read(buffer, byteOffset, byteCount); } finally { eos = eof; // update eos after every read(), even when it throws } if (bytesRead != -1) { - crc.update(buffer, offset, bytesRead); + crc.update(buffer, byteOffset, bytesRead); } if (eos) { diff --git a/luni/src/main/java/java/util/zip/InflaterInputStream.java b/luni/src/main/java/java/util/zip/InflaterInputStream.java index 371c80a..25b2fe8 100644 --- a/luni/src/main/java/java/util/zip/InflaterInputStream.java +++ b/luni/src/main/java/java/util/zip/InflaterInputStream.java @@ -132,14 +132,13 @@ public class InflaterInputStream extends FilterInputStream { /** * Reads up to {@code byteCount} bytes of decompressed data and stores it in - * {@code buffer} starting at {@code offset}. - * - * @return Number of uncompressed bytes read + * {@code buffer} starting at {@code byteOffset}. Returns the number of uncompressed bytes read, + * or -1. */ @Override - public int read(byte[] buffer, int offset, int byteCount) throws IOException { + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { checkClosed(); - Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); if (byteCount == 0) { return 0; @@ -156,7 +155,7 @@ public class InflaterInputStream extends FilterInputStream { // Invariant: if reading returns -1 or throws, eof must be true. // It may also be true if the next read() should return -1. try { - int result = inf.inflate(buffer, offset, byteCount); + int result = inf.inflate(buffer, byteOffset, byteCount); eof = inf.finished(); if (result > 0) { return result; diff --git a/luni/src/main/java/java/util/zip/ZipFile.java b/luni/src/main/java/java/util/zip/ZipFile.java index 97879d5..57c2617 100644 --- a/luni/src/main/java/java/util/zip/ZipFile.java +++ b/luni/src/main/java/java/util/zip/ZipFile.java @@ -406,13 +406,13 @@ public class ZipFile implements Closeable, ZipConstants { return Streams.readSingleByte(this); } - @Override public int read(byte[] b, int off, int len) throws IOException { + @Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { synchronized (sharedRaf) { sharedRaf.seek(offset); - if (len > length - offset) { - len = (int) (length - offset); + if (byteCount > length - offset) { + byteCount = (int) (length - offset); } - int count = sharedRaf.read(b, off, len); + int count = sharedRaf.read(buffer, byteOffset, byteCount); if (count > 0) { offset += count; return count; @@ -451,8 +451,8 @@ public class ZipFile implements Closeable, ZipConstants { this.entry = entry; } - @Override public int read(byte[] buffer, int off, int nbytes) throws IOException { - int i = super.read(buffer, off, nbytes); + @Override public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { + int i = super.read(buffer, byteOffset, byteCount); if (i != -1) { bytesRead += i; } diff --git a/luni/src/main/java/java/util/zip/ZipInputStream.java b/luni/src/main/java/java/util/zip/ZipInputStream.java index d46e2dd..9c18f49 100644 --- a/luni/src/main/java/java/util/zip/ZipInputStream.java +++ b/luni/src/main/java/java/util/zip/ZipInputStream.java @@ -286,15 +286,13 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants } /** - * Reads up to the specified number of uncompressed bytes into the buffer - * starting at the offset. - * - * @return the number of bytes read + * Reads up to {@code byteCount} uncompressed bytes into the buffer + * starting at {@code byteOffset}. Returns the number of bytes actually read, or -1. */ @Override - public int read(byte[] buffer, int offset, int byteCount) throws IOException { + public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException { checkClosed(); - Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); + Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount); if (inf.finished() || currentEntry == null) { return -1; @@ -317,10 +315,10 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants if ((csize - inRead) < toRead) { toRead = csize - inRead; } - System.arraycopy(buf, lastRead, buffer, offset, toRead); + System.arraycopy(buf, lastRead, buffer, byteOffset, toRead); lastRead += toRead; inRead += toRead; - crc.update(buffer, offset, toRead); + crc.update(buffer, byteOffset, toRead); return toRead; } if (inf.needsInput()) { @@ -331,14 +329,14 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants } int read; try { - read = inf.inflate(buffer, offset, byteCount); + read = inf.inflate(buffer, byteOffset, byteCount); } catch (DataFormatException e) { throw new ZipException(e.getMessage()); } if (read == 0 && inf.finished()) { return -1; } - crc.update(buffer, offset, read); + crc.update(buffer, byteOffset, read); return read; } |