Qore Programming Language Reference Manual  0.8.12
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

*binary bulkRead (int limit, timeout timeout_ms=-1)
 Reads bytes (up to a specified limit) from the input stream; returns NOTHING if there are no more bytes in the stream. More...
 
nothing close ()
 Closes the underlying input stream. More...
 
 constructor (Qore::InputStream is, string sourceEncoding, string destEncoding)
 Creates the EncodingConversionInputStream based on the InputStream given. More...
 
int read (timeout timeout_ms=-1)
 Reads a single byte from the input stream; returns -1 if the end of the stream has been reached. 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.12
Example: EncodingConversionInputStream basic usage
1 EncodingConversionInputStream latin2Stream(sourceUtf8Stream, "UTF-8", "ISO-8859-2");
2 while ((int i = latin2Stream.read()) != -1) {
3  #i is a latin-2 character
4 }

Member Function Documentation

*binary Qore::EncodingConversionInputStream::bulkRead ( int  limit,
timeout  timeout_ms = -1 
)
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
timeout_msa timeout period with a resolution of milliseconds (a relative date/time value; integer arguments will be assumed to be milliseconds); if not given or negative the call will never time out
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.bulkRead(20)) {
4  #b contains latin-2 characters
5 }
Exceptions
ENCODING-CONVERSION-ERRORif an invalid multibyte sequence is encountered in the input

Implements Qore::InputStream.

nothing Qore::EncodingConversionInputStream::close ( )
virtual

Closes the underlying input stream.

Any methods called on a closed input stream will thrown an IO-ERROR exception.

Exceptions
IO-ERRORif an I/O error occurs

Implements Qore::InputStream.

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
int Qore::EncodingConversionInputStream::read ( timeout  timeout_ms = -1)
virtual

Reads a single byte from the input stream; returns -1 if the end of the stream has been reached.

Parameters
timeout_msa timeout period with a resolution of milliseconds (a relative date/time value; integer arguments will be assumed to be milliseconds); if not given or negative the call will never time out
Returns
the next byte (0 - 255) in the input stream or -1 if the end of the stream has been reached
Example:
1 EncodingConversionInputStream latin2Stream(sourceUtf8Stream, "UTF-8", "ISO-8859-2");
2 while ((int i = latin2Stream.read()) != -1) {
3  #i is a latin-2 character
4 }
Exceptions
ENCODING-CONVERSION-ERRORif an invalid multibyte sequence is encountered in the input

Implements Qore::InputStream.