MemoryOutputStream
Object Hierarchy:
GLib.MemoryOutputStream
GLib.MemoryOutputStream
GLib.MemoryOutputStream
GLib.OutputStream
GLib.OutputStream
GLib.OutputStream->GLib.MemoryOutputStream
GLib.Object
GLib.Object
GLib.Object->GLib.OutputStream
GLib.PollableOutputStream
GLib.PollableOutputStream
GLib.PollableOutputStream->GLib.MemoryOutputStream
GLib.Seekable
GLib.Seekable
GLib.Seekable->GLib.MemoryOutputStream
Description:
[
CCode ( type_id =
"g_memory_output_stream_get_type ()" ) ]
public class MemoryOutputStream :
OutputStream ,
PollableOutputStream ,
Seekable
MemoryOutputStream is a class for using arbitrary memory chunks as output for GIO streaming output operations.
As of GLib 2.34, MemoryOutputStream trivially implements
PollableOutputStream : it always polls as ready.
Example: MemoryOutputStream:
public static int main (string [] args) { try { MemoryOutputStream os = new MemoryOutputStream (null , GLib.realloc, GLib.free); // Write data to memory: DataOutputStream dos = new DataOutputStream (os); dos.put_int16 (int16 .MIN); dos.put_int32 (int32 .MIN); dos.put_int64 (int64 .MIN); dos.close (); // Read data: uint8 [] data = os.steal_data (); data.length = (int ) os.get_data_size (); MemoryInputStream @is = new MemoryInputStream.from_data (data, GLib.free); DataInputStream dis = new DataInputStream (@is); print (" %d (Expected: %d ) \n " , dis.read_int16 (), int16 .MIN); print (" %d (Expected: %d ) \n " , dis.read_int32 (), int32 .MIN); print ("%" +int64 .FORMAT+" (Expected: %" +int64 .FORMAT+") \n " , dis.read_int64 (), int64 .MIN); } catch (IOError e) { print ("IOError %s \n " , e.message); } return 0 ; }
valac --pkg gio-2.0 GLib.MemoryOutputStream.vala
Content:
Properties:
public void * data { get ; construct ; }
Pointer to buffer where data will be written.
public ulong data_size { get ; }
Size of data written to the buffer.
public DestroyNotify ? destroy_function { get ; construct ; }
Function called with the buffer as argument when the stream is
destroyed.
public ReallocFunc ? realloc_function { get ; construct ; }
Function with realloc semantics called to enlarge the buffer.
public ulong size { get ; construct ; }
Current size of the data buffer.
Static methods:
public static MemoryOutputStream with_data (uint8 [] data)
public static MemoryOutputStream with_owned_data (owned uint8 [] data)
Creation methods:
Methods:
public unowned uint8 [] get_data ()
Gets any loaded data from the this .
public size_t get_data_size ()
Returns the number of bytes from the start up to including the last
byte written in the stream that has not been truncated away.
public size_t get_size ()
Gets the size of the currently allocated data area (available from
get_data ).
public Bytes steal_as_bytes ()
Returns data from the this as a
Bytes .
public uint8 [] steal_data ()
Gets any loaded data from the this .
Inherited Members:
All known members inherited from class GLib.OutputStream
All known members inherited from class GLib.Object
@get
@new
@ref
@set
add_toggle_ref
add_weak_pointer
bind_property
connect
constructed
disconnect
dispose
dup_data
dup_qdata
force_floating
freeze_notify
get_class
get_data
get_property
get_qdata
get_type
getv
interface_find_property
interface_install_property
interface_list_properties
is_floating
new_valist
new_with_properties
newv
notify
notify_property
ref_count
ref_sink
remove_toggle_ref
remove_weak_pointer
replace_data
replace_qdata
set_data
set_data_full
set_property
set_qdata
set_qdata_full
set_valist
setv
steal_data
steal_qdata
thaw_notify
unref
watch_closure
weak_ref
weak_unref
All known members inherited from interface GLib.PollableOutputStream
All known members inherited from interface GLib.Seekable