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 / BufferedOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  990 b   |  55 lines

  1. package java.io;
  2.  
  3. public class BufferedOutputStream extends FilterOutputStream {
  4.    protected byte[] buf;
  5.    protected int count;
  6.  
  7.    public BufferedOutputStream(OutputStream var1) {
  8.       this(var1, 512);
  9.    }
  10.  
  11.    public BufferedOutputStream(OutputStream var1, int var2) {
  12.       super(var1);
  13.       if (var2 <= 0) {
  14.          throw new IllegalArgumentException("Buffer size <= 0");
  15.       } else {
  16.          this.buf = new byte[var2];
  17.       }
  18.    }
  19.  
  20.    private void flushBuffer() throws IOException {
  21.       if (this.count > 0) {
  22.          super.out.write(this.buf, 0, this.count);
  23.          this.count = 0;
  24.       }
  25.  
  26.    }
  27.  
  28.    public synchronized void write(int var1) throws IOException {
  29.       if (this.count >= this.buf.length) {
  30.          this.flushBuffer();
  31.       }
  32.  
  33.       this.buf[this.count++] = (byte)var1;
  34.    }
  35.  
  36.    public synchronized void write(byte[] var1, int var2, int var3) throws IOException {
  37.       if (var3 >= this.buf.length) {
  38.          this.flushBuffer();
  39.          super.out.write(var1, var2, var3);
  40.       } else {
  41.          if (var3 > this.buf.length - this.count) {
  42.             this.flushBuffer();
  43.          }
  44.  
  45.          System.arraycopy(var1, var2, this.buf, this.count, var3);
  46.          this.count += var3;
  47.       }
  48.    }
  49.  
  50.    public synchronized void flush() throws IOException {
  51.       this.flushBuffer();
  52.       super.out.flush();
  53.    }
  54. }
  55.