home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / io / BufferedOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  1.1 KB  |  51 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.       this.buf = new byte[var2];
  14.    }
  15.  
  16.    private void flushBuffer() throws IOException {
  17.       if (this.count > 0) {
  18.          super.out.write(this.buf, 0, this.count);
  19.          this.count = 0;
  20.       }
  21.  
  22.    }
  23.  
  24.    public synchronized void write(int var1) throws IOException {
  25.       if (this.count >= this.buf.length) {
  26.          this.flushBuffer();
  27.       }
  28.  
  29.       this.buf[this.count++] = (byte)var1;
  30.    }
  31.  
  32.    public synchronized void write(byte[] var1, int var2, int var3) throws IOException {
  33.       if (var3 >= this.buf.length) {
  34.          this.flushBuffer();
  35.          super.out.write(var1, var2, var3);
  36.       } else {
  37.          if (var3 > this.buf.length - this.count) {
  38.             this.flushBuffer();
  39.          }
  40.  
  41.          System.arraycopy(var1, var2, this.buf, this.count, var3);
  42.          this.count += var3;
  43.       }
  44.    }
  45.  
  46.    public synchronized void flush() throws IOException {
  47.       this.flushBuffer();
  48.       super.out.flush();
  49.    }
  50. }
  51.