Qore Programming Language Reference Manual  0.8.12.3
Qore::EncodingConversionInputStream Class Reference

An InputStream implementation that performs on-the-fly conversion between two character encodings. More...

Inheritance diagram for Qore::EncodingConversionInputStream:

Public Member Functions

 constructor (Qore::InputStream is, string sourceEncoding, string destEncoding)
 Creates the EncodingConversionInputStream based on the InputStream given. More...
 
*binary read (int limit)
 Reads bytes (up to a specified limit) from the input stream; returns NOTHING if there are no more bytes in the stream. More...
 
- Public Member Functions inherited from Qore::InputStream
 constructor ()
 Constructor. More...
 

Detailed Description

An InputStream implementation that performs on-the-fly conversion between two character encodings.

Since
Qore 0.8.13
Example: EncodingConversionInputStream basic usage
1 EncodingConversionInputStream latin2Stream(sourceUtf8Stream, "UTF-8", "ISO-8859-2");
2 binary *b;
3 while (b = latin2Stream.read(20)) {
4  #b contains up to 20 bytes representing latin-2 characters
5 }

Member Function Documentation

Qore::EncodingConversionInputStream::constructor ( Qore::InputStream  is,
string  sourceEncoding,
string  destEncoding 
)

Creates the EncodingConversionInputStream based on the InputStream given.

Parameters
isthe source InputStream to read bytes from
sourceEncodingthe encoding of the characters in the source input stream
destEncodingthe destination character encoding
Exceptions
ENCODING-CONVERSION-ERRORif either of the encodings is unsupported
*binary Qore::EncodingConversionInputStream::read ( int  limit)
virtual

Reads bytes (up to a specified limit) from the input stream; returns NOTHING if there are no more bytes in the stream.

Parameters
limitthe maximum number of bytes to read
Returns
the read bytes (the length is between 1 and `limit` inclusive) or NOTHING if no more bytes are available
Example:
1 EncodingConversionInputStream latin2Stream(sourceUtf8Stream, "UTF-8", "ISO-8859-2");
2 *binary b;
3 while (b = latin2Stream.read(20)) {
4  #b contains up to 20 bytes representing latin-2 characters
5 }
Exceptions
ENCODING-CONVERSION-ERRORif an invalid multibyte sequence is encountered in the input

Implements Qore::InputStream.