8258444: Clean up specifications of java.io.Reader.read(char[],int,int) in subclass overrides

Reviewed-by: alanb, rriggs
This commit is contained in:
Brian Burkhalter 2021-02-25 16:22:59 +00:00
parent 7d4f60b16b
commit 5a9b70103c
9 changed files with 101 additions and 115 deletions

View file

@ -25,6 +25,8 @@
package java.io;
import java.util.Objects;
/**
* This class implements a character buffer that can be used as a
* character-input stream.
@ -34,7 +36,7 @@ package java.io;
*/
public class CharArrayReader extends Reader {
/** The character buffer. */
protected char buf[];
protected char[] buf;
/** The current buffer position. */
protected int pos;
@ -52,7 +54,7 @@ public class CharArrayReader extends Reader {
* Creates a CharArrayReader from the specified array of chars.
* @param buf Input buffer (not copied)
*/
public CharArrayReader(char buf[]) {
public CharArrayReader(char[] buf) {
this.buf = buf;
this.pos = 0;
this.count = buf.length;
@ -75,7 +77,7 @@ public class CharArrayReader extends Reader {
* @param offset Offset of the first char to read
* @param length Number of chars to read
*/
public CharArrayReader(char buf[], int offset, int length) {
public CharArrayReader(char[] buf, int offset, int length) {
if ((offset < 0) || (offset > buf.length) || (length < 0) ||
((offset + length) < 0)) {
throw new IllegalArgumentException();
@ -109,22 +111,27 @@ public class CharArrayReader extends Reader {
/**
* Reads characters into a portion of an array.
* @param b Destination buffer
* @param off Offset at which to start storing characters
* @param len Maximum number of characters to read
* @return The actual number of characters read, or -1 if
* the end of the stream has been reached
*
* @throws IOException If an I/O error occurs
* @throws IndexOutOfBoundsException {@inheritDoc}
* <p> If {@code len} is zero, then no characters are read and {@code 0} is
* returned; otherwise, there is an attempt to read at least one character.
* If no character is available because the stream is at its end, the value
* {@code -1} is returned; otherwise, at least one character is read and
* stored into {@code cbuf}.
*
* @param cbuf {@inheritDoc}
* @param off {@inheritDoc}
* @param len {@inheritDoc}
*
* @return {@inheritDoc}
*
* @throws IndexOutOfBoundsException {@inheritDoc}
* @throws IOException {@inheritDoc}
*/
public int read(char b[], int off, int len) throws IOException {
public int read(char[] cbuf, int off, int len) throws IOException {
synchronized (lock) {
ensureOpen();
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
Objects.checkFromIndexSize(off, len, cbuf.length);
if (len == 0) {
return 0;
}
@ -139,7 +146,7 @@ public class CharArrayReader extends Reader {
if (len <= 0) {
return 0;
}
System.arraycopy(buf, pos, b, off, len);
System.arraycopy(buf, pos, cbuf, off, len);
pos += len;
return len;
}