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 / InputStreamReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.9 KB  |  173 lines

  1. package java.io;
  2.  
  3. import sun.io.ByteToCharConverter;
  4. import sun.io.ConversionBufferFullException;
  5.  
  6. public class InputStreamReader extends Reader {
  7.    private ByteToCharConverter btc;
  8.    // $FF: renamed from: in java.io.InputStream
  9.    private InputStream field_0;
  10.    private static final int defaultByteBufferSize = 8192;
  11.    // $FF: renamed from: bb byte[]
  12.    private byte[] field_1;
  13.    private int nBytes;
  14.    private int nextByte;
  15.  
  16.    public InputStreamReader(InputStream var1) {
  17.       this(var1, ByteToCharConverter.getDefault());
  18.    }
  19.  
  20.    public InputStreamReader(InputStream var1, String var2) throws UnsupportedEncodingException {
  21.       this(var1, ByteToCharConverter.getConverter(var2));
  22.    }
  23.  
  24.    private InputStreamReader(InputStream var1, ByteToCharConverter var2) {
  25.       super(var1);
  26.       this.nBytes = 0;
  27.       this.nextByte = 0;
  28.       if (var1 == null) {
  29.          throw new NullPointerException("input stream is null");
  30.       } else {
  31.          this.field_0 = var1;
  32.          this.btc = var2;
  33.          this.field_1 = new byte[8192];
  34.       }
  35.    }
  36.  
  37.    public String getEncoding() {
  38.       Object var1 = super.lock;
  39.       synchronized(var1) {
  40.          if (this.btc != null) {
  41.             String var2 = this.btc.getCharacterEncoding();
  42.             return var2;
  43.          } else {
  44.             Object var3 = null;
  45.             return (String)var3;
  46.          }
  47.       }
  48.    }
  49.  
  50.    private void malfunction() {
  51.       throw new InternalError("Converter malfunction (" + this.btc.getCharacterEncoding() + ") -- please submit a bug report via " + System.getProperty("java.vendor.url.bug"));
  52.    }
  53.  
  54.    private int convertInto(char[] var1, int var2, int var3) throws IOException {
  55.       int var4 = 0;
  56.       if (this.nextByte < this.nBytes) {
  57.          try {
  58.             var4 = this.btc.convert(this.field_1, this.nextByte, this.nBytes, var1, var2, var3);
  59.             this.nextByte = this.nBytes;
  60.             if (this.btc.nextByteIndex() != this.nextByte) {
  61.                this.malfunction();
  62.             }
  63.          } catch (ConversionBufferFullException var6) {
  64.             this.nextByte = this.btc.nextByteIndex();
  65.             var4 = this.btc.nextCharIndex() - var2;
  66.          }
  67.       }
  68.  
  69.       return var4;
  70.    }
  71.  
  72.    private int flushInto(char[] var1, int var2, int var3) throws IOException {
  73.       int var4 = 0;
  74.  
  75.       try {
  76.          var4 = this.btc.flush(var1, var2, var3);
  77.       } catch (ConversionBufferFullException var6) {
  78.          var4 = this.btc.nextCharIndex() - var2;
  79.       }
  80.  
  81.       return var4;
  82.    }
  83.  
  84.    private int fill(char[] var1, int var2, int var3) throws IOException {
  85.       int var4 = 0;
  86.       if (this.nextByte < this.nBytes) {
  87.          var4 = this.convertInto(var1, var2, var3);
  88.       }
  89.  
  90.       while(var2 + var4 < var3) {
  91.          if (this.nBytes != -1) {
  92.             if (var4 > 0 && !this.inReady()) {
  93.                break;
  94.             }
  95.  
  96.             this.nBytes = this.field_0.read(this.field_1);
  97.          }
  98.  
  99.          if (this.nBytes == -1) {
  100.             this.nBytes = 0;
  101.             var4 += this.flushInto(var1, var2 + var4, var3);
  102.             if (var4 == 0) {
  103.                return -1;
  104.             }
  105.             break;
  106.          }
  107.  
  108.          this.nextByte = 0;
  109.          var4 += this.convertInto(var1, var2 + var4, var3);
  110.       }
  111.  
  112.       return var4;
  113.    }
  114.  
  115.    private boolean inReady() {
  116.       try {
  117.          return this.field_0.available() > 0;
  118.       } catch (IOException var2) {
  119.          return false;
  120.       }
  121.    }
  122.  
  123.    private void ensureOpen() throws IOException {
  124.       if (this.field_0 == null) {
  125.          throw new IOException("Stream closed");
  126.       }
  127.    }
  128.  
  129.    public int read() throws IOException {
  130.       char[] var1 = new char[1];
  131.       return this.read(var1, 0, 1) == -1 ? -1 : var1[0];
  132.    }
  133.  
  134.    public int read(char[] var1, int var2, int var3) throws IOException {
  135.       Object var4 = super.lock;
  136.       synchronized(var4) {
  137.          this.ensureOpen();
  138.          if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
  139.             if (var3 == 0) {
  140.                byte var8 = 0;
  141.                return var8;
  142.             } else {
  143.                int var5 = this.fill(var1, var2, var2 + var3);
  144.                return var5;
  145.             }
  146.          } else {
  147.             throw new IndexOutOfBoundsException();
  148.          }
  149.       }
  150.    }
  151.  
  152.    public boolean ready() throws IOException {
  153.       Object var1 = super.lock;
  154.       synchronized(var1) {
  155.          this.ensureOpen();
  156.          boolean var2 = this.nextByte < this.nBytes || this.inReady();
  157.          return var2;
  158.       }
  159.    }
  160.  
  161.    public void close() throws IOException {
  162.       Object var1 = super.lock;
  163.       synchronized(var1) {
  164.          if (this.field_0 != null) {
  165.             this.field_0.close();
  166.             this.field_0 = null;
  167.             this.field_1 = null;
  168.             this.btc = null;
  169.          }
  170.       }
  171.    }
  172. }
  173.