home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / PushbackReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  2.1 KB  |  158 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.       synchronized(this.lock) {
  29.          this.ensureOpen();
  30.          return this.pos < this.buf.length ? this.buf[this.pos++] : super.read();
  31.       }
  32.    }
  33.  
  34.    public int read(char[] var1, int var2, int var3) throws IOException {
  35.       synchronized(this.lock) {
  36.          this.ensureOpen();
  37.  
  38.          int var10000;
  39.          try {
  40.             if (var3 <= 0) {
  41.                if (var3 < 0) {
  42.                   throw new IndexOutOfBoundsException();
  43.                }
  44.  
  45.                if (var2 < 0 || var2 > var1.length) {
  46.                   throw new IndexOutOfBoundsException();
  47.                }
  48.  
  49.                var10000 = 0;
  50.                return var10000;
  51.             }
  52.  
  53.             int var5 = this.buf.length - this.pos;
  54.             if (var5 > 0) {
  55.                if (var3 < var5) {
  56.                   var5 = var3;
  57.                }
  58.  
  59.                System.arraycopy(this.buf, this.pos, var1, var2, var5);
  60.                this.pos += var5;
  61.                var2 += var5;
  62.                var3 -= var5;
  63.             }
  64.  
  65.             if (var3 > 0) {
  66.                var3 = super.read(var1, var2, var3);
  67.                if (var3 == -1) {
  68.                   var10000 = var5 == 0 ? -1 : var5;
  69.                   return var10000;
  70.                }
  71.  
  72.                var10000 = var5 + var3;
  73.                return var10000;
  74.             }
  75.  
  76.             var10000 = var5;
  77.          } catch (ArrayIndexOutOfBoundsException var7) {
  78.             throw new IndexOutOfBoundsException();
  79.          }
  80.  
  81.          return var10000;
  82.       }
  83.    }
  84.  
  85.    public void unread(int var1) throws IOException {
  86.       synchronized(this.lock) {
  87.          this.ensureOpen();
  88.          if (this.pos == 0) {
  89.             throw new IOException("Pushback buffer overflow");
  90.          } else {
  91.             this.buf[--this.pos] = (char)var1;
  92.          }
  93.       }
  94.    }
  95.  
  96.    public void unread(char[] var1, int var2, int var3) throws IOException {
  97.       synchronized(this.lock) {
  98.          this.ensureOpen();
  99.          if (var3 > this.pos) {
  100.             throw new IOException("Pushback buffer overflow");
  101.          } else {
  102.             this.pos -= var3;
  103.             System.arraycopy(var1, var2, this.buf, this.pos, var3);
  104.          }
  105.       }
  106.    }
  107.  
  108.    public void unread(char[] var1) throws IOException {
  109.       this.unread(var1, 0, var1.length);
  110.    }
  111.  
  112.    public boolean ready() throws IOException {
  113.       synchronized(this.lock) {
  114.          this.ensureOpen();
  115.          return this.pos < this.buf.length || super.ready();
  116.       }
  117.    }
  118.  
  119.    public void mark(int var1) throws IOException {
  120.       throw new IOException("mark/reset not supported");
  121.    }
  122.  
  123.    public void reset() throws IOException {
  124.       throw new IOException("mark/reset not supported");
  125.    }
  126.  
  127.    public boolean markSupported() {
  128.       return false;
  129.    }
  130.  
  131.    public void close() throws IOException {
  132.       super.close();
  133.       this.buf = null;
  134.    }
  135.  
  136.    public long skip(long var1) throws IOException {
  137.       if (var1 < 0L) {
  138.          throw new IllegalArgumentException("skip value is negative");
  139.       } else {
  140.          synchronized(this.lock) {
  141.             this.ensureOpen();
  142.             int var4 = this.buf.length - this.pos;
  143.             if (var4 > 0) {
  144.                if (var1 <= (long)var4) {
  145.                   this.pos = (int)((long)this.pos + var1);
  146.                   return var1;
  147.                }
  148.  
  149.                this.pos = this.buf.length;
  150.                var1 -= (long)var4;
  151.             }
  152.  
  153.             return (long)var4 + super.skip(var1);
  154.          }
  155.       }
  156.    }
  157. }
  158.