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

  1. package java.io;
  2.  
  3. public class BufferedInputStream extends FilterInputStream {
  4.    protected byte[] buf;
  5.    protected int count;
  6.    protected int pos;
  7.    protected int markpos;
  8.    protected int marklimit;
  9.  
  10.    public BufferedInputStream(InputStream var1) {
  11.       this(var1, 2048);
  12.    }
  13.  
  14.    public BufferedInputStream(InputStream var1, int var2) {
  15.       super(var1);
  16.       this.markpos = -1;
  17.       this.buf = new byte[var2];
  18.    }
  19.  
  20.    private void fill() throws IOException {
  21.       if (this.markpos < 0) {
  22.          this.pos = 0;
  23.       } else if (this.pos >= this.buf.length) {
  24.          if (this.markpos > 0) {
  25.             int var1 = this.pos - this.markpos;
  26.             System.arraycopy(this.buf, this.markpos, this.buf, 0, var1);
  27.             this.pos = var1;
  28.             this.markpos = 0;
  29.          } else if (this.buf.length >= this.marklimit) {
  30.             this.markpos = -1;
  31.             this.pos = 0;
  32.          } else {
  33.             int var3 = this.pos * 2;
  34.             if (var3 > this.marklimit) {
  35.                var3 = this.marklimit;
  36.             }
  37.  
  38.             byte[] var2 = new byte[var3];
  39.             System.arraycopy(this.buf, 0, var2, 0, this.pos);
  40.             this.buf = var2;
  41.          }
  42.       }
  43.  
  44.       int var4 = super.in.read(this.buf, this.pos, this.buf.length - this.pos);
  45.       this.count = var4 <= 0 ? this.pos : var4 + this.pos;
  46.    }
  47.  
  48.    public synchronized int read() throws IOException {
  49.       if (this.pos >= this.count) {
  50.          this.fill();
  51.          if (this.pos >= this.count) {
  52.             return -1;
  53.          }
  54.       }
  55.  
  56.       return this.buf[this.pos++] & 255;
  57.    }
  58.  
  59.    public synchronized int read(byte[] var1, int var2, int var3) throws IOException {
  60.       int var4 = this.count - this.pos;
  61.       if (var4 <= 0) {
  62.          if (var3 >= this.buf.length && this.markpos < 0) {
  63.             return super.in.read(var1, var2, var3);
  64.          }
  65.  
  66.          this.fill();
  67.          var4 = this.count - this.pos;
  68.          if (var4 <= 0) {
  69.             return -1;
  70.          }
  71.       }
  72.  
  73.       int var5 = var4 < var3 ? var4 : var3;
  74.       System.arraycopy(this.buf, this.pos, var1, var2, var5);
  75.       this.pos += var5;
  76.       return var5;
  77.    }
  78.  
  79.    public synchronized long skip(long var1) throws IOException {
  80.       if (var1 < 0L) {
  81.          return 0L;
  82.       } else {
  83.          long var3 = (long)(this.count - this.pos);
  84.          if (var3 >= var1) {
  85.             this.pos = (int)((long)this.pos + var1);
  86.             return var1;
  87.          } else {
  88.             this.pos = (int)((long)this.pos + var3);
  89.             return var3 + super.in.skip(var1 - var3);
  90.          }
  91.       }
  92.    }
  93.  
  94.    public synchronized int available() throws IOException {
  95.       return this.count - this.pos + super.in.available();
  96.    }
  97.  
  98.    public synchronized void mark(int var1) {
  99.       this.marklimit = var1;
  100.       this.markpos = this.pos;
  101.    }
  102.  
  103.    public synchronized void reset() throws IOException {
  104.       if (this.markpos < 0) {
  105.          throw new IOException("Resetting to invalid mark");
  106.       } else {
  107.          this.pos = this.markpos;
  108.       }
  109.    }
  110.  
  111.    public boolean markSupported() {
  112.       return true;
  113.    }
  114. }
  115.