Package ch.bailu.gtk.gio
Class OutputStream
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gio.OutputStream
- All Implemented Interfaces:
PointerInterface
- Direct Known Subclasses:
FileOutputStream
,FilterOutputStream
,MemoryOutputStream
,UnixOutputStream
#GOutputStream has functions to write to a stream (g_output_stream_write()),
to close a stream (g_output_stream_close()) and to flush pending writes
(g_output_stream_flush()).
To copy the content of an input stream to an output stream without
manually handling the reads and writes, use g_output_stream_splice().
See the documentation for #GIOStream for details of thread safety of
streaming APIs.
All of these functions have async variants too.
to close a stream (g_output_stream_close()) and to flush pending writes
(g_output_stream_flush()).
To copy the content of an input stream to an output stream without
manually handling the reads and writes, use g_output_stream_splice().
See the documentation for #GIOStream for details of thread safety of
streaming APIs.
All of these functions have async variants too.
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the pending flag on @stream.boolean
close
(Cancellable cancellable) Closes the stream, releasing resources related to it.void
closeAsync
(int io_priority, Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, Pointer user_data) Requests an asynchronous close of the stream, releasing resources
related to it.boolean
closeFinish
(AsyncResult result) Closes an output stream.boolean
flush
(Cancellable cancellable) Forces a write of all user-space buffered data for the given
@stream.void
flushAsync
(int io_priority, Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, Pointer user_data) Forces an asynchronous write of all user-space buffered data for
the given @stream.boolean
flushFinish
(AsyncResult result) Finishes flushing an output stream.static ClassHandler
static int
static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
boolean
Checks if an output stream has pending actions.boolean
isClosed()
Checks if an output stream has already been closed.boolean
Checks if an output stream is being closed.boolean
Sets @stream to have actions pending.long
splice
(InputStream source, int flags, Cancellable cancellable) Splices an input stream into an output stream.void
spliceAsync
(InputStream source, int flags, int io_priority, Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, Pointer user_data) Splices a stream asynchronously.long
spliceFinish
(AsyncResult result) Finishes an asynchronous stream splice operation.long
write
(Pointer buffer, long count, Cancellable cancellable) Tries to write @count bytes from @buffer into the stream.boolean
writeAll
(Pointer buffer, long count, Int64 bytes_written, Cancellable cancellable) Tries to write @count bytes from @buffer into the stream.void
writeAllAsync
(Pointer buffer, long count, int io_priority, Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, Pointer user_data) Request an asynchronous write of @count bytes from @buffer into
the stream.boolean
writeAllFinish
(AsyncResult result, Int64 bytes_written) Finishes an asynchronous stream write operation started with
g_output_stream_write_all_async().void
writeAsync
(Pointer buffer, long count, int io_priority, Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, Pointer user_data) Request an asynchronous write of @count bytes from @buffer into
the stream.long
writeBytes
(Bytes bytes, Cancellable cancellable) A wrapper function for g_output_stream_write() which takes a
#GBytes as input.void
writeBytesAsync
(Bytes bytes, int io_priority, Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, Pointer user_data) This function is similar to g_output_stream_write_async(), but
takes a #GBytes as input.long
writeBytesFinish
(AsyncResult result) Finishes a stream write-from-#GBytes operation.long
writeFinish
(AsyncResult result) Finishes a stream write operation.boolean
writevAllFinish
(AsyncResult result, Int64 bytes_written) Finishes an asynchronous stream write operation started with
g_output_stream_writev_all_async().boolean
writevFinish
(AsyncResult result, Int64 bytes_written) Finishes a stream writev operation.Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
OutputStream
-
-
Method Details
-
getClassHandler
-
clearPending
public void clearPending()Clears the pending flag on @stream. -
close
Closes the stream, releasing resources related to it.
Once the stream is closed, all other operations will return %G_IO_ERROR_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 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 return %G_IO_ERROR_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.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
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
- Throws:
AllocationError
-
closeAsync
public void closeAsync(int io_priority, @Nullable Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Requests an asynchronous close of the stream, releasing resources
related to it. When the operation is finished @callback will be
called. You can then call g_output_stream_close_finish() to get
the result of the operation.
For behaviour details see g_output_stream_close().
The asynchronous 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:
io_priority
- the io priority of the request.cancellable
- optional cancellable objectcallback
- callback to call when the request is satisfieduser_data
- the data to pass to callback function
-
closeFinish
Closes an output stream.- Parameters:
result
- a #GAsyncResult.- Returns:
- %TRUE if stream was successfully closed, %FALSE otherwise.
- Throws:
AllocationError
-
flush
Forces a write of all user-space buffered data for the given
@stream. Will block during the operation. Closing the stream will
implicitly cause a flush.
This function is optional for inherited classes.
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.- Parameters:
cancellable
- optional cancellable object- Returns:
- %TRUE on success, %FALSE on error
- Throws:
AllocationError
-
flushAsync
public void flushAsync(int io_priority, @Nullable Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Forces an asynchronous write of all user-space buffered data for
the given @stream.
For behaviour details see g_output_stream_flush().
When the operation is finished @callback will be
called. You can then call g_output_stream_flush_finish() to get the
result of the operation.- Parameters:
io_priority
- the io priority of the request.cancellable
- optional #GCancellable object, %NULL to ignore.callback
- a #GAsyncReadyCallback to call when the request is satisfieduser_data
- the data to pass to callback function
-
flushFinish
Finishes flushing an output stream.- Parameters:
result
- a GAsyncResult.- Returns:
- %TRUE if flush operation succeeded, %FALSE otherwise.
- Throws:
AllocationError
-
hasPending
public boolean hasPending()Checks if an output stream has pending actions.- Returns:
- %TRUE if @stream has pending actions.
-
isClosed
public boolean isClosed()Checks if an output stream has already been closed.- Returns:
- %TRUE if @stream is closed. %FALSE otherwise.
-
isClosing
public boolean isClosing()Checks if an output stream is being closed. This can be
used inside e.g. a flush implementation to see if the
flush (or other i/o operation) is called from within
the closing operation.- Returns:
- %TRUE if @stream is being closed. %FALSE otherwise.
-
setPending
Sets @stream to have actions pending. If the pending flag is
already set or @stream is closed, it will return %FALSE and set
@error.- Returns:
- %TRUE if pending was previously unset and is now set.
- Throws:
AllocationError
-
splice
public long splice(@Nonnull InputStream source, int flags, @Nullable Cancellable cancellable) throws AllocationError Splices an input stream into an output stream.- Parameters:
source
- a #GInputStream.flags
- a set of #GOutputStreamSpliceFlags.cancellable
- optional #GCancellable object, %NULL to ignore.- Returns:
- a #gssize containing the size of the data spliced, or -1 if an error occurred. Note that if the number of bytes spliced is greater than %G_MAXSSIZE, then that will be returned, and there is no way to determine the actual number of bytes spliced.
- Throws:
AllocationError
-
spliceAsync
public void spliceAsync(@Nonnull InputStream source, int flags, int io_priority, @Nullable Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Splices a stream asynchronously.
When the operation is finished @callback will be called.
You can then call g_output_stream_splice_finish() to get the
result of the operation.
For the synchronous, blocking version of this function, see
g_output_stream_splice().- Parameters:
source
- a #GInputStream.flags
- a set of #GOutputStreamSpliceFlags.io_priority
- the io priority of the request.cancellable
- optional #GCancellable object, %NULL to ignore.callback
- a #GAsyncReadyCallback.user_data
- user data passed to @callback.
-
spliceFinish
Finishes an asynchronous stream splice operation.- Parameters:
result
- a #GAsyncResult.- Returns:
- a #gssize of the number of bytes spliced. Note that if the number of bytes spliced is greater than %G_MAXSSIZE, then that will be returned, and there is no way to determine the actual number of bytes spliced.
- Throws:
AllocationError
-
write
public long write(@Nonnull Pointer buffer, long count, @Nullable Cancellable cancellable) throws AllocationError Tries to write @count bytes from @buffer into the stream. Will block
during the operation.
If count is 0, returns 0 and does nothing. A value of @count
larger than %G_MAXSSIZE will cause a %G_IO_ERROR_INVALID_ARGUMENT error.
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 block until at least one byte
is written or an error occurs; 0 is never returned (unless
@count is 0).
If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
operation was partially finished when the operation was cancelled the
partial result will be returned, without an error.
On error -1 is returned and @error is set accordingly.- Parameters:
buffer
- the buffer containing the data to write.count
- the number of bytes to writecancellable
- optional cancellable object- Returns:
- Number of bytes written, or -1 on error
- Throws:
AllocationError
-
writeAll
public boolean writeAll(@Nonnull Pointer buffer, long count, @Nullable Int64 bytes_written, @Nullable Cancellable cancellable) throws AllocationError 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.
As a special exception to the normal conventions for functions that
use #GError, if this function returns %FALSE (and sets @error) then
@bytes_written will be set to the number of bytes that were
successfully written before the error was encountered. This
functionality is only available from C. If you need it from another
language then you must write your own loop around
g_output_stream_write().- Parameters:
buffer
- the buffer containing the data to write.count
- the number of bytes to writebytes_written
- location to store the number of bytes that was written to the streamcancellable
- optional #GCancellable object, %NULL to ignore.- Returns:
- %TRUE on success, %FALSE if there was an error
- Throws:
AllocationError
-
writeAllAsync
public void writeAllAsync(@Nonnull Pointer buffer, long count, int io_priority, @Nullable Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Request an asynchronous write of @count bytes from @buffer into
the stream. When the operation is finished @callback will be called.
You can then call g_output_stream_write_all_finish() to get the result of the
operation.
This is the asynchronous version of g_output_stream_write_all().
Call g_output_stream_write_all_finish() to collect the result.
Any outstanding I/O request with higher priority (lower numerical
value) will be executed before an outstanding request with lower
priority. Default priority is %G_PRIORITY_DEFAULT.
Note that no copy of @buffer will be made, so it must stay valid
until @callback is called.- Parameters:
buffer
- the buffer containing the data to writecount
- the number of bytes to writeio_priority
- the io priority of the requestcancellable
- optional #GCancellable object, %NULL to ignorecallback
- callback to call when the request is satisfieduser_data
- the data to pass to callback function
-
writeAllFinish
public boolean writeAllFinish(@Nonnull AsyncResult result, @Nullable Int64 bytes_written) throws AllocationError Finishes an asynchronous stream write operation started with
g_output_stream_write_all_async().
As a special exception to the normal conventions for functions that
use #GError, if this function returns %FALSE (and sets @error) then
@bytes_written will be set to the number of bytes that were
successfully written before the error was encountered. This
functionality is only available from C. If you need it from another
language then you must write your own loop around
g_output_stream_write_async().- Parameters:
result
- a #GAsyncResultbytes_written
- location to store the number of bytes that was written to the stream- Returns:
- %TRUE on success, %FALSE if there was an error
- Throws:
AllocationError
-
writeAsync
public void writeAsync(@Nonnull Pointer buffer, long count, int io_priority, @Nullable Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Request an asynchronous write of @count bytes from @buffer into
the stream. When the operation is finished @callback will be called.
You can then call g_output_stream_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 %G_IO_ERROR_PENDING errors.
A value of @count larger than %G_MAXSSIZE will cause a
%G_IO_ERROR_INVALID_ARGUMENT error.
On success, the number of bytes written will be passed to the
@callback. 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.
You are guaranteed that this method will never fail with
%G_IO_ERROR_WOULD_BLOCK - if @stream can't accept more data, the
method will just wait until this changes.
Any outstanding I/O request with higher priority (lower numerical
value) will be executed before an outstanding request with lower
priority. Default priority is %G_PRIORITY_DEFAULT.
The asynchronous 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
g_output_stream_write().
Note that no copy of @buffer will be made, so it must stay valid
until @callback is called. See g_output_stream_write_bytes_async()
for a #GBytes version that will automatically hold a reference to
the contents (without copying) for the duration of the call.- Parameters:
buffer
- the buffer containing the data to write.count
- the number of bytes to writeio_priority
- the io priority of the request.cancellable
- optional #GCancellable object, %NULL to ignore.callback
- callback to call when the request is satisfieduser_data
- the data to pass to callback function
-
writeBytes
public long writeBytes(@Nonnull Bytes bytes, @Nullable Cancellable cancellable) throws AllocationError A wrapper function for g_output_stream_write() which takes a
#GBytes as input. This can be more convenient for use by language
bindings or in other cases where the refcounted nature of #GBytes
is helpful over a bare pointer interface.
However, note that this function may still perform partial writes,
just like g_output_stream_write(). If that occurs, to continue
writing, you will need to create a new #GBytes containing just the
remaining bytes, using g_bytes_new_from_bytes(). Passing the same
#GBytes instance multiple times potentially can result in duplicated
data in the output stream.- Parameters:
bytes
- the #GBytes to writecancellable
- optional cancellable object- Returns:
- Number of bytes written, or -1 on error
- Throws:
AllocationError
-
writeBytesAsync
public void writeBytesAsync(@Nonnull Bytes bytes, int io_priority, @Nullable Cancellable cancellable, OutputStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data) This function is similar to g_output_stream_write_async(), but
takes a #GBytes as input. Due to the refcounted nature of #GBytes,
this allows the stream to avoid taking a copy of the data.
However, note that this function may still perform partial writes,
just like g_output_stream_write_async(). If that occurs, to continue
writing, you will need to create a new #GBytes containing just the
remaining bytes, using g_bytes_new_from_bytes(). Passing the same
#GBytes instance multiple times potentially can result in duplicated
data in the output stream.
For the synchronous, blocking version of this function, see
g_output_stream_write_bytes().- Parameters:
bytes
- The bytes to writeio_priority
- the io priority of the request.cancellable
- optional #GCancellable object, %NULL to ignore.callback
- callback to call when the request is satisfieduser_data
- the data to pass to callback function
-
writeBytesFinish
Finishes a stream write-from-#GBytes operation.- Parameters:
result
- a #GAsyncResult.- Returns:
- a #gssize containing the number of bytes written to the stream.
- Throws:
AllocationError
-
writeFinish
Finishes a stream write operation.- Parameters:
result
- a #GAsyncResult.- Returns:
- a #gssize containing the number of bytes written to the stream.
- Throws:
AllocationError
-
writevAllFinish
public boolean writevAllFinish(@Nonnull AsyncResult result, @Nullable Int64 bytes_written) throws AllocationError Finishes an asynchronous stream write operation started with
g_output_stream_writev_all_async().
As a special exception to the normal conventions for functions that
use #GError, if this function returns %FALSE (and sets @error) then
@bytes_written will be set to the number of bytes that were
successfully written before the error was encountered. This
functionality is only available from C. If you need it from another
language then you must write your own loop around
g_output_stream_writev_async().- Parameters:
result
- a #GAsyncResultbytes_written
- location to store the number of bytes that were written to the stream- Returns:
- %TRUE on success, %FALSE if there was an error
- Throws:
AllocationError
-
writevFinish
public boolean writevFinish(@Nonnull AsyncResult result, @Nullable Int64 bytes_written) throws AllocationError Finishes a stream writev operation.- Parameters:
result
- a #GAsyncResult.bytes_written
- location to store the number of bytes that were written to the stream- Returns:
- %TRUE on success, %FALSE if there was an error
- Throws:
AllocationError
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-