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

  1. package java.io;
  2.  
  3. import sun.io.CharToByteConverter;
  4. import sun.io.ConversionBufferFullException;
  5.  
  6. public class OutputStreamWriter extends Writer {
  7.    private CharToByteConverter ctb;
  8.    private OutputStream out;
  9.    private static final int defaultByteBufferSize = 8192;
  10.    // $FF: renamed from: bb byte[]
  11.    private byte[] field_0;
  12.    private int nextByte;
  13.    private int nBytes;
  14.  
  15.    public OutputStreamWriter(OutputStream var1, String var2) throws UnsupportedEncodingException {
  16.       this(var1, CharToByteConverter.getConverter(var2));
  17.    }
  18.  
  19.    public OutputStreamWriter(OutputStream var1) {
  20.       this(var1, CharToByteConverter.getDefault());
  21.    }
  22.  
  23.    private OutputStreamWriter(OutputStream var1, CharToByteConverter var2) {
  24.       super(var1);
  25.       this.nextByte = 0;
  26.       this.nBytes = 0;
  27.       if (var1 == null) {
  28.          throw new NullPointerException("out is null");
  29.       } else {
  30.          this.out = var1;
  31.          this.ctb = var2;
  32.          this.field_0 = new byte[8192];
  33.          this.nBytes = 8192;
  34.       }
  35.    }
  36.  
  37.    public String getEncoding() {
  38.       Object var1 = super.lock;
  39.       synchronized(var1) {
  40.          if (this.ctb != null) {
  41.             String var2 = this.ctb.getCharacterEncoding();
  42.             return var2;
  43.          } else {
  44.             Object var3 = null;
  45.             return (String)var3;
  46.          }
  47.       }
  48.    }
  49.  
  50.    private void ensureOpen() throws IOException {
  51.       if (this.out == null) {
  52.          throw new IOException("Stream closed");
  53.       }
  54.    }
  55.  
  56.    public void write(int var1) throws IOException {
  57.       char[] var2 = new char[]{(char)var1};
  58.       this.write((char[])var2, 0, 1);
  59.    }
  60.  
  61.    public void write(char[] var1, int var2, int var3) throws IOException {
  62.       Object var4 = super.lock;
  63.       synchronized(var4) {
  64.          this.ensureOpen();
  65.          if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
  66.             if (var3 != 0) {
  67.                int var5 = var2;
  68.                int var6 = var2 + var3;
  69.                boolean var7 = false;
  70.  
  71.                while(var5 < var6) {
  72.                   boolean var8 = false;
  73.  
  74.                   try {
  75.                      this.nextByte += this.ctb.convertAny(var1, var5, var6, this.field_0, this.nextByte, this.nBytes);
  76.                      var5 = var6;
  77.                   } catch (ConversionBufferFullException var12) {
  78.                      int var10 = this.ctb.nextCharIndex();
  79.                      if (var10 == var5 && var7) {
  80.                         throw new CharConversionException("Output buffer too small");
  81.                      }
  82.  
  83.                      var5 = var10;
  84.                      var8 = true;
  85.                      this.nextByte = this.ctb.nextByteIndex();
  86.                   }
  87.  
  88.                   if (this.nextByte >= this.nBytes || var8) {
  89.                      this.out.write(this.field_0, 0, this.nextByte);
  90.                      this.nextByte = 0;
  91.                      var7 = true;
  92.                   }
  93.                }
  94.  
  95.             }
  96.          } else {
  97.             throw new IndexOutOfBoundsException();
  98.          }
  99.       }
  100.    }
  101.  
  102.    public void write(String var1, int var2, int var3) throws IOException {
  103.       if (var3 < 0) {
  104.          throw new IndexOutOfBoundsException();
  105.       } else {
  106.          char[] var4 = new char[var3];
  107.          var1.getChars(var2, var2 + var3, var4, 0);
  108.          this.write((char[])var4, 0, var3);
  109.       }
  110.    }
  111.  
  112.    void flushBuffer() throws IOException {
  113.       Object var1 = super.lock;
  114.       synchronized(var1) {
  115.          this.ensureOpen();
  116.  
  117.          while(true) {
  118.             try {
  119.                this.nextByte += this.ctb.flushAny(this.field_0, this.nextByte, this.nBytes);
  120.             } catch (ConversionBufferFullException var4) {
  121.                this.nextByte = this.ctb.nextByteIndex();
  122.             }
  123.  
  124.             if (this.nextByte == 0) {
  125.                return;
  126.             }
  127.  
  128.             if (this.nextByte > 0) {
  129.                this.out.write(this.field_0, 0, this.nextByte);
  130.                this.nextByte = 0;
  131.             }
  132.          }
  133.       }
  134.    }
  135.  
  136.    public void flush() throws IOException {
  137.       Object var1 = super.lock;
  138.       synchronized(var1) {
  139.          this.flushBuffer();
  140.          this.out.flush();
  141.       }
  142.    }
  143.  
  144.    public void close() throws IOException {
  145.       Object var1 = super.lock;
  146.       synchronized(var1) {
  147.          if (this.out != null) {
  148.             this.flush();
  149.             this.out.close();
  150.             this.out = null;
  151.             this.field_0 = null;
  152.             this.ctb = null;
  153.          }
  154.       }
  155.    }
  156. }
  157.