home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / io / PushbackInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  1.4 KB  |  79 lines

  1. package java.io;
  2.  
  3. public class PushbackInputStream extends FilterInputStream {
  4.    protected byte[] buf;
  5.    protected int pos;
  6.  
  7.    public PushbackInputStream(InputStream var1, int var2) {
  8.       super(var1);
  9.       this.buf = new byte[var2];
  10.       this.pos = var2;
  11.    }
  12.  
  13.    public PushbackInputStream(InputStream var1) {
  14.       this(var1, 1);
  15.    }
  16.  
  17.    public int read() throws IOException {
  18.       return this.pos < this.buf.length ? this.buf[this.pos++] & 255 : super.read();
  19.    }
  20.  
  21.    public int read(byte[] var1, int var2, int var3) throws IOException {
  22.       if (var3 <= 0) {
  23.          return 0;
  24.       } else {
  25.          int var4 = this.buf.length - this.pos;
  26.          if (var4 > 0) {
  27.             if (var3 < var4) {
  28.                var4 = var3;
  29.             }
  30.  
  31.             System.arraycopy(this.buf, this.pos, var1, var2, var4);
  32.             this.pos += var4;
  33.             var2 += var4;
  34.             var3 -= var4;
  35.          }
  36.  
  37.          if (var3 > 0) {
  38.             var3 = super.read(var1, var2, var3);
  39.             if (var3 == -1) {
  40.                return var4 == 0 ? -1 : var4;
  41.             } else {
  42.                return var4 + var3;
  43.             }
  44.          } else {
  45.             return var4;
  46.          }
  47.       }
  48.    }
  49.  
  50.    public void unread(int var1) throws IOException {
  51.       if (this.pos == 0) {
  52.          throw new IOException("Push back buffer is full");
  53.       } else {
  54.          this.buf[--this.pos] = (byte)var1;
  55.       }
  56.    }
  57.  
  58.    public void unread(byte[] var1, int var2, int var3) throws IOException {
  59.       if (var3 > this.pos) {
  60.          throw new IOException("Push back buffer is full");
  61.       } else {
  62.          this.pos -= var3;
  63.          System.arraycopy(var1, var2, this.buf, this.pos, var3);
  64.       }
  65.    }
  66.  
  67.    public void unread(byte[] var1) throws IOException {
  68.       this.unread(var1, 0, var1.length);
  69.    }
  70.  
  71.    public int available() throws IOException {
  72.       return this.pos + super.available();
  73.    }
  74.  
  75.    public boolean markSupported() {
  76.       return false;
  77.    }
  78. }
  79.