Methods Summary |
---|
public void | close()Closes the stream and releases any system resources associated with
it. Once the stream has been closed, further read(),
unread(), ready(), or skip() invocations will throw an IOException.
Closing a previously closed stream has no effect.
super.close();
buf = null;
|
private void | ensureOpen()Checks to make sure that the stream has not been closed.
if (buf == null)
throw new IOException("Stream closed");
|
public void | mark(int readAheadLimit)Marks the present position in the stream. The mark
for class PushbackReader always throws an exception.
throw new IOException("mark/reset not supported");
|
public boolean | markSupported()Tells whether this stream supports the mark() operation, which it does
not.
return false;
|
public int | read()Reads a single character.
synchronized (lock) {
ensureOpen();
if (pos < buf.length)
return buf[pos++];
else
return super.read();
}
|
public int | read(char[] cbuf, int off, int len)Reads characters into a portion of an array.
synchronized (lock) {
ensureOpen();
try {
if (len <= 0) {
if (len < 0) {
throw new IndexOutOfBoundsException();
} else if ((off < 0) || (off > cbuf.length)) {
throw new IndexOutOfBoundsException();
}
return 0;
}
int avail = buf.length - pos;
if (avail > 0) {
if (len < avail)
avail = len;
System.arraycopy(buf, pos, cbuf, off, avail);
pos += avail;
off += avail;
len -= avail;
}
if (len > 0) {
len = super.read(cbuf, off, len);
if (len == -1) {
return (avail == 0) ? -1 : avail;
}
return avail + len;
}
return avail;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IndexOutOfBoundsException();
}
}
|
public boolean | ready()Tells whether this stream is ready to be read.
synchronized (lock) {
ensureOpen();
return (pos < buf.length) || super.ready();
}
|
public void | reset()Resets the stream. The reset method of
PushbackReader always throws an exception.
throw new IOException("mark/reset not supported");
|
public long | skip(long n)Skips characters. This method will block until some characters are
available, an I/O error occurs, or the end of the stream is reached.
if (n < 0L)
throw new IllegalArgumentException("skip value is negative");
synchronized (lock) {
ensureOpen();
int avail = buf.length - pos;
if (avail > 0) {
if (n <= avail) {
pos += n;
return n;
} else {
pos = buf.length;
n -= avail;
}
}
return avail + super.skip(n);
}
|
public void | unread(int c)Pushes back a single character by copying it to the front of the
pushback buffer. After this method returns, the next character to be read
will have the value (char)c .
synchronized (lock) {
ensureOpen();
if (pos == 0)
throw new IOException("Pushback buffer overflow");
buf[--pos] = (char) c;
}
|
public void | unread(char[] cbuf, int off, int len)Pushes back a portion of an array of characters by copying it to the
front of the pushback buffer. After this method returns, the next
character to be read will have the value cbuf[off] , the
character after that will have the value cbuf[off+1] , and
so forth.
synchronized (lock) {
ensureOpen();
if (len > pos)
throw new IOException("Pushback buffer overflow");
pos -= len;
System.arraycopy(cbuf, off, buf, pos, len);
}
|
public void | unread(char[] cbuf)Pushes back an array of characters by copying it to the front of the
pushback buffer. After this method returns, the next character to be
read will have the value cbuf[0] , the character after that
will have the value cbuf[1] , and so forth.
unread(cbuf, 0, cbuf.length);
|