java.io
Class BufferedOutputStream

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.io.OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream 
      extended by java.io.FilterOutputStream sample code for java.io.FilterOutputStream definition code for java.io.FilterOutputStream 
          extended by java.io.BufferedOutputStream
All Implemented Interfaces:
Closeable sample code for java.io.Closeable definition code for java.io.Closeable , Flushable sample code for java.io.Flushable definition code for java.io.Flushable

public class BufferedOutputStream
extends FilterOutputStream sample code for java.io.FilterOutputStream definition code for java.io.FilterOutputStream

The class implements a buffered output stream. By setting up such an output stream, an application can write bytes to the underlying output stream without necessarily causing a call to the underlying system for each byte written.

Since:
JDK1.0

Field Summary
protected  byte[] buf sample code for java.io.BufferedOutputStream.buf definition code for java.io.BufferedOutputStream.buf
          The internal buffer where data is stored.
protected  int count sample code for java.io.BufferedOutputStream.count definition code for java.io.BufferedOutputStream.count
          The number of valid bytes in the buffer.
 
Fields inherited from class java.io.FilterOutputStream sample code for java.io.FilterOutputStream definition code for java.io.FilterOutputStream
out sample code for java.io.FilterOutputStream.out definition code for java.io.FilterOutputStream.out
 
Constructor Summary
BufferedOutputStream sample code for java.io.BufferedOutputStream.BufferedOutputStream(java.io.OutputStream) definition code for java.io.BufferedOutputStream.BufferedOutputStream(java.io.OutputStream) (OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out)
          Creates a new buffered output stream to write data to the specified underlying output stream.
BufferedOutputStream sample code for java.io.BufferedOutputStream.BufferedOutputStream(java.io.OutputStream, int) definition code for java.io.BufferedOutputStream.BufferedOutputStream(java.io.OutputStream, int) (OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out, int size)
          Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer size.
 
Method Summary
 void flush sample code for java.io.BufferedOutputStream.flush() definition code for java.io.BufferedOutputStream.flush() ()
          Flushes this buffered output stream.
 void write sample code for java.io.BufferedOutputStream.write(byte[], int, int) definition code for java.io.BufferedOutputStream.write(byte[], int, int) (byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this buffered output stream.
 void write sample code for java.io.BufferedOutputStream.write(int) definition code for java.io.BufferedOutputStream.write(int) (int b)
          Writes the specified byte to this buffered output stream.
 
Methods inherited from class java.io.FilterOutputStream sample code for java.io.FilterOutputStream definition code for java.io.FilterOutputStream
close sample code for java.io.FilterOutputStream.close() definition code for java.io.FilterOutputStream.close() , write sample code for java.io.FilterOutputStream.write(byte[]) definition code for java.io.FilterOutputStream.write(byte[])
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

buf sample code for java.io.BufferedOutputStream.buf

protected byte[] buf
The internal buffer where data is stored.


count sample code for java.io.BufferedOutputStream.count

protected int count
The number of valid bytes in the buffer. This value is always in the range 0 through buf.length; elements buf[0] through buf[count-1] contain valid byte data.

Constructor Detail

BufferedOutputStream sample code for java.io.BufferedOutputStream(java.io.OutputStream) definition code for java.io.BufferedOutputStream(java.io.OutputStream)

public BufferedOutputStream(OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out)
Creates a new buffered output stream to write data to the specified underlying output stream.

Parameters:
out - the underlying output stream.

BufferedOutputStream sample code for java.io.BufferedOutputStream(java.io.OutputStream, int) definition code for java.io.BufferedOutputStream(java.io.OutputStream, int)

public BufferedOutputStream(OutputStream sample code for java.io.OutputStream definition code for java.io.OutputStream  out,
                            int size)
Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer size.

Parameters:
out - the underlying output stream.
size - the buffer size.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if size <= 0.
Method Detail

write sample code for java.io.BufferedOutputStream.write(int) definition code for java.io.BufferedOutputStream.write(int)

public void write(int b)
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Writes the specified byte to this buffered output stream.

Overrides:
write sample code for java.io.FilterOutputStream.write(int) definition code for java.io.FilterOutputStream.write(int) in class FilterOutputStream sample code for java.io.FilterOutputStream definition code for java.io.FilterOutputStream
Parameters:
b - the byte to be written.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs.

write sample code for java.io.BufferedOutputStream.write(byte[], int, int) definition code for java.io.BufferedOutputStream.write(byte[], int, int)

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Writes len bytes from the specified byte array starting at offset off to this buffered output stream.

Ordinarily this method stores bytes from the given array into this stream's buffer, flushing the buffer to the underlying output stream as needed. If the requested length is at least as large as this stream's buffer, however, then this method will flush the buffer and write the bytes directly to the underlying output stream. Thus redundant BufferedOutputStreams will not copy data unnecessarily.

Overrides:
write sample code for java.io.FilterOutputStream.write(byte[], int, int) definition code for java.io.FilterOutputStream.write(byte[], int, int) in class FilterOutputStream sample code for java.io.FilterOutputStream definition code for java.io.FilterOutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs.
See Also:
FilterOutputStream.write(int) sample code for java.io.FilterOutputStream.write(int) definition code for java.io.FilterOutputStream.write(int)

flush sample code for java.io.BufferedOutputStream.flush() definition code for java.io.BufferedOutputStream.flush()

public void flush()
           throws IOException sample code for java.io.IOException definition code for java.io.IOException 
Flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream.

Specified by:
flush sample code for java.io.Flushable.flush() definition code for java.io.Flushable.flush() in interface Flushable sample code for java.io.Flushable definition code for java.io.Flushable
Overrides:
flush sample code for java.io.FilterOutputStream.flush() definition code for java.io.FilterOutputStream.flush() in class FilterOutputStream sample code for java.io.FilterOutputStream definition code for java.io.FilterOutputStream
Throws:
IOException sample code for java.io.IOException definition code for java.io.IOException - if an I/O error occurs.
See Also:
FilterOutputStream.out sample code for java.io.FilterOutputStream.out definition code for java.io.FilterOutputStream.out