home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / io / InputStreamReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  3.2 KB  |  181 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.field_0 = var1;
  27.       this.btc = var2;
  28.       this.field_1 = new byte[8192];
  29.    }
  30.  
  31.    public String getEncoding() {
  32.       Object var2 = super.lock;
  33.       synchronized(var2){}
  34.  
  35.       String var1;
  36.       try {
  37.          if (this.btc == null) {
  38.             var1 = null;
  39.             return var1;
  40.          }
  41.  
  42.          var1 = this.btc.getCharacterEncoding();
  43.       } catch (Throwable var5) {
  44.          throw var5;
  45.       }
  46.  
  47.       return var1;
  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 var5) {
  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 var5) {
  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.             var4 += this.flushInto(var1, var2 + var4, var3);
  101.             if (var4 == 0) {
  102.                return -1;
  103.             }
  104.             break;
  105.          }
  106.  
  107.          this.nextByte = 0;
  108.          var4 += this.convertInto(var1, var2 + var4, var3);
  109.       }
  110.  
  111.       return var4;
  112.    }
  113.  
  114.    private boolean inReady() {
  115.       try {
  116.          return this.field_0.available() > 0;
  117.       } catch (IOException var1) {
  118.          return false;
  119.       }
  120.    }
  121.  
  122.    private void ensureOpen() throws IOException {
  123.       if (this.field_0 == null) {
  124.          throw new IOException("Stream closed");
  125.       }
  126.    }
  127.  
  128.    public int read() throws IOException {
  129.       char[] var1 = new char[1];
  130.       return this.read(var1, 0, 1) == -1 ? -1 : var1[0];
  131.    }
  132.  
  133.    public int read(char[] var1, int var2, int var3) throws IOException {
  134.       Object var5 = super.lock;
  135.       synchronized(var5){}
  136.  
  137.       int var4;
  138.       try {
  139.          this.ensureOpen();
  140.          var4 = this.fill(var1, var2, var2 + var3);
  141.       } catch (Throwable var8) {
  142.          throw var8;
  143.       }
  144.  
  145.       return var4;
  146.    }
  147.  
  148.    public boolean ready() throws IOException {
  149.       Object var2 = super.lock;
  150.       synchronized(var2){}
  151.  
  152.       boolean var1;
  153.       try {
  154.          this.ensureOpen();
  155.          var1 = this.nextByte < this.nBytes || this.inReady();
  156.       } catch (Throwable var5) {
  157.          throw var5;
  158.       }
  159.  
  160.       return var1;
  161.    }
  162.  
  163.    public void close() throws IOException {
  164.       Object var1 = super.lock;
  165.       synchronized(var1){}
  166.  
  167.       try {
  168.          if (this.field_0 != null) {
  169.             this.field_0.close();
  170.             this.field_0 = null;
  171.             this.field_1 = null;
  172.             this.btc = null;
  173.             return;
  174.          }
  175.       } catch (Throwable var4) {
  176.          throw var4;
  177.       }
  178.  
  179.    }
  180. }
  181.