Methods Summary |
---|
public void | close()This method closes this CharArrayReader. Once it is closed, you can no
longer read from it. Only the first invocation of this method has any
effect.
synchronized (lock) {
if (isOpen()) {
buf = null;
}
}
|
private boolean | isClosed()Indicates whether this reader is closed.
return buf == null;
|
private boolean | isOpen()Indicates whether this reader is open.
return buf != null;
|
public void | mark(int readLimit)Sets a mark position in this reader. The parameter {@code readLimit} is
ignored for CharArrayReaders. Calling {@code reset()} will reposition the
reader back to the marked position provided the mark has not been
invalidated.
synchronized (lock) {
if (isClosed()) {
throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
markedPos = pos;
}
|
public boolean | markSupported()Indicates whether this reader supports the {@code mark()} and
{@code reset()} methods.
return true;
|
public int | read()Reads a single character from this reader and returns it as an integer
with the two higher-order bytes set to 0. Returns -1 if no more
characters are available from this reader.
synchronized (lock) {
if (isClosed()) {
throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
if (pos == count) {
return -1;
}
return buf[pos++];
}
|
public int | read(char[] buffer, int offset, int len)Reads at most {@code count} characters from this CharArrayReader and
stores them at {@code offset} in the character array {@code buf}.
Returns the number of characters actually read or -1 if the end of reader
was encountered.
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
// avoid int overflow
// BEGIN android-changed
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
// made implicit null check explicit,
// removed redundant check, used (offset | len) < 0 instead of
// (offset < 0) || (len < 0) to safe one operation
if (buffer == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
if ((offset | len) < 0 || len > buffer.length - offset) {
throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
// END android-changed
synchronized (lock) {
if (isClosed()) {
throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
if (pos < this.count) {
int bytesRead = pos + len > this.count ? this.count - pos : len;
System.arraycopy(this.buf, pos, buffer, offset, bytesRead);
pos += bytesRead;
return bytesRead;
}
return -1;
}
|
public boolean | ready()Indicates whether this reader is ready to be read without blocking.
Returns {@code true} if the next {@code read} will not block. Returns
{@code false} if this reader may or may not block when {@code read} is
called. The implementation in CharArrayReader always returns {@code true}
even when it has been closed.
synchronized (lock) {
if (isClosed()) {
throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
return pos != count;
}
|
public void | reset()Resets this reader's position to the last {@code mark()} location.
Invocations of {@code read()} and {@code skip()} will occur from this new
location. If this reader has not been marked, it is reset to the
beginning of the string.
synchronized (lock) {
if (isClosed()) {
throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
pos = markedPos != -1 ? markedPos : 0;
}
|
public long | skip(long n)Skips {@code count} number of characters in this reader. Subsequent
{@code read()}s will not return these characters unless {@code reset()}
is used. This method does nothing and returns 0 if {@code n} is negative.
synchronized (lock) {
if (isClosed()) {
throw new IOException(Msg.getString("K0060")); //$NON-NLS-1$
}
if (n <= 0) {
return 0;
}
long skipped = 0;
if (n < this.count - pos) {
pos = pos + (int) n;
skipped = n;
} else {
skipped = this.count - pos;
pos = this.count;
}
return skipped;
}
|