org.apache.cocoon.util
Class BufferedOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.FilterOutputStream
          extended byorg.apache.cocoon.util.BufferedOutputStream

public final class BufferedOutputStream
extends FilterOutputStream

This class is like the BufferedOutputStream but it extends it with a logic to count the number of bytes written to the output stream.

Since:
2.1
Version:
$Id: BufferedOutputStream.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
protected  byte[] buf
           
protected  int count
           
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
BufferedOutputStream(OutputStream out)
          Creates a new buffered output stream to write data to the specified underlying output stream with a default 8192-byte buffer size.
BufferedOutputStream(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 clearBuffer()
          Clear/reset the buffer
 void close()
          Closes this buffered output stream.
 void flush()
          Flushes this buffered output stream.
 int getCount()
          Return the size of the current buffer
 void realFlush()
          Flushes this buffered output stream.
 void write(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(int b)
          Writes the specified byte to this buffered output stream.
 
Methods inherited from class java.io.FilterOutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buf

protected byte[] buf

count

protected int count
Constructor Detail

BufferedOutputStream

public BufferedOutputStream(OutputStream out)
Creates a new buffered output stream to write data to the specified underlying output stream with a default 8192-byte buffer size.

Parameters:
out - the underlying output stream.

BufferedOutputStream

public BufferedOutputStream(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 - if size <= 0.
Method Detail

write

public void write(int b)
           throws IOException
Writes the specified byte to this buffered output stream.

Parameters:
b - the byte to be written.
Throws:
IOException - if an I/O error occurs.

write

public void write(byte[] b,
                  int off,
                  int len)
           throws 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.

Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException - if an I/O error occurs.

flush

public void flush()
           throws IOException
Flushes this buffered output stream. We don't flush here, flushing is done during closing.

Throws:
IOException - if an I/O error occurs.

close

public void close()
           throws IOException
Closes this buffered output stream. Flush before closing.

Throws:
IOException - if an I/O error occurs.

realFlush

public void realFlush()
               throws IOException
Flushes this buffered output stream.

Throws:
IOException

clearBuffer

public void clearBuffer()
Clear/reset the buffer


getCount

public int getCount()
Return the size of the current buffer



Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.