home *** CD-ROM | disk | FTP | other *** search
- package java.io;
-
- public class BufferedOutputStream extends FilterOutputStream {
- protected byte[] buf;
- protected int count;
-
- public BufferedOutputStream(OutputStream out) {
- this(out, 512);
- }
-
- public BufferedOutputStream(OutputStream out, int size) {
- super(out);
- this.buf = new byte[size];
- }
-
- public synchronized void write(int b) throws IOException {
- if (this.count == this.buf.length) {
- this.flush();
- }
-
- this.buf[this.count++] = (byte)b;
- }
-
- public synchronized void write(byte[] b, int off, int len) throws IOException {
- int avail = this.buf.length - this.count;
- if (len <= avail) {
- System.arraycopy(b, off, this.buf, this.count, len);
- this.count += len;
- } else {
- this.flush();
- super.out.write(b, off, len);
- }
- }
-
- public synchronized void flush() throws IOException {
- super.out.write(this.buf, 0, this.count);
- super.out.flush();
- this.count = 0;
- }
- }
-