Methods Summary |
---|
public void | close()Close the stream.
super.close();
buf = null;
|
private void | ensureOpen()Check to make sure that the stream has not been closed.
if (buf == null)
throw new IOException("Stream closed");
|
public void | mark(int readAheadLimit)Mark 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()Tell whether this stream supports the mark() operation, which it does
not.
return false;
|
public int | read()Read 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)Read 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()Tell whether this stream is ready to be read.
synchronized (lock) {
ensureOpen();
return (pos < buf.length) || super.ready();
}
|
public void | reset()Reset the stream. The reset method of
PushbackReader always throws an exception.
throw new IOException("mark/reset not supported");
|
public long | skip(long n)Skip 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)Push back a single character.
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)Push 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)Push 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);
|