Qore::EncodingConversionInputStream Class Reference

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

Inheritance diagram for Qore::EncodingConversionInputStream:
[legend]

## 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
  EncodingConversionInputStream latin2Stream(sourceUtf8Stream, "UTF-8", "ISO-8859-2");
  while ((int i = latin2Stream.read()) != -1) {
  #i is a latin-2 character
  }

## 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

  limit | the maximum number of bytes to read
  timeout_ms | a 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:
  EncodingConversionInputStream latin2Stream(sourceUtf8Stream, "UTF-8", "ISO-8859-2");
  *binary b;
  while (b = latin2Stream.bulkRead(20)) {
  #b contains latin-2 characters
  }

Exceptions

  ENCODING-CONVERSION-ERROR | if 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-ERROR | if 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

  is | the source InputStream to read bytes from
  sourceEncoding | the encoding of the characters in the source input stream
  destEncoding | the destination character encoding

Exceptions

  ENCODING-CONVERSION-ERROR | if 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_ms | a 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:
  EncodingConversionInputStream latin2Stream(sourceUtf8Stream, "UTF-8", "ISO-8859-2");
  while ((int i = latin2Stream.read()) != -1) {
  #i is a latin-2 character
  }

Exceptions

  ENCODING-CONVERSION-ERROR | if an invalid multibyte sequence is encountered in the input

Implements Qore::InputStream.