glibmm: Gio::OutputStream Class Reference

# Gio::OutputStream Class Reference
[Stream Classes]

Base class for implementing streaming output. More...

Inherits Glib::Object.

Inherited by Gio::FileOutputStream, Gio::FilterOutputStream, Gio::MemoryOutputStream, and Gio::UnixOutputStream.

Collaboration diagram for Gio::OutputStream:
[legend]

List of all members.

## Public Member Functions
virtual | ~OutputStream ()
GOutputStream* | gobj ()
| Provides access to the underlying C GObject.
const GOutputStream* | gobj () const
| Provides access to the underlying C GObject.
GOutputStream* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
gssize | write (const void* buffer, gsize count, const Glib::RefPtr< Cancellable >& cancellable)
| Tries to write count bytes from buffer into the stream.
gssize | write (const void* buffer, gsize count)
| Tries to write count bytes from buffer into the stream.
gssize | write (const std::string& buffer, const Glib::RefPtr< Cancellable >& cancellable)
| Tries to write count bytes from buffer into the stream.
gssize | write (const std::string& buffer)
| Tries to write count bytes from buffer into the stream.
bool | write_all (const void* buffer, gsize count, gsize& bytes_written, const Glib::RefPtr< Cancellable >& cancellable)
| Tries to write count bytes from buffer into the stream.
bool | write_all (const void* buffer, gsize count, gsize& bytes_written)
| Tries to write count bytes from buffer into the stream.
bool | write_all (const std::string& buffer, gsize& bytes_written, const Glib::RefPtr< Cancellable >& cancellable)
| Tries to write count bytes from buffer into the stream.
bool | write_all (const std::string& buffer, gsize& bytes_written)
| Tries to write count bytes from buffer into the stream.
gssize | splice (const Glib::RefPtr< InputStream >& source, const Glib::RefPtr< Cancellable >& cancellable, OutputStreamSpliceFlags flags=OUTPUT_STREAM_SPLICE_NONE)
| Splices an input stream into an output stream.
gssize | splice (const Glib::RefPtr< InputStream >& source, OutputStreamSpliceFlags flags=OUTPUT_STREAM_SPLICE_NONE)
| Splices an input stream into an output stream.
bool | flush (const Glib::RefPtr< Cancellable >& cancellable)
| Flushed any outstanding buffers in the stream.
bool | flush ()
| Flushed any outstanding buffers in the stream.
bool | close (const Glib::RefPtr< Cancellable >& cancellable)
| Closes the stream, releasing resources related to it.
bool | close ()
| Closes the stream, releasing resources related to it.
void | write_async (const void* buffer, gsize count, const SlotAsyncReady&slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous write of count bytes from buffer into the stream.
void | write_async (const void* buffer, gsize count, const SlotAsyncReady&slot, int io_priority=Glib::PRIORITY_DEFAULT)
| Request an asynchronous write of count bytes from buffer into the stream.
gssize | write_finish (const Glib::RefPtr< AsyncResult >& result)
| Finishes a stream write operation.
void | splice_async (const Glib::RefPtr< InputStream >& source, const SlotAsyncReady&slot, const Glib::RefPtr< Cancellable >& cancellable, OutputStreamSpliceFlags flags=OUTPUT_STREAM_SPLICE_NONE, int io_priority=Glib::PRIORITY_DEFAULT)
| Splices a stream asynchronously.
void | splice_async (const Glib::RefPtr< InputStream >& source, const SlotAsyncReady&slot, OutputStreamSpliceFlags flags=OUTPUT_STREAM_SPLICE_NONE, int io_priority=Glib::PRIORITY_DEFAULT)
| Splices a stream asynchronously.
gssize | splice_finish (const Glib::RefPtr< AsyncResult >& result)
| Finishes an asynchronous stream splice operation.
void | flush_async (const SlotAsyncReady&slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
| Flushes a stream asynchronously.
void | flush_async (const SlotAsyncReady&slot, int io_priority=Glib::PRIORITY_DEFAULT)
| Flushes a stream asynchronously.
bool | flush_finish (const Glib::RefPtr< AsyncResult >& result)
| Finishes flushing an output stream.
void | close_async (const SlotAsyncReady&slot, const Glib::RefPtr< Cancellable >& cancellable, int io_priority=Glib::PRIORITY_DEFAULT)
| Requests an asynchronous close of the stream, releasing resources related to it.
void | close_async (const SlotAsyncReady&slot, int io_priority=Glib::PRIORITY_DEFAULT)
| Requests an asynchronous close of the stream, releasing resources related to it.
bool | close_finish (const Glib::RefPtr< AsyncResult >& result)
| Closes an output stream.
## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gio::OutputStream > | wrap (GOutputStream* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

Base class for implementing streaming output.

Since glibmm 2.16:

## Constructor & Destructor Documentation

virtual Gio::OutputStream::~OutputStream | ( |  | ) | `[virtual]`

## Member Function Documentation

bool Gio::OutputStream::close | ( |  | ) |

Closes the stream, releasing resources related to it.

Once the stream is closed, all other operations will throw a Gio::Error with CLOSED. Closing a stream multiple times will not return an error.

Closing a stream will automatically flush any outstanding buffers in the stream.

Streams will be automatically closed when the last reference is dropped, but you might want to call make sure resources are released as early as possible.

Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details.

On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still throw a Gio::Error with CLOSED for all operations. Still, it is important to check and report the error to the user, otherwise there might be a loss of data as all data might not be written.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown. Cancelling a close will still leave the stream closed, but there some streams can use a faster close that doesn't block to e.g. check errors. On cancellation (as with any error) there is no guarantee that all written data will reach the target.

Parameters:

  | cancellable | Optional cancellable object.

Returns:
  `true` on success, `false` on failure.

bool Gio::OutputStream::close | ( | const Glib::RefPtr< Cancellable >& | cancellable | ) |

Closes the stream, releasing resources related to it.

Once the stream is closed, all other operations will throw a Gio::Error with CLOSED. Closing a stream multiple times will not cause an error to be thrown.

Closing a stream will automatically flush any outstanding buffers in the stream.

Streams will be automatically closed when the last reference is dropped, but you might want to call this function to make sure resources are released as early as possible.

Some streams might keep the backing store of the stream (e.g. a file descriptor) open after the stream is closed. See the documentation for the individual stream for details.

On failure the first error that happened will be reported, but the close operation will finish as much as possible. A stream that failed to close will still throw a Gio::Error with CLOSED for all operations. Still, it is important to check and report the error to the user, otherwise there might be a loss of data as all data might not be written.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED. Cancelling a close will still leave the stream closed, but there some streams can use a faster close that doesn't block to e.g. check errors. On cancellation (as with any error) there is no guarantee that all written data will reach the target.

Parameters:

  | cancellable | Cancellable object.

Returns:
  `true` on success, `false` on failure.

void Gio::OutputStream::close_async | ( | const SlotAsyncReady& | slot,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT` |
| ) |  |  |

Requests an asynchronous close of the stream, releasing resources related to it.

When the operation is finished the slot will be called, giving the results. You can then call close_finish() to get the result of the operation. For behaviour details see close().

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters:

  | slot | Callback slot to call when the request is satisfied.
  | io_priority | The io priority of the request.

void Gio::OutputStream::close_async | ( | const SlotAsyncReady& | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT` |
| ) |  |  |

Requests an asynchronous close of the stream, releasing resources related to it.

When the operation is finished the slot will be called, giving the results. You can then call close_finish() to get the result of the operation. For behaviour details see close().

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

Parameters:

  | slot | Callback slot to call when the request is satisfied.
  | cancellable | Cancellable object.
  | io_priority | The io priority of the request.

bool Gio::OutputStream::close_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Closes an output stream.

Parameters:

  | result | A AsyncResult.

Returns:
  `true` if stream was successfully closed, `false` otherwise.

bool Gio::OutputStream::flush | ( |  | ) |

Flushed any outstanding buffers in the stream.

Will block during the operation. Closing the stream will implicitly cause a flush.

This function is optional for inherited classes.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error with CANCELLED will be thrown.

Parameters:

  | cancellable | Optional cancellable object.

Returns:
  `true` on success, `false` on error.

bool Gio::OutputStream::flush | ( | const Glib::RefPtr< Cancellable >& | cancellable | ) |

Flushed any outstanding buffers in the stream.

Will block during the operation. Closing the stream will implicitly cause a flush.

This function is optional for inherited classes.

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED.

Parameters:

  | cancellable | Cancellable object.

Returns:
  `true` on success, `false` on error.

void Gio::OutputStream::flush_async | ( | const SlotAsyncReady& | slot,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT` |
| ) |  |  |

Flushes a stream asynchronously.

When the operation is finished the slot will be called, giving the results. You can then call flush_finish() to get the result of the operation. For behaviour details see flush().

Parameters:

  | slot | Callback slot to call when the request is satisfied.
  | io_priority | The io priority of the request.

void Gio::OutputStream::flush_async | ( | const SlotAsyncReady& | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT` |
| ) |  |  |

Flushes a stream asynchronously.

When the operation is finished the slot will be called, giving the results. You can then call flush_finish() to get the result of the operation. For behaviour details see flush().

Parameters:

  | slot | Callback slot to call when the request is satisfied.
  | cancellable | Cancellable object.
  | io_priority | The io priority of the request.

bool Gio::OutputStream::flush_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Finishes flushing an output stream.

Parameters:

  | result | A GAsyncResult.

Returns:
  `true` if flush operation suceeded, `false` otherwise.

const GOutputStream* Gio::OutputStream::gobj | ( |  | ) | const`[inline]`

Provides access to the underlying C GObject.

Reimplemented from Glib::ObjectBase.

Reimplemented in Gio::BufferedOutputStream, Gio::DataOutputStream, Gio::FileOutputStream, Gio::FilterOutputStream, Gio::MemoryOutputStream, and Gio::UnixOutputStream.

GOutputStream* Gio::OutputStream::gobj | ( |  | ) | `[inline]`

Provides access to the underlying C GObject.

Reimplemented from Glib::ObjectBase.

Reimplemented in Gio::BufferedOutputStream, Gio::DataOutputStream, Gio::FileOutputStream, Gio::FilterOutputStream, Gio::MemoryOutputStream, and Gio::UnixOutputStream.

GOutputStream* Gio::OutputStream::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

Reimplemented in Gio::BufferedOutputStream, Gio::DataOutputStream, Gio::FileOutputStream, Gio::FilterOutputStream, Gio::MemoryOutputStream, and Gio::UnixOutputStream.

gssize Gio::OutputStream::splice | ( | const Glib::RefPtr< InputStream >& | source,
|  | OutputStreamSpliceFlags | flags = `OUTPUT_STREAM_SPLICE_NONE` |
| ) |  |  |

Splices an input stream into an output stream.

Parameters:

  | source | An InputStream.
  | flags | A set of OutputStreamSpliceFlags. ignore.

Returns:
  A gssize containing the size of the data spliced.

gssize Gio::OutputStream::splice | ( | const Glib::RefPtr< InputStream >& | source,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | OutputStreamSpliceFlags | flags = `OUTPUT_STREAM_SPLICE_NONE` |
| ) |  |  |

Splices an input stream into an output stream.

Parameters:

  | source | An InputStream.
  | flags | A set of OutputStreamSpliceFlags.
  | cancellable | A Cancellable object. ignore.

Returns:
  A gssize containing the size of the data spliced.

void Gio::OutputStream::splice_async | ( | const Glib::RefPtr< InputStream >& | source,
|  | const SlotAsyncReady& | slot,
|  | OutputStreamSpliceFlags | flags = `OUTPUT_STREAM_SPLICE_NONE`,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT` |
| ) |  |  |

Splices a stream asynchronously.

When the operation is finished slot will be called. You can then call splice_finish() to get the result of the operation.

For the synchronous, blocking version of this function, see splice().

Parameters:

  | source | An InputStream.
  | slot | Callback slot to call when the request is satisfied.
  | io_priority | The io priority of the request.

void Gio::OutputStream::splice_async | ( | const Glib::RefPtr< InputStream >& | source,
|  | const SlotAsyncReady& | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | OutputStreamSpliceFlags | flags = `OUTPUT_STREAM_SPLICE_NONE`,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT` |
| ) |  |  |

Splices a stream asynchronously.

When the operation is finished slot will be called. You can then call splice_finish() to get the result of the operation.

For the synchronous, blocking version of this function, see splice().

Parameters:

  | source | An InputStream.
  | slot | Callback slot to call when the request is satisfied.
  | cancellable | Cancellable object.
  | io_priority | The io priority of the request.

gssize Gio::OutputStream::splice_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Finishes an asynchronous stream splice operation.

Parameters:

  | result | A AsyncResult.

Returns:
  A gssize of the number of bytes spliced.

gssize Gio::OutputStream::write | ( | const std::string & | buffer | ) |

Tries to write count bytes from buffer into the stream.

Will block during the operation.

If string that is larger than MAXSSIZE bytes will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written to the stream is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial i/o error, or if the there is not enough storage in the stream. All writes either block until at least one byte is written, so zero is never returned (unless count is zero).

On error -1 is returned.

Parameters:

  | buffer | The buffer containing the data to write.

Returns:
  Number of bytes written, or -1 on error.

gssize Gio::OutputStream::write | ( | const std::string & | buffer,
|  | const Glib::RefPtr< Cancellable >& | cancellable |
| ) |  |  |

Tries to write count bytes from buffer into the stream.

Will block during the operation.

If count is zero returns zero and does nothing. A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written to the stream is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial i/o error, or if the there is not enough storage in the stream. All writes either block until at least one byte is written, so zero is never returned (unless count is zero).

On error -1 is returned.

Parameters:

  | buffer | The buffer containing the data to write.
  | cancellable | Cancellable object.

Returns:
  Number of bytes written, or -1 on error.

gssize Gio::OutputStream::write | ( | const void * | buffer,
|  | gsize | count |
| ) |  |  |

Tries to write count bytes from buffer into the stream.

Will block during the operation.

If count is zero returns zero and does nothing. A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written to the stream is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial i/o error, or if the there is not enough storage in the stream. All writes either block until at least one byte is written, so zero is never returned (unless count is zero).

On error -1 is returned.

Parameters:

  | buffer | The buffer containing the data to write.
  | count | The number of bytes to write.

Returns:
  Number of bytes written, or -1 on error.

gssize Gio::OutputStream::write | ( | const void * | buffer,
|  | gsize | count,
|  | const Glib::RefPtr< Cancellable >& | cancellable |
| ) |  |  |

Tries to write count bytes from buffer into the stream.

Will block during the operation.

If count is zero returns zero and does nothing. A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written to the stream is returned. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial i/o error, or if there is not enough storage in the stream. All writes either block until at least one byte is written, so zero is never returned (unless count is zero).

The operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, a Gio::Error will be thrown with CANCELLED. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.

Parameters:

  | buffer | The buffer containing the data to write.
  | count | The number of bytes to write.
  | cancellable | Cancellable object.

Returns:
  Number of bytes written, or -1 on error.

bool Gio::OutputStream::write_all | ( | const std::string & | buffer,
|  | gsize & | bytes_written |
| ) |  |  |

Tries to write count bytes from buffer into the stream.

Will block during the operation.

This function is similar to write(), except it tries to write as many bytes as requested, only stopping on an error.

On a successful write of count bytes, `true` is returned, and bytes_written is set to count .

If there is an error during the operation `false` is returned and error is set to indicate the error status, bytes_written is updated to contain the number of bytes written into the stream before the error occured.

Parameters:

  | buffer | The buffer containing the data to write.
  | bytes_written | Location to store the number of bytes that was written to the stream.

Returns:
  `true` on success, `false` if there was an error.

bool Gio::OutputStream::write_all | ( | const std::string & | buffer,
|  | gsize & | bytes_written,
|  | const Glib::RefPtr< Cancellable >& | cancellable |
| ) |  |  |

Tries to write count bytes from buffer into the stream.

Will block during the operation.

This function is similar to write(), except it tries to write as many bytes as requested, only stopping on an error.

On a successful write of count bytes, `true` is returned, and bytes_written is set to count .

If there is an error during the operation `false` is returned and error is set to indicate the error status, bytes_written is updated to contain the number of bytes written into the stream before the error occured.

Parameters:

  | buffer | The buffer containing the data to write.
  | bytes_written | Location to store the number of bytes that was written to the stream.
  | cancellable | Cancellable object.

Returns:
  `true` on success, `false` if there was an error.

bool Gio::OutputStream::write_all | ( | const void * | buffer,
|  | gsize | count,
|  | gsize & | bytes_written |
| ) |  |  |

Tries to write count bytes from buffer into the stream.

Will block during the operation.

This function is similar to write(), except it tries to write as many bytes as requested, only stopping on an error.

On a successful write of count bytes, `true` is returned, and bytes_written is set to count .

If there is an error during the operation `false` is returned and error is set to indicate the error status, bytes_written is updated to contain the number of bytes written into the stream before the error occured.

Parameters:

  | buffer | The buffer containing the data to write.
  | count | The number of bytes to write.
  | bytes_written | Location to store the number of bytes that was written to the stream.

Returns:
  `true` on success, `false` if there was an error.

bool Gio::OutputStream::write_all | ( | const void * | buffer,
|  | gsize | count,
|  | gsize & | bytes_written,
|  | const Glib::RefPtr< Cancellable >& | cancellable |
| ) |  |  |

Tries to write count bytes from buffer into the stream.

Will block during the operation.

This function is similar to g_output_stream_write(), except it tries to write as many bytes as requested, only stopping on an error.

On a successful write of count bytes, `true` is returned, and bytes_written is set to count.

If there is an error during the operation `false` is returned and error is set to indicate the error status, bytes_written is updated to contain the number of bytes written into the stream before the error occurred.

Parameters:

  | buffer | The buffer containing the data to write.
  | count | The number of bytes to write.
  | bytes_written | Location to store the number of bytes that was written to the stream.
  | cancellable | Optional Cancellable object, `0` to ignore.

Returns:
  `true` on success, `false` if there was an error.

void Gio::OutputStream::write_async | ( | const void * | buffer,
|  | gsize | count,
|  | const SlotAsyncReady& | slot,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT` |
| ) |  |  |

Request an asynchronous write of count bytes from buffer into the stream.

When the operation is finished slot will be called. You can then call write_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with INVALID_ARGUMENT to be thrown.

On success, the number of bytes written will be passed to the callback slot. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, but generally we try to write as many bytes as requested.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is Glib::PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

For the synchronous, blocking version of this function, see write().

Parameters:

  | buffer | The buffer containing the data to write.
  | count | The number of bytes to write
  | slot | Callback slot to call when the request is satisfied.
  | io_priority | The io priority of the request.

void Gio::OutputStream::write_async | ( | const void * | buffer,
|  | gsize | count,
|  | const SlotAsyncReady& | slot,
|  | const Glib::RefPtr< Cancellable >& | cancellable,
|  | int | io_priority = `Glib::PRIORITY_DEFAULT` |
| ) |  |  |

Request an asynchronous write of count bytes from buffer into the stream.

When the operation is finished slot will be called. You can then call write_finish() to get the result of the operation.

During an async request no other sync and async calls are allowed, and will result in Gio::Error with PENDING being thrown.

A value of count larger than MAXSSIZE will cause a Gio::Error with NVALID_ARGUMENT to be thrown.

On success, the number of bytes written will be passed to the callback slot. It is not an error if this is not the same as the requested size, as it can happen e.g. on a partial I/O error, but generally we try to write as many bytes as requested.

Any outstanding I/O request with higher priority (lower numerical value) will be executed before an outstanding request with lower priority. Default priority is Glib::PRIORITY_DEFAULT.

The asyncronous methods have a default fallback that uses threads to implement asynchronicity, so they are optional for inheriting classes. However, if you override one you must override all.

For the synchronous, blocking version of this function, see write().

Parameters:

  | buffer | The buffer containing the data to write.
  | count | The number of bytes to write
  | slot | Callback slot to call when the request is satisfied.
  | cancellable | Cancellable object.
  | io_priority | The io priority of the request.

gssize Gio::OutputStream::write_finish | ( | const Glib::RefPtr< AsyncResult >& | result | ) |

Finishes a stream write operation.

Parameters:

  | result | A AsyncResult.

Returns:
  A gssize containing the number of bytes written to the stream.

## Friends And Related Function Documentation

Glib::RefPtr< Gio::OutputStream > wrap | ( | GOutputStream * | object,
|  | bool | take_copy = `false` |
| ) |  |  | `[related]`

A Glib::wrap() method for this object.

Parameters:

  | object | The C instance.
  | take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns:
  A C++ instance that wraps this C instance.

The documentation for this class was generated from the following file:

- giomm/outputstream.h