home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class PushbackInputStream extends FilterInputStream {
- protected int pushBack = -1;
-
- public PushbackInputStream(InputStream in) {
- super(in);
- }
-
- public int read() throws IOException {
- int c = this.pushBack;
- if (c != -1) {
- this.pushBack = -1;
- } else {
- c = super.in.read();
- }
-
- return c;
- }
-
- public int read(byte[] bytes, int offset, int length) throws IOException {
- if (this.pushBack != -1) {
- if (length == 0) {
- return 0;
- } else {
- bytes[offset] = (byte)this.pushBack;
- this.pushBack = -1;
- return 1;
- }
- } else {
- return super.in.read(bytes, offset, length);
- }
- }
-
- public void unread(int ch) throws IOException {
- if (this.pushBack != -1) {
- throw new IOException("Attempt to unread more than one character!");
- } else {
- this.pushBack = ch;
- }
- }
-
- public int available() throws IOException {
- return this.pushBack == -1 ? super.available() : super.available() + 1;
- }
-
- public boolean markSupported() {
- return false;
- }
- }
-