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 / BufferedReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  3.5 KB  |  342 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 boolean skipLF;
  15.    private boolean markedSkipLF;
  16.    private static int defaultCharBufferSize = 8192;
  17.    private static int defaultExpectedLineLength = 80;
  18.  
  19.    public BufferedReader(Reader var1, int var2) {
  20.       super(var1);
  21.       this.markedChar = -1;
  22.       this.readAheadLimit = 0;
  23.       this.skipLF = false;
  24.       this.markedSkipLF = false;
  25.       if (var2 <= 0) {
  26.          throw new IllegalArgumentException("Buffer size <= 0");
  27.       } else {
  28.          this.field_0 = var1;
  29.          this.field_1 = new char[var2];
  30.          this.nextChar = this.nChars = 0;
  31.       }
  32.    }
  33.  
  34.    public BufferedReader(Reader var1) {
  35.       this(var1, defaultCharBufferSize);
  36.    }
  37.  
  38.    private void ensureOpen() throws IOException {
  39.       if (this.field_0 == null) {
  40.          throw new IOException("Stream closed");
  41.       }
  42.    }
  43.  
  44.    private void fill() throws IOException {
  45.       int var1;
  46.       if (this.markedChar <= -1) {
  47.          var1 = 0;
  48.       } else {
  49.          int var2 = this.nextChar - this.markedChar;
  50.          if (var2 >= this.readAheadLimit) {
  51.             this.markedChar = -2;
  52.             this.readAheadLimit = 0;
  53.             var1 = 0;
  54.          } else {
  55.             if (this.readAheadLimit <= this.field_1.length) {
  56.                System.arraycopy(this.field_1, this.markedChar, this.field_1, 0, var2);
  57.                this.markedChar = 0;
  58.                var1 = var2;
  59.             } else {
  60.                char[] var3 = new char[this.readAheadLimit];
  61.                System.arraycopy(this.field_1, this.markedChar, var3, 0, var2);
  62.                this.field_1 = var3;
  63.                this.markedChar = 0;
  64.                var1 = var2;
  65.             }
  66.  
  67.             this.nextChar = this.nChars = var2;
  68.          }
  69.       }
  70.  
  71.       int var4;
  72.       do {
  73.          var4 = this.field_0.read(this.field_1, var1, this.field_1.length - var1);
  74.       } while(var4 == 0);
  75.  
  76.       if (var4 > 0) {
  77.          this.nChars = var1 + var4;
  78.          this.nextChar = var1;
  79.       }
  80.  
  81.    }
  82.  
  83.    public int read() throws IOException {
  84.       Object var1 = super.lock;
  85.       synchronized(var1) {
  86.          this.ensureOpen();
  87.  
  88.          while(true) {
  89.             if (this.nextChar >= this.nChars) {
  90.                this.fill();
  91.                if (this.nextChar >= this.nChars) {
  92.                   byte var5 = -1;
  93.                   return var5;
  94.                }
  95.             }
  96.  
  97.             if (!this.skipLF) {
  98.                break;
  99.             }
  100.  
  101.             this.skipLF = false;
  102.             if (this.field_1[this.nextChar] != '\n') {
  103.                break;
  104.             }
  105.  
  106.             ++this.nextChar;
  107.          }
  108.  
  109.          char var2 = this.field_1[this.nextChar++];
  110.          return var2;
  111.       }
  112.    }
  113.  
  114.    private int read1(char[] var1, int var2, int var3) throws IOException {
  115.       if (this.nextChar >= this.nChars) {
  116.          if (var3 >= this.field_1.length && this.markedChar <= -1 && !this.skipLF) {
  117.             return this.field_0.read(var1, var2, var3);
  118.          }
  119.  
  120.          this.fill();
  121.       }
  122.  
  123.       if (this.nextChar >= this.nChars) {
  124.          return -1;
  125.       } else {
  126.          if (this.skipLF) {
  127.             this.skipLF = false;
  128.             if (this.field_1[this.nextChar] == '\n') {
  129.                ++this.nextChar;
  130.                if (this.nextChar >= this.nChars) {
  131.                   this.fill();
  132.                }
  133.  
  134.                if (this.nextChar >= this.nChars) {
  135.                   return -1;
  136.                }
  137.             }
  138.          }
  139.  
  140.          int var4 = Math.min(var3, this.nChars - this.nextChar);
  141.          System.arraycopy(this.field_1, this.nextChar, var1, var2, var4);
  142.          this.nextChar += var4;
  143.          return var4;
  144.       }
  145.    }
  146.  
  147.    public int read(char[] var1, int var2, int var3) throws IOException {
  148.       Object var4 = super.lock;
  149.       synchronized(var4) {
  150.          this.ensureOpen();
  151.          if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
  152.             if (var3 == 0) {
  153.                byte var10 = 0;
  154.                return var10;
  155.             } else {
  156.                int var5 = this.read1(var1, var2, var3);
  157.                if (var5 <= 0) {
  158.                   return var5;
  159.                } else {
  160.                   while(var5 < var3 && this.field_0.ready()) {
  161.                      int var7 = this.read1(var1, var2 + var5, var3 - var5);
  162.                      if (var7 <= 0) {
  163.                         break;
  164.                      }
  165.  
  166.                      var5 += var7;
  167.                   }
  168.  
  169.                   return var5;
  170.                }
  171.             }
  172.          } else {
  173.             throw new IndexOutOfBoundsException();
  174.          }
  175.       }
  176.    }
  177.  
  178.    String readLine(boolean var1) throws IOException {
  179.       StringBuffer var2 = null;
  180.       boolean var4 = var1 || this.skipLF;
  181.       Object var5 = super.lock;
  182.       synchronized(var5) {
  183.          this.ensureOpen();
  184.  
  185.          while(true) {
  186.             if (this.nextChar >= this.nChars) {
  187.                this.fill();
  188.             }
  189.  
  190.             if (this.nextChar >= this.nChars) {
  191.                if (var2 != null && var2.length() > 0) {
  192.                   String var13 = var2.toString();
  193.                   return var13;
  194.                }
  195.  
  196.                Object var14 = null;
  197.                return (String)var14;
  198.             }
  199.  
  200.             boolean var6 = false;
  201.             char var7 = 0;
  202.             if (var4 && this.field_1[this.nextChar] == '\n') {
  203.                ++this.nextChar;
  204.             }
  205.  
  206.             this.skipLF = false;
  207.             var4 = false;
  208.  
  209.             int var8;
  210.             for(var8 = this.nextChar; var8 < this.nChars; ++var8) {
  211.                var7 = this.field_1[var8];
  212.                if (var7 == '\n' || var7 == '\r') {
  213.                   var6 = true;
  214.                   break;
  215.                }
  216.             }
  217.  
  218.             int var3 = this.nextChar;
  219.             this.nextChar = var8;
  220.             if (var6) {
  221.                String var9;
  222.                if (var2 == null) {
  223.                   var9 = new String(this.field_1, var3, var8 - var3);
  224.                } else {
  225.                   var2.append(this.field_1, var3, var8 - var3);
  226.                   var9 = var2.toString();
  227.                }
  228.  
  229.                ++this.nextChar;
  230.                if (var7 == '\r') {
  231.                   this.skipLF = true;
  232.                }
  233.  
  234.                return var9;
  235.             }
  236.  
  237.             if (var2 == null) {
  238.                var2 = new StringBuffer(defaultExpectedLineLength);
  239.             }
  240.  
  241.             var2.append(this.field_1, var3, var8 - var3);
  242.          }
  243.       }
  244.    }
  245.  
  246.    public String readLine() throws IOException {
  247.       return this.readLine(false);
  248.    }
  249.  
  250.    public long skip(long var1) throws IOException {
  251.       if (var1 < 0L) {
  252.          throw new IllegalArgumentException("skip value is negative");
  253.       } else {
  254.          Object var3 = super.lock;
  255.          synchronized(var3) {
  256.             this.ensureOpen();
  257.  
  258.             long var4;
  259.             for(var4 = var1; var4 > 0L; this.nextChar = this.nChars) {
  260.                if (this.nextChar >= this.nChars) {
  261.                   this.fill();
  262.                }
  263.  
  264.                if (this.nextChar >= this.nChars) {
  265.                   break;
  266.                }
  267.  
  268.                if (this.skipLF) {
  269.                   this.skipLF = false;
  270.                   if (this.field_1[this.nextChar] == '\n') {
  271.                      ++this.nextChar;
  272.                   }
  273.                }
  274.  
  275.                long var6 = (long)(this.nChars - this.nextChar);
  276.                if (var4 <= var6) {
  277.                   this.nextChar = (int)((long)this.nextChar + var4);
  278.                   var4 = 0L;
  279.                   break;
  280.                }
  281.  
  282.                var4 -= var6;
  283.             }
  284.  
  285.             long var10 = var1 - var4;
  286.             return var10;
  287.          }
  288.       }
  289.    }
  290.  
  291.    public boolean ready() throws IOException {
  292.       Object var1 = super.lock;
  293.       synchronized(var1) {
  294.          this.ensureOpen();
  295.          boolean var2 = this.nextChar < this.nChars || this.field_0.ready();
  296.          return var2;
  297.       }
  298.    }
  299.  
  300.    public boolean markSupported() {
  301.       return true;
  302.    }
  303.  
  304.    public void mark(int var1) throws IOException {
  305.       if (var1 < 0) {
  306.          throw new IllegalArgumentException("Read-ahead limit < 0");
  307.       } else {
  308.          Object var2 = super.lock;
  309.          synchronized(var2) {
  310.             this.ensureOpen();
  311.             this.readAheadLimit = var1;
  312.             this.markedChar = this.nextChar;
  313.             this.markedSkipLF = this.skipLF;
  314.          }
  315.       }
  316.    }
  317.  
  318.    public void reset() throws IOException {
  319.       Object var1 = super.lock;
  320.       synchronized(var1) {
  321.          this.ensureOpen();
  322.          if (this.markedChar < 0) {
  323.             throw new IOException(this.markedChar == -2 ? "Mark invalid" : "Stream not marked");
  324.          } else {
  325.             this.nextChar = this.markedChar;
  326.             this.skipLF = this.markedSkipLF;
  327.          }
  328.       }
  329.    }
  330.  
  331.    public void close() throws IOException {
  332.       Object var1 = super.lock;
  333.       synchronized(var1) {
  334.          if (this.field_0 != null) {
  335.             this.field_0.close();
  336.             this.field_0 = null;
  337.             this.field_1 = null;
  338.          }
  339.       }
  340.    }
  341. }
  342.