ot::io
class Writer (abstract)
#include "ot/io/Writer.h"
Abstract base class representing an output stream with the ability to write Unicode characters to a sink.
Concrete sub-classes of Writer may be used to translate Unicode characters into byte sequences which are then written to an OutputStream. In this case, an instance of CodeConverter may be used to translate between Unicode characters and bytes.
Depending on the configuration chosen, Unicode characters may be represented internally using 32-bit UCS-4 characters, 16-bit UTF-16 characters or 8-bit UTF-8 characters. See SystemCodeConverter for further information.
The Writer interface mirrors OutputStream, but deals in characters where OutputStream deals in bytes.
- Multi-threaded considerations:
-
As shown on the inheritance graph, Writer derives from SynchronizedObject, which gives it the ability to protect its internal state from concurrent access from multiple threads. All public methods are synchronized for safe concurrent access.
Method Summary
|
virtual void |
close()=0
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()
If this Writer maintains an output buffer, the buffer is emptied and written to the output destination without requesting the final destination to flush the output. |
RefPtr< SynchronizedObject > |
getLock() const
Returns a reference to the SynchronizedObject used for controlling access to synchronized methods. |
virtual void |
write(CharType c)
Writes the single CharType character c. |
virtual void |
write(const Character& ch)
Writes the Unicode character ch to the output stream. |
virtual void |
write(const String& str)
Writes the sequence of CharType characters contained in the String str. |
virtual void |
write(const CharType* pStr, size_t len)=0
Writes an array of CharType characters. |
Protected Instance Data Members |
m_rpLock
RefPtrMember< SynchronizedObject > m_rpLock
The SynchronizedObject used to control concurrent multi-threaded access to synchronized methods.
unit_type
typedef CharType unit_type
Constructor/Destructor Detail |
Writer
Writer()
-
Default constructor.
Writer
Writer(SynchronizedObject* pLockObject)
-
Constructor taking a SynchronizedObject which will be used as the lock for synchronized functions.
- Exceptions:
NullPointerException
-
if pLockObject is null
close
virtual void close()=0
-
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()
-
If this Writer maintains an output buffer, the buffer is emptied and written to the output destination without requesting the final destination to flush the output.
The base class implementation does nothing.
- See also:
-
flush()
- Multi-threaded considerations:
-
Synchronized for safe access from multiple concurrent threads.
getLock
RefPtr< SynchronizedObject > getLock() const
-
Returns a reference to the SynchronizedObject used for controlling access to synchronized methods.
write
virtual void write(CharType c)
-
Writes the single CharType character c.
Depending on the character encoding being employed, a single CharType character may not represent a complete Unicode character. In this case the characters from subsequent write operations will be used to complete the multi-character sequence.
- Parameters:
c
-
the character to write.
- Exceptions:
IOException
-
if an I/O error occurs.
- See also:
-
write(const Character& ch)
- Multi-threaded considerations:
-
Synchronized for safe access from multiple concurrent threads.
write
virtual void write(const Character& ch)
-
Writes the Unicode character ch to the output stream.
Depending on the character encoding being employed, a single Unicode character may be represented internally using a sequence of more than one CharType characters. In this case, as many CharType characters as are required to encode the Unicode character are written.
- Parameters:
ch
-
the Unicode character to write.
- Exceptions:
IOException
-
if an I/O error occurs.
- See also:
-
write(CharType c)
- Multi-threaded considerations:
-
Synchronized for safe access from multiple concurrent threads.
write
virtual void write(const String& str)
-
Writes the sequence of CharType characters contained in the String str.
- Parameters:
str
-
the String to write.
- Exceptions:
IOException
-
if an I/O error occurs.
- Multi-threaded considerations:
-
Synchronized for safe access from multiple concurrent threads.
write
virtual void write(const CharType* pStr,
size_t len)=0
-
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