Cross-Platform C++

ot::io
class BufferedOutputStream

#include "ot/io/BufferedOutputStream.h"

ot::io::OutputStream ot::ManagedObject A BufferedOutputStream wraps another OutputStream object and provides buffering. When the BufferedOutputStream is created, an internal buffer is created. The size of the internal buffer can be specified by using the overloaded constructor.

When bytes are written to the stream, they are copied into the internal buffer instead of being written directly to the contained output stream. When the internal buffer becomes full it is automatically flushed to the contained input stream. In this way i/o efficiency may be improved by translating multiple small write operations into one large one.

To further improve efficiency and avoid the needless copying of data, if the application performs a write request that is larger than the internal buffer, the internal buffer is bypassed and bytes are written directly to the contained output stream.




Constructor/Destructor Summary
BufferedOutputStream(OutputStream* pOutputStream)
         Constructs a BufferedOutputStream using a default buffer size and pOutputStream as the contained output stream.
BufferedOutputStream(OutputStream* pOutputStream, size_t bufSize)
         Constructs a BufferedOutputStream using pOutputStream as the contained output stream and a buffer size of bufSize.
~BufferedOutputStream()
         Writes out and destroys the internal buffer before destroying this BufferedOutputStream.

Method Summary
 virtual void close()
         Any buffered data is written to the output stream before it is closed and any system resources associated with the output stream are released.
 virtual void flush()
         Forces all buffered data to be written out and sent to the final data sink.
 virtual void flushBuffers()
         Forces all data buffers associated with this output stream to be written out.
 virtual void write(const Byte* pBuffer, size_t bufLen)
         Writes an array of bytes to this output stream.

Methods inherited from class ot::ManagedObject
addRef, getRefCount, onFinalRelease, operator=, release

Methods inherited from class ot::io::OutputStream
write

Constructor/Destructor Detail

BufferedOutputStream

 BufferedOutputStream(OutputStream* pOutputStream)
Constructs a BufferedOutputStream using a default buffer size and pOutputStream as the contained output stream.

Exceptions:
NullPointerException - if pOutputStream is null.

BufferedOutputStream

 BufferedOutputStream(OutputStream* pOutputStream,
                      size_t bufSize)
Constructs a BufferedOutputStream using pOutputStream as the contained output stream and a buffer size of bufSize.

Exceptions:
NullPointerException - if pOutputStream is null.

~BufferedOutputStream

virtual ~BufferedOutputStream()
Writes out and destroys the internal buffer before destroying this BufferedOutputStream.


Method Detail

close

virtual void close()
Any buffered data is written to the output stream before it is closed and any system resources associated with the output stream are released. Once an OutputStream is closed further calls to write(), flush() or flushBuffers() will result in an IOException being thrown. Further calls to close() are legal but have no effect.

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

flush

virtual void flush()
Forces all buffered data to be written out and sent to the final data sink.

Exceptions:
IOException - if an I/O error occurs.
See also:
flushBuffers()

flushBuffers

virtual void flushBuffers()
Forces all data buffers associated with this output stream to be written out. This may not cause the data to be sent to the final sink if the underlying sink maintains its own buffering scheme.

Exceptions:
IOException - if an I/O error occurs.
See also:
flush()

write

virtual void write(const Byte* pBuffer,
                   size_t bufLen)
Writes an array of bytes to this output stream. Normally the BufferedOutputStream simply copies the bytes to its internal buffer, flushing the buffer to the contained OutputStream when it becomes full.

In the situation where bufLen is larger than the internal buffer size, the internal buffer will first be flushed before passing this write call directly to the contained OutputStream. By using this technique, the unnecessary copying of data is avoided.

Parameters:
pBuffer - pointer to the start of an array of bytes to be written
bufLen - length of the byte array
Exceptions:
NullPointerException - if pBuffer is null.
IOException - if an I/O error occurs.


Cross-Platform C++

Found a bug or missing feature? Please email us at support@elcel.com

Copyright © 2000-2003 ElCel Technology   Trademark Acknowledgements