org.apache.cocoon.util
Class BufferedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by org.apache.cocoon.util.BufferedOutputStream
All Implemented Interfaces:
Closeable, Flushable

public class BufferedOutputStream
extends FilterOutputStream

This class is similar to the BufferedOutputStream. In addition it provides an increasing buffer, the possibility to reset the buffer and it counts the number of bytes written to the output stream.

Since:
2.1
Version:
CVS $Id: BufferedOutputStream.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Carsten Ziegeler

Field Summary
 
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 flush buffer size of 32768 bytes and a default initial buffer size of 8192 bytes.
BufferedOutputStream(OutputStream out, int flushBufferSize)
          Creates a new buffered output stream to write data to the specified underlying output stream with the specified flush buffer size and a default initial buffer size of 8192 bytes.
BufferedOutputStream(OutputStream out, int flushBufferSize, int initialBufferSize)
          Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer sizes.
 
Method Summary
 void clearBuffer()
          Deprecated. Public access is deprecated. Use reset() instead.
 void close()
          Closes this buffered output stream.
 void flush()
          Flushes this buffered output stream.
 int getCount()
          Return the size of the current buffer
 boolean isResettable()
           
 void reset()
          Reset the BufferedOutputStream to the last flush().
 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
 

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 flush buffer size of 32768 bytes and a default initial buffer size of 8192 bytes.

Parameters:
out - the underlying output stream.

BufferedOutputStream

public BufferedOutputStream(OutputStream out,
                            int flushBufferSize)
Creates a new buffered output stream to write data to the specified underlying output stream with the specified flush buffer size and a default initial buffer size of 8192 bytes.

Parameters:
out - the underlying output stream.

BufferedOutputStream

public BufferedOutputStream(OutputStream out,
                            int flushBufferSize,
                            int initialBufferSize)
Creates a new buffered output stream to write data to the specified underlying output stream with the specified buffer sizes.

Parameters:
out - the underlying output stream.
flushBufferSize - the buffer size when the stream is flushed. Must be greater than 0 or -1 meaning the stream never flushes itself.
initialBufferSize - the initial buffer size. Must be greater than 0. Will be limited to the flush buffer size.
Method Detail

write

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

Overrides:
write in class FilterOutputStream
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.

Overrides:
write in class FilterOutputStream
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.

Specified by:
flush in interface Flushable
Overrides:
flush in class FilterOutputStream
Throws:
IOException - if an I/O error occurs.

close

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

Specified by:
close in interface Closeable
Overrides:
close in class FilterOutputStream
Throws:
IOException - if an I/O error occurs.

clearBuffer

public void clearBuffer()
Deprecated. Public access is deprecated. Use reset() instead.

Clear the buffer.


reset

public void reset()
Reset the BufferedOutputStream to the last flush().


isResettable

public boolean isResettable()
Returns:
if it is possible to reset the buffer completely, i.e. nothing has been flushed yet.

getCount

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



Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.