home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / io / PushbackReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.8 KB  |  143 lines

  1. package java.io;
  2.  
  3. public class PushbackReader extends FilterReader {
  4.    private char[] buf;
  5.    private int pos;
  6.  
  7.    public PushbackReader(Reader var1, int var2) {
  8.       super(var1);
  9.       if (var2 <= 0) {
  10.          throw new IllegalArgumentException("size <= 0");
  11.       } else {
  12.          this.buf = new char[var2];
  13.          this.pos = var2;
  14.       }
  15.    }
  16.  
  17.    public PushbackReader(Reader var1) {
  18.       this(var1, 1);
  19.    }
  20.  
  21.    private void ensureOpen() throws IOException {
  22.       if (this.buf == null) {
  23.          throw new IOException("Stream closed");
  24.       }
  25.    }
  26.  
  27.    public int read() throws IOException {
  28.       Object var1 = super.lock;
  29.       synchronized(var1) {
  30.          this.ensureOpen();
  31.          if (this.pos < this.buf.length) {
  32.             char var2 = this.buf[this.pos++];
  33.             return var2;
  34.          } else {
  35.             int var3 = super.read();
  36.             return var3;
  37.          }
  38.       }
  39.    }
  40.  
  41.    public int read(char[] var1, int var2, int var3) throws IOException {
  42.       Object var4 = super.lock;
  43.       synchronized(var4) {
  44.          this.ensureOpen();
  45.  
  46.          try {
  47.             if (var3 <= 0) {
  48.                if (var3 < 0) {
  49.                   throw new IndexOutOfBoundsException();
  50.                } else if (var2 >= 0 && var2 <= var1.length) {
  51.                   byte var11 = 0;
  52.                   return var11;
  53.                } else {
  54.                   throw new IndexOutOfBoundsException();
  55.                }
  56.             } else {
  57.                int var5 = this.buf.length - this.pos;
  58.                if (var5 > 0) {
  59.                   if (var3 < var5) {
  60.                      var5 = var3;
  61.                   }
  62.  
  63.                   System.arraycopy(this.buf, this.pos, var1, var2, var5);
  64.                   this.pos += var5;
  65.                   var2 += var5;
  66.                   var3 -= var5;
  67.                }
  68.  
  69.                if (var3 > 0) {
  70.                   var3 = super.read(var1, var2, var3);
  71.                   if (var3 == -1) {
  72.                      int var12 = var5 == 0 ? -1 : var5;
  73.                      return var12;
  74.                   } else {
  75.                      int var6 = var5 + var3;
  76.                      return var6;
  77.                   }
  78.                } else {
  79.                   return var5;
  80.                }
  81.             }
  82.          } catch (ArrayIndexOutOfBoundsException var8) {
  83.             throw new IndexOutOfBoundsException();
  84.          }
  85.       }
  86.    }
  87.  
  88.    public void unread(int var1) throws IOException {
  89.       Object var2 = super.lock;
  90.       synchronized(var2) {
  91.          this.ensureOpen();
  92.          if (this.pos == 0) {
  93.             throw new IOException("Pushback buffer overflow");
  94.          } else {
  95.             this.buf[--this.pos] = (char)var1;
  96.          }
  97.       }
  98.    }
  99.  
  100.    public void unread(char[] var1, int var2, int var3) throws IOException {
  101.       Object var4 = super.lock;
  102.       synchronized(var4) {
  103.          this.ensureOpen();
  104.          if (var3 > this.pos) {
  105.             throw new IOException("Pushback buffer overflow");
  106.          } else {
  107.             this.pos -= var3;
  108.             System.arraycopy(var1, var2, this.buf, this.pos, var3);
  109.          }
  110.       }
  111.    }
  112.  
  113.    public void unread(char[] var1) throws IOException {
  114.       this.unread(var1, 0, var1.length);
  115.    }
  116.  
  117.    public boolean ready() throws IOException {
  118.       Object var1 = super.lock;
  119.       synchronized(var1) {
  120.          this.ensureOpen();
  121.          boolean var2 = this.pos < this.buf.length || super.ready();
  122.          return var2;
  123.       }
  124.    }
  125.  
  126.    public void mark(int var1) throws IOException {
  127.       throw new IOException("mark/reset not supported");
  128.    }
  129.  
  130.    public void reset() throws IOException {
  131.       throw new IOException("mark/reset not supported");
  132.    }
  133.  
  134.    public boolean markSupported() {
  135.       return false;
  136.    }
  137.  
  138.    public void close() throws IOException {
  139.       super.close();
  140.       this.buf = null;
  141.    }
  142. }
  143.