ConverterInputStream


Object Hierarchy:

GLib.ConverterInputStream GLib.ConverterInputStream GLib.ConverterInputStream GLib.FilterInputStream GLib.FilterInputStream GLib.FilterInputStream->GLib.ConverterInputStream GLib.InputStream GLib.InputStream GLib.InputStream->GLib.FilterInputStream GLib.Object GLib.Object GLib.Object->GLib.InputStream GLib.PollableInputStream GLib.PollableInputStream GLib.PollableInputStream->GLib.ConverterInputStream

Description:

[ CCode ( type_id = "g_converter_input_stream_get_type ()" ) ]
public class ConverterInputStream : FilterInputStream, PollableInputStream

Converter input stream implements InputStream and allows conversion of data of various types during reading.

As of GLib 2.34, ConverterInputStream implements PollableInputStream.

Example: Charset conversion:

public static int main (string[] args) {
try {
MemoryOutputStream mostream = new MemoryOutputStream (null, GLib.realloc, GLib.free);
CharsetConverter oconverter = new CharsetConverter ("utf-16", "utf-8");
ConverterOutputStream costream = new ConverterOutputStream (mostream, oconverter);
DataOutputStream dostream = new DataOutputStream (costream);
dostream.put_string ("ΑαΒβΓγΔδΕεΖζΗηΘθ\n");
dostream.put_string ("ΙιΚκΛλΜμΝνΞξΟοΠπ\n");
dostream.put_string ("ΡρΣσΤτΥυΦφΧχΨψΩω\n");
mostream.close ();

Bytes bytes = mostream.steal_as_bytes ();

MemoryInputStream mistream = new MemoryInputStream.from_bytes (bytes);
CharsetConverter iconverter = new CharsetConverter ("utf-8", "utf-16");
ConverterInputStream cistream = new ConverterInputStream (mistream, iconverter);
DataInputStream distream = new DataInputStream (cistream);

string line = distream.read_line ();
print (@"$line\n");

line = distream.read_line ();
print (@"$line\n");

line = distream.read_line ();
print (@"$line\n");
} catch (IOError e) {
print ("IOError: %s\n", e.message);
} catch (Error e) {
print ("Error: %s\n", e.message);
}
return 0;
}

valac --pkg gio-2.0 GLib.CharsetConverter.vala

Namespace: GLib
Package: gio-2.0

Content:

Properties:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class GLib.FilterInputStream
All known members inherited from class GLib.Object
All known members inherited from interface GLib.PollableInputStream



2022 vala-language.org