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

  1. package java.io;
  2.  
  3. public class BufferedReader extends Reader {
  4.    // $FF: renamed from: in java.io.Reader
  5.    private Reader field_0;
  6.    // $FF: renamed from: cb char[]
  7.    private char[] field_1;
  8.    private int nChars;
  9.    private int nextChar;
  10.    private static final int INVALIDATED = -2;
  11.    private static final int UNMARKED = -1;
  12.    private int markedChar;
  13.    private int readAheadLimit;
  14.    private static int defaultCharBufferSize = 8192;
  15.    private static int defaultExpectedLineLength = 80;
  16.  
  17.    public BufferedReader(Reader var1, int var2) {
  18.       super(var1);
  19.       this.markedChar = -1;
  20.       if (var2 <= 0) {
  21.          throw new IllegalArgumentException("Buffer size <= 0");
  22.       } else {
  23.          this.field_0 = var1;
  24.          this.field_1 = new char[var2];
  25.          this.nextChar = this.nChars = 0;
  26.       }
  27.    }
  28.  
  29.    public BufferedReader(Reader var1) {
  30.       this(var1, defaultCharBufferSize);
  31.    }
  32.  
  33.    private void ensureOpen() throws IOException {
  34.       if (this.field_0 == null) {
  35.          throw new IOException("Stream closed");
  36.       }
  37.    }
  38.  
  39.    private void fill() throws IOException {
  40.       int var1;
  41.       if (this.markedChar <= -1) {
  42.          var1 = 0;
  43.       } else {
  44.          int var2 = this.nextChar - this.markedChar;
  45.          if (var2 >= this.readAheadLimit) {
  46.             this.markedChar = -2;
  47.             this.readAheadLimit = 0;
  48.             var1 = 0;
  49.          } else if (this.readAheadLimit <= this.field_1.length) {
  50.             System.arraycopy(this.field_1, this.markedChar, this.field_1, 0, var2);
  51.             this.markedChar = 0;
  52.             var1 = var2;
  53.          } else {
  54.             char[] var3 = new char[this.readAheadLimit];
  55.             System.arraycopy(this.field_1, this.markedChar, var3, 0, var2);
  56.             this.field_1 = var3;
  57.             this.markedChar = 0;
  58.             var1 = var2;
  59.          }
  60.       }
  61.  
  62.       int var4;
  63.       do {
  64.          var4 = this.field_0.read(this.field_1, var1, this.field_1.length - var1);
  65.       } while(var4 == 0);
  66.  
  67.       if (var4 > 0) {
  68.          this.nChars = var1 + var4;
  69.          this.nextChar = var1;
  70.       }
  71.  
  72.    }
  73.  
  74.    public int read() throws IOException {
  75.       Object var2 = super.lock;
  76.       synchronized(var2){}
  77.  
  78.       try {
  79.          this.ensureOpen();
  80.          if (this.nextChar >= this.nChars) {
  81.             this.fill();
  82.             if (this.nextChar >= this.nChars) {
  83.                byte var6 = -1;
  84.                return var6;
  85.             }
  86.          }
  87.  
  88.          char var1 = this.field_1[this.nextChar++];
  89.          return var1;
  90.       } catch (Throwable var5) {
  91.          throw var5;
  92.       }
  93.    }
  94.  
  95.    public int read(char[] var1, int var2, int var3) throws IOException {
  96.       Object var5 = super.lock;
  97.       synchronized(var5){}
  98.  
  99.       int var4;
  100.       try {
  101.          this.ensureOpen();
  102.          if (this.nextChar >= this.nChars) {
  103.             if (var3 >= this.field_1.length && this.markedChar <= -1) {
  104.                var4 = this.field_0.read(var1, var2, var3);
  105.                return var4;
  106.             }
  107.  
  108.             this.fill();
  109.          }
  110.  
  111.          if (this.nextChar < this.nChars) {
  112.             int var7 = Math.min(var3, this.nChars - this.nextChar);
  113.             System.arraycopy(this.field_1, this.nextChar, var1, var2, var7);
  114.             this.nextChar += var7;
  115.             var4 = var7;
  116.             return var4;
  117.          }
  118.  
  119.          var4 = -1;
  120.       } catch (Throwable var9) {
  121.          throw var9;
  122.       }
  123.  
  124.       return var4;
  125.    }
  126.  
  127.    public String readLine() throws IOException {
  128.       StringBuffer var1 = new StringBuffer(defaultExpectedLineLength);
  129.       Object var3 = super.lock;
  130.       synchronized(var3){}
  131.  
  132.       try {
  133.          this.ensureOpen();
  134.  
  135.          boolean var5;
  136.          char var6;
  137.          do {
  138.             if (this.nextChar >= this.nChars) {
  139.                this.fill();
  140.             }
  141.  
  142.             if (this.nextChar >= this.nChars) {
  143.                if (var1.length() <= 0) {
  144.                   Object var10 = null;
  145.                   return (String)var10;
  146.                }
  147.  
  148.                String var2 = var1.toString();
  149.                return var2;
  150.             }
  151.  
  152.             var5 = false;
  153.             var6 = 0;
  154.  
  155.             int var7;
  156.             for(var7 = this.nextChar; var7 < this.nChars; ++var7) {
  157.                var6 = this.field_1[var7];
  158.                if (var6 == '\n' || var6 == '\r') {
  159.                   var5 = true;
  160.                   break;
  161.                }
  162.             }
  163.  
  164.             var1.append(this.field_1, this.nextChar, var7 - this.nextChar);
  165.             this.nextChar = var7;
  166.          } while(!var5);
  167.  
  168.          ++this.nextChar;
  169.          if (var6 != '\r') {
  170.             return var1.toString();
  171.          } else {
  172.             if (this.nextChar >= this.nChars) {
  173.                this.fill();
  174.             }
  175.  
  176.             if (this.nextChar < this.nChars && this.field_1[this.nextChar] == '\n') {
  177.                ++this.nextChar;
  178.             }
  179.  
  180.             return var1.toString();
  181.          }
  182.       } catch (Throwable var9) {
  183.          throw var9;
  184.       }
  185.    }
  186.  
  187.    public long skip(long var1) throws IOException {
  188.       Object var5 = super.lock;
  189.       synchronized(var5){}
  190.  
  191.       long var3;
  192.       try {
  193.          this.ensureOpen();
  194.  
  195.          long var7;
  196.          for(var7 = var1; var7 > 0L; this.nextChar = this.nChars) {
  197.             if (this.nextChar >= this.nChars) {
  198.                this.fill();
  199.             }
  200.  
  201.             if (this.nextChar >= this.nChars) {
  202.                break;
  203.             }
  204.  
  205.             long var9 = (long)(this.nChars - this.nextChar);
  206.             if (var7 <= var9) {
  207.                this.nextChar = (int)((long)this.nextChar + var7);
  208.                var7 = 0L;
  209.                break;
  210.             }
  211.  
  212.             var7 -= var9;
  213.          }
  214.  
  215.          var3 = var1 - var7;
  216.       } catch (Throwable var12) {
  217.          throw var12;
  218.       }
  219.  
  220.       return var3;
  221.    }
  222.  
  223.    public boolean ready() throws IOException {
  224.       Object var2 = super.lock;
  225.       synchronized(var2){}
  226.  
  227.       boolean var1;
  228.       try {
  229.          this.ensureOpen();
  230.          var1 = this.nextChar < this.nChars || this.field_0.ready();
  231.       } catch (Throwable var5) {
  232.          throw var5;
  233.       }
  234.  
  235.       return var1;
  236.    }
  237.  
  238.    public boolean markSupported() {
  239.       return true;
  240.    }
  241.  
  242.    public void mark(int var1) throws IOException {
  243.       if (var1 < 0) {
  244.          throw new IllegalArgumentException("Read-ahead limit < 0");
  245.       } else {
  246.          Object var2 = super.lock;
  247.          synchronized(var2){}
  248.  
  249.          try {
  250.             this.ensureOpen();
  251.             this.readAheadLimit = var1;
  252.             this.markedChar = this.nextChar;
  253.          } catch (Throwable var4) {
  254.             throw var4;
  255.          }
  256.  
  257.       }
  258.    }
  259.  
  260.    public void reset() throws IOException {
  261.       Object var1 = super.lock;
  262.       synchronized(var1){}
  263.  
  264.       try {
  265.          this.ensureOpen();
  266.          if (this.markedChar < 0) {
  267.             throw new IOException(this.markedChar == -2 ? "Mark invalid" : "Stream not marked");
  268.          }
  269.  
  270.          this.nextChar = this.markedChar;
  271.       } catch (Throwable var3) {
  272.          throw var3;
  273.       }
  274.  
  275.    }
  276.  
  277.    public void close() throws IOException {
  278.       Object var1 = super.lock;
  279.       synchronized(var1){}
  280.  
  281.       try {
  282.          if (this.field_0 != null) {
  283.             this.field_0.close();
  284.             this.field_0 = null;
  285.             this.field_1 = null;
  286.             return;
  287.          }
  288.       } catch (Throwable var4) {
  289.          throw var4;
  290.       }
  291.  
  292.    }
  293. }
  294.