Methods Summary |
---|
public synchronized int | available()Returns the number of bytes that are available before this stream will
block.
return count - pos;
|
public synchronized int | read()Reads a single byte from the source string and returns it as an integer
in the range from 0 to 255. Returns -1 if the end of the source string
has been reached.
return pos < count ? buffer.charAt(pos++) & 0xFF : -1;
|
public synchronized int | read(byte[] b, int offset, int length)Reads at most {@code length} bytes from the source string and stores them
in the byte array {@code b} starting at {@code offset}.
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
// According to 22.7.6 should return -1 before checking other
// parameters.
if (pos >= count) {
return -1;
}
if (b == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
// avoid int overflow
// BEGIN android-changed
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
// removed redundant check, used (offset | length) < 0
// instead of (offset < 0) || (length < 0) to safe one operation
if ((offset | length) < 0 || length > b.length - offset) {
throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
// END android-changed
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;
|
public synchronized void | reset()Resets this stream to the beginning of the source string.
pos = 0;
|
public synchronized long | skip(long n)Skips {@code n} characters in the source string. It does nothing and
returns 0 if {@code n} is negative. Less than {@code n} characters are
skipped if the end of the source string is reached before the operation
completes.
if (n <= 0) {
return 0;
}
int numskipped;
if (this.count - pos < n) {
numskipped = this.count - pos;
pos = this.count;
} else {
numskipped = (int) n;
pos += n;
}
return numskipped;
|