ot::io
class BufferedWriter
#include "ot/io/BufferedWriter.h"
A BufferedWriter wraps another Writer object and provides buffering.
When the BufferedWriter is constructed, an internal buffer is created. The size of the internal buffer can be specified by using the overloaded constructor.
When characters are written to this Writer, they are copied into the internal buffer instead of being written directly to the contained Writer. When the internal buffer becomes full it is automatically flushed to the contained Writer. 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 characters are written directly to the contained Writer.
- Multi-threaded considerations:
-
The contained Writer is used as the lock object for synchronized methods.
Constructor/Destructor Summary |
BufferedWriter(Writer* pWriter)
Constructs a BufferedWriter using the default buffer size and pWriter as the contained Writer. |
BufferedWriter(Writer* pWriter, size_t bufSize)
Constructs a BufferedWriter using a buffer size of bufSize and pWriter as the contained Writer. |
~BufferedWriter()
Flushes and destroys the character buffer before destroying this BufferedWriter. |
Method Summary
|
virtual void |
close()
Closes the character stream, flushing it first. |
virtual void |
flush()
Flushes any output buffers before forcing the output to its final destination. |
virtual void |
flushBuffers()
The internal character buffer is written to the contained Writer without requesting that Writer to flush(). |
virtual void |
write(const CharType* pStr, size_t len)
Writes an array of CharType characters. |
Constructor/Destructor Detail |
BufferedWriter
BufferedWriter(Writer* pWriter)
-
Constructs a BufferedWriter using the default buffer size and pWriter as the contained Writer.
- Exceptions:
NullPointerException
-
if pWriter is null.
BufferedWriter
BufferedWriter(Writer* pWriter,
size_t bufSize)
-
Constructs a BufferedWriter using a buffer size of bufSize and pWriter as the contained Writer.
If bufSize is zero, the default buffer size is used.
- Exceptions:
NullPointerException
-
if pWriter is null.
~BufferedWriter
virtual ~BufferedWriter()
-
Flushes and destroys the character buffer before destroying this BufferedWriter.
close
virtual void close()
-
Closes the character stream, flushing it first.
- Multi-threaded considerations:
-
Synchronized for safe access from multiple concurrent threads.
flush
virtual void flush()
-
Flushes any output buffers before forcing the output to its final destination.
- Exceptions:
IOException
-
if an I/O error occurs.
- See also:
-
flushBuffers()
- Multi-threaded considerations:
-
Synchronized for safe access from multiple concurrent threads.
flushBuffers
virtual void flushBuffers()
-
The internal character buffer is written to the contained Writer without requesting that Writer to flush().
- See also:
-
flush()
- Multi-threaded considerations:
-
Synchronized for safe access from multiple concurrent threads.
write
virtual void write(const CharType* pStr,
size_t len)
-
Writes an array of CharType characters.
- Parameters:
pStr
-
a pointer to the first CharType character in the array
len
-
the number of CharType characters to write
- Exceptions:
IOException
-
if an I/O error occurs.
- Multi-threaded considerations:
-
Synchronized for safe access from multiple concurrent threads.
Found a bug or missing feature? Please email us at support@elcel.com