home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 November / PCO1197.ISO / FilesBBS / WIN95 / NET_COM / N32E403.EXE / nav40l.z / java40.jar / java / io / BufferedWriter.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-04  |  2.0 KB  |  159 lines

  1. package java.io;
  2.  
  3. public class BufferedWriter extends Writer {
  4.    private Writer out;
  5.    // $FF: renamed from: cb char[]
  6.    private char[] field_0;
  7.    private int nChars;
  8.    private int nextChar;
  9.    private static int defaultCharBufferSize = 8192;
  10.    private String lineSeparator;
  11.  
  12.    public BufferedWriter(Writer var1) {
  13.       this(var1, defaultCharBufferSize);
  14.    }
  15.  
  16.    public BufferedWriter(Writer var1, int var2) {
  17.       super(var1);
  18.       if (var2 <= 0) {
  19.          throw new IllegalArgumentException("Buffer size <= 0");
  20.       } else {
  21.          this.out = var1;
  22.          this.field_0 = new char[var2];
  23.          this.nChars = var2;
  24.          this.nextChar = 0;
  25.          this.lineSeparator = System.getProperty("line.separator");
  26.       }
  27.    }
  28.  
  29.    private void ensureOpen() throws IOException {
  30.       if (this.out == null) {
  31.          throw new IOException("Stream closed");
  32.       }
  33.    }
  34.  
  35.    void flushBuffer() throws IOException {
  36.       Object var1 = super.lock;
  37.       synchronized(var1){}
  38.  
  39.       try {
  40.          this.ensureOpen();
  41.          if (this.nextChar != 0) {
  42.             this.out.write(this.field_0, 0, this.nextChar);
  43.             this.nextChar = 0;
  44.             return;
  45.          }
  46.       } catch (Throwable var4) {
  47.          throw var4;
  48.       }
  49.  
  50.    }
  51.  
  52.    public void write(int var1) throws IOException {
  53.       Object var2 = super.lock;
  54.       synchronized(var2){}
  55.  
  56.       try {
  57.          this.ensureOpen();
  58.          if (this.nextChar >= this.nChars) {
  59.             this.flushBuffer();
  60.          }
  61.  
  62.          this.field_0[this.nextChar++] = (char)var1;
  63.       } catch (Throwable var4) {
  64.          throw var4;
  65.       }
  66.  
  67.    }
  68.  
  69.    public void write(char[] var1, int var2, int var3) throws IOException {
  70.       Object var4 = super.lock;
  71.       synchronized(var4){}
  72.  
  73.       try {
  74.          this.ensureOpen();
  75.          if (var3 < this.nChars) {
  76.             int var6 = var2;
  77.             int var7 = var2 + var3;
  78.  
  79.             while(var6 < var7) {
  80.                int var8 = Math.min(this.nChars - this.nextChar, var7 - var6);
  81.                System.arraycopy(var1, var6, this.field_0, this.nextChar, var8);
  82.                var6 += var8;
  83.                this.nextChar += var8;
  84.                if (this.nextChar >= this.nChars) {
  85.                   this.flushBuffer();
  86.                }
  87.             }
  88.  
  89.             return;
  90.          }
  91.  
  92.          this.flushBuffer();
  93.          this.out.write(var1, var2, var3);
  94.       } catch (Throwable var10) {
  95.          throw var10;
  96.       }
  97.  
  98.    }
  99.  
  100.    public void write(String var1, int var2, int var3) throws IOException {
  101.       Object var4 = super.lock;
  102.       synchronized(var4){}
  103.  
  104.       try {
  105.          this.ensureOpen();
  106.          int var6 = var2;
  107.          int var7 = var2 + var3;
  108.  
  109.          while(var6 < var7) {
  110.             int var8 = Math.min(this.nChars - this.nextChar, var7 - var6);
  111.             var1.getChars(var6, var6 + var8, this.field_0, this.nextChar);
  112.             var6 += var8;
  113.             this.nextChar += var8;
  114.             if (this.nextChar >= this.nChars) {
  115.                this.flushBuffer();
  116.             }
  117.          }
  118.       } catch (Throwable var10) {
  119.          throw var10;
  120.       }
  121.  
  122.    }
  123.  
  124.    public void newLine() throws IOException {
  125.       ((Writer)this).write(this.lineSeparator);
  126.    }
  127.  
  128.    public void flush() throws IOException {
  129.       Object var1 = super.lock;
  130.       synchronized(var1){}
  131.  
  132.       try {
  133.          this.flushBuffer();
  134.          this.out.flush();
  135.       } catch (Throwable var3) {
  136.          throw var3;
  137.       }
  138.  
  139.    }
  140.  
  141.    public void close() throws IOException {
  142.       Object var1 = super.lock;
  143.       synchronized(var1){}
  144.  
  145.       try {
  146.          if (this.out != null) {
  147.             this.flushBuffer();
  148.             this.out.close();
  149.             this.out = null;
  150.             this.field_0 = null;
  151.             return;
  152.          }
  153.       } catch (Throwable var4) {
  154.          throw var4;
  155.       }
  156.  
  157.    }
  158. }
  159.