InputStream
Object Hierarchy:
Description:
[
CCode ( type_id =
"g_input_stream_get_type ()" ) ]
public abstract class InputStream :
Object
InputStream has functions to read from a stream (
read), to close a stream (
close) and to skip some content (
skip).
To copy the content of an input stream to an output stream without manually handling the reads and writes, use
splice.
See the documentation for IOStream for details of thread safety of streaming
APIs.
All of these functions have async variants too.
Example: IOStream:
public static int main (string[] args) {
try {
// Create a file that can only be accessed by the current user:
File file = File.new_for_path ("my-test.bin");
IOStream ios = file.create_readwrite (FileCreateFlags.PRIVATE);
//
// Write data:
//
size_t bytes_written;
OutputStream os = ios.output_stream;
os.write_all ("My 1. line\n".data, out bytes_written);
os.write_all ("My 2. line\n".data, out bytes_written);
DataOutputStream dos = new DataOutputStream (os);
dos.put_string ("My 3. line\n");
dos.put_int16 (10);
ios = null;
// Open the file for reading:
InputStream @is = file.read ();
//
// Read n bytes:
//
// Output: ``M``
uint8 buffer[1];
size_t size = @is.read (buffer);
stdout.write (buffer, size);
// Output: ``y 1. line``
DataInputStream dis = new DataInputStream (@is);
string str = dis.read_line ();
print ("%s\n", str);
// Output: ``My 2. line``
str = dis.read_line ();
print ("%s\n", str);
// Output: ``My 3. line``
str = dis.read_line ();
print ("%s\n", str);
// Output: ``10``
int16 i = dis.read_int16 ();
print ("%d\n", i);
} catch (Error e) {
print ("Error: %s\n", e.message);
}
return 0;
}
valac --pkg gio-2.0 GLib.IOStream.vala
Content:
Creation methods:
Methods:
- public void clear_pending ()
Clears the pending flag on this.
- public abstract bool close (Cancellable? cancellable = null) throws IOError
Closes the stream, releasing resources related to it.
- public virtual async bool close_async (int io_priority = DEFAULT, Cancellable? cancellable = null) throws IOError
Requests an asynchronous closes of the stream, releasing resources related
to it.
- public bool has_pending ()
Checks if an input stream has pending actions.
- public bool is_closed ()
Checks if an input stream is closed.
- public abstract ssize_t read (uint8[] buffer, Cancellable? cancellable = null) throws IOError
Tries to read buffer.length
bytes from the stream into the
buffer starting at buffer
.
- public bool read_all (uint8[] buffer, out size_t bytes_read, Cancellable? cancellable = null) throws IOError
Tries to read buffer.length
bytes from the stream into the
buffer starting at buffer
.
- public async bool read_all_async (uint8[] buffer, int io_priority, Cancellable? cancellable, out size_t bytes_read) throws Error
Request an asynchronous read of buffer.length
bytes from the
stream into the buffer starting at buffer
.
- public virtual async ssize_t read_async (uint8[]? buffer, int io_priority = DEFAULT, Cancellable? cancellable = null) throws IOError
Request an asynchronous read of buffer.length
bytes from the
stream into the buffer starting at buffer
.
- public Bytes read_bytes (size_t count, Cancellable? cancellable = null) throws Error
Like
read, this tries to read count
bytes from the stream in a blocking fashion.
- public async Bytes read_bytes_async (size_t count, int io_priority = DEFAULT, Cancellable? cancellable = null) throws Error
Request an asynchronous read of count
bytes from the stream
into a new Bytes.
- public bool set_pending () throws Error
Sets this to have actions pending.
- public virtual ssize_t skip (size_t count, Cancellable? cancellable = null) throws IOError
Tries to skip count
bytes from the stream.
- public virtual async ssize_t skip_async (size_t count, int io_priority = DEFAULT, Cancellable? cancellable = null) throws IOError
Request an asynchronous skip of count
bytes from the stream.
Inherited Members:
All known members inherited from class GLib.Object