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

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