public synchronized int read(byte[] b,
int offset,
int length) {
// According to 22.7.6 should return -1 before checking other
// parameters.
if (pos >= count) {
return -1;
}
if (b == null) {
// luni.11=buffer is null
throw new NullPointerException(Messages.getString("luni.11")); //$NON-NLS-1$
}
// avoid int overflow
if (offset < 0 || offset > b.length) {
// luni.12=Offset out of bounds \: {0}
throw new ArrayIndexOutOfBoundsException(Messages.getString("luni.12", offset)); //$NON-NLS-1$
}
if (length < 0 || length > b.length - offset) {
// luni.18=Length out of bounds \: {0}
throw new ArrayIndexOutOfBoundsException(Messages.getString("luni.18", length)); //$NON-NLS-1$
}
if (length == 0) {
return 0;
}
int copylen = count - pos < length ? count - pos : length;
for (int i = 0; i < copylen; i++) {
b[offset + i] = (byte) buffer.charAt(pos + i);
}
pos += copylen;
return copylen;
} Deprecated!Reads at most {@code length} bytes from the source string and stores them
in the byte array {@code b} starting at {@code offset}. |