|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |
#include "ot/io/InputStreamReader.h"
A CodeConverter can be configured to behave in one of two specified ways when it encounters an encoding error. By default, encoding errors are silently dealt with by skipping the invalid byte sequence and returning the replacement character U+FFFD to the application. A stricter scheme is also available that treats encoding errors as non-recoverable and throws a MalformedInputException. Overloaded versions of the InputStreamReader constructors can be used to explicitly set the required policy.
To improve efficiency, the InputStreamReader contains a byte buffer into which it reads bytes from the underlying input stream. Therefore more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.
The following example demonstrates a simple transcoding function. It decodes a UTF-8 encoded file into a stream of Unicode characters and then writes the characters out encoded into bytes using the UTF-16 encoding:-
File in(OT_T("utf8.txt")); File out(OT_T("utf16.txt")); RefPtr<Reader> rpRdr = new InputStreamReader( new FileInputStream(in), OT_T("UTF-8") ); RefPtr<Writer> rpWtr = new OutputStreamWriter( new FileOutputStream(out), OT_T("UTF-16") ); CharType buffer[1024]; long count; while( (count=rpRdr->read(buffer, sizeof(buffer))) != Reader::EndOfFile) { rpWtr->write(buffer, count); } rpWtr->flush();
Constructor/Destructor Summary | |
InputStreamReader(InputStream* pInputStream) Constructs an InputStreamReader with pInputStream as the contained InputStream. | |
InputStreamReader(InputStream* pInputStream, const String& encoding) Constructs an InputStreamReader with pInputStream as the contained InputStream and encoding as the specified encoding name. | |
InputStreamReader(InputStream* pInputStream, CodeConverter* pDecoder) Constructs an InputStreamReader with pInputStream as the contained InputStream and pDecoder as the CodeConverter which will translate bytes from the input stream into Unicode characters. | |
InputStreamReader(InputStream* pInputStream, const String& encoding, bool bStrict) Constructs an InputStreamReader with pInputStream as the contained InputStream and encoding as the specified encoding name. | |
~InputStreamReader() The destructor frees resources associated with this InputStreamReader. |
Method Summary | |
virtual void |
close() Closes the Reader and its associated InputStream. |
RefPtr< CodeConverter > |
getDecoder() const Returns the CodeConverter used by this InputStreamReader to decode bytes into Unicode characters. |
String |
getEncoding() const Returns the canonical name of the encoding employed by the underlying byte stream. |
virtual long |
read(CharType* pBuffer, size_t bufLen) Reads up to bufLen characters into the supplied buffer. |
virtual Character |
readAtomic() Reads a single Unicode Character. |
virtual long |
readAtomic(CharType* pBuffer, size_t bufLen) Reads an integral number of Unicode characters into the supplied CharType buffer. |
static String |
SenseEncoding(InputStream* pInputStream, size_t& BOMSize) A static helper function that attempts to guess the encoding used by an InputStream by checking the initial byte sequence for a Byte Order Mark (BOM). |
Methods inherited from class ot::ManagedObject |
addRef, getRefCount, onFinalRelease, operator=, release |
Methods inherited from class ot::io::Reader |
getLock, mark, markSupported, read, reset, skip, skipAtomic |
Methods inherited from class ot::SynchronizedObject |
lock, unlock |
Constructor/Destructor Detail |
InputStreamReader(InputStream* pInputStream)
pInputStream
- NullPointerException
- InputStreamReader(InputStream* pInputStream, const String& encoding)
pInputStream
- encoding
- NullPointerException
- UnsupportedEncodingException
- InputStreamReader(InputStream* pInputStream, CodeConverter* pDecoder)
pInputStream
- pDecoder
- NullPointerException
- InputStreamReader(InputStream* pInputStream, const String& encoding, bool bStrict)
pInputStream
- encoding
- bStrict
- NullPointerException
- UnsupportedEncodingException
- virtual ~InputStreamReader()
Method Detail |
virtual void close()
IOException
- RefPtr< CodeConverter > getDecoder() const
String getEncoding() const
virtual long read(CharType* pBuffer, size_t bufLen)
pBuffer
- bufLen
- IllegalArgumentException
- NullPointerException
- IOException
- virtual Character readAtomic()
AtomicReadException
- IOException
- virtual long readAtomic(CharType* pBuffer, size_t bufLen)
A return value of zero indicates that the supplied buffer was not large enough to hold the multi-character sequence for one Unicode character.
pBuffer
- bufLen
- IllegalArgumentException
- NullPointerException
- AtomicReadException
- IOException
- static String SenseEncoding(InputStream* pInputStream, size_t& BOMSize)
pInputStream
- BOMSize
- NullPointerException
- IOException
-
|
OpenTop 1.3 | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | Cross-Platform C++ | ||||
SUMMARY: CONSTRUCTOR | METHOD | DETAIL: CONSTRUCTOR | METHOD |