Package ch.bailu.gtk.gio
Class IOStream
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.gio.IOStream
- All Implemented Interfaces:
PointerInterface
- Direct Known Subclasses:
FileIOStream
,SimpleIOStream
,SocketConnection
,TlsConnection
GIOStream represents an object that has both read and write streams.
Generally the two streams act as separate input and output streams,
but they share some common resources and state. For instance, for
seekable streams, both streams may use the same position.
Examples of #GIOStream objects are #GSocketConnection, which represents
a two-way network connection; and #GFileIOStream, which represents a
file handle opened in read-write mode.
To do the actual reading and writing you need to get the substreams
with g_io_stream_get_input_stream() and g_io_stream_get_output_stream().
The #GIOStream object owns the input and the output streams, not the other
way around, so keeping the substreams alive will not keep the #GIOStream
object alive. If the #GIOStream object is freed it will be closed, thus
closing the substreams, so even if the substreams stay alive they will
always return %G_IO_ERROR_CLOSED for all operations.
To close a stream use g_io_stream_close() which will close the common
stream object and also the individual substreams. You can also close
the substreams themselves. In most cases this only marks the
substream as closed, so further I/O on it fails but common state in the
#GIOStream may still be open. However, some streams may support
"half-closed" states where one direction of the stream is actually shut down.
Operations on #GIOStreams cannot be started while another operation on the
#GIOStream or its substreams is in progress. Specifically, an application can
read from the #GInputStream and write to the #GOutputStream simultaneously
(either in separate threads, or as asynchronous operations in the same
thread), but an application cannot start any #GIOStream operation while there
is a #GIOStream, #GInputStream or #GOutputStream operation in progress, and
an application can’t start any #GInputStream or #GOutputStream operation
while there is a #GIOStream operation in progress.
This is a product of individual stream operations being associated with a
given #GMainContext (the thread-default context at the time the operation was
started), rather than entire streams being associated with a single
#GMainContext.
GIO may run operations on #GIOStreams from other (worker) threads, and this
may be exposed to application code in the behaviour of wrapper streams, such
as #GBufferedInputStream or #GTlsConnection. With such wrapper APIs,
application code may only run operations on the base (wrapped) stream when
the wrapper stream is idle. Note that the semantics of such operations may
not be well-defined due to the state the wrapper stream leaves the base
stream in (though they are guaranteed not to crash).
Generally the two streams act as separate input and output streams,
but they share some common resources and state. For instance, for
seekable streams, both streams may use the same position.
Examples of #GIOStream objects are #GSocketConnection, which represents
a two-way network connection; and #GFileIOStream, which represents a
file handle opened in read-write mode.
To do the actual reading and writing you need to get the substreams
with g_io_stream_get_input_stream() and g_io_stream_get_output_stream().
The #GIOStream object owns the input and the output streams, not the other
way around, so keeping the substreams alive will not keep the #GIOStream
object alive. If the #GIOStream object is freed it will be closed, thus
closing the substreams, so even if the substreams stay alive they will
always return %G_IO_ERROR_CLOSED for all operations.
To close a stream use g_io_stream_close() which will close the common
stream object and also the individual substreams. You can also close
the substreams themselves. In most cases this only marks the
substream as closed, so further I/O on it fails but common state in the
#GIOStream may still be open. However, some streams may support
"half-closed" states where one direction of the stream is actually shut down.
Operations on #GIOStreams cannot be started while another operation on the
#GIOStream or its substreams is in progress. Specifically, an application can
read from the #GInputStream and write to the #GOutputStream simultaneously
(either in separate threads, or as asynchronous operations in the same
thread), but an application cannot start any #GIOStream operation while there
is a #GIOStream, #GInputStream or #GOutputStream operation in progress, and
an application can’t start any #GInputStream or #GOutputStream operation
while there is a #GIOStream operation in progress.
This is a product of individual stream operations being associated with a
given #GMainContext (the thread-default context at the time the operation was
started), rather than entire streams being associated with a single
#GMainContext.
GIO may run operations on #GIOStreams from other (worker) threads, and this
may be exposed to application code in the behaviour of wrapper streams, such
as #GBufferedInputStream or #GTlsConnection. With such wrapper APIs,
application code may only run operations on the base (wrapped) stream when
the wrapper stream is idle. Note that the semantics of such operations may
not be well-defined due to the state the wrapper stream leaves the base
stream in (though they are guaranteed not to crash).
-
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, IOStream.OnAsyncReadyCallback callback, Pointer user_data) Requests an asynchronous close of the stream, releasing resources
related to it.boolean
closeFinish
(AsyncResult result) Closes a stream.static ClassHandler
Gets the input stream for this object.static int
Gets the output stream for this object.static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
boolean
Checks if a stream has pending actions.boolean
isClosed()
Checks if a stream is closed.boolean
Sets @stream to have actions pending.void
spliceAsync
(IOStream stream2, int flags, int io_priority, Cancellable cancellable, IOStream.OnAsyncReadyCallback callback, Pointer user_data) Asynchronously splice the output stream of @stream1 to the input stream of
@stream2, and splice the output stream of @stream2 to the input stream of
@stream1.static boolean
spliceFinish
(AsyncResult result) Finishes an asynchronous io stream splice 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
-
IOStream
-
-
Method Details
-
getClassHandler
-
clearPending
public void clearPending()Clears the pending flag on @stream. -
close
Closes the stream, releasing resources related to it. This will also
close the individual input and output streams, if they are not already
closed.
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 some streams
can use a faster close that doesn't block to e.g. check errors.
The default implementation of this method just calls close on the
individual input/output streams.- Parameters:
cancellable
- optional #GCancellable object, %NULL to ignore- Returns:
- %TRUE on success, %FALSE on failure
- Throws:
AllocationError
-
closeAsync
public void closeAsync(int io_priority, @Nullable Cancellable cancellable, IOStream.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_io_stream_close_finish() to get
the result of the operation.
For behaviour details see g_io_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 requestcancellable
- optional cancellable objectcallback
- callback to call when the request is satisfieduser_data
- the data to pass to callback function
-
closeFinish
Closes a stream.- Parameters:
result
- a #GAsyncResult- Returns:
- %TRUE if stream was successfully closed, %FALSE otherwise.
- Throws:
AllocationError
-
getInputStream
Gets the input stream for this object. This is used
for reading.- Returns:
- a #GInputStream, owned by the #GIOStream. Do not free.
-
getOutputStream
Gets the output stream for this object. This is used for
writing.- Returns:
- a #GOutputStream, owned by the #GIOStream. Do not free.
-
hasPending
public boolean hasPending()Checks if a stream has pending actions.- Returns:
- %TRUE if @stream has pending actions.
-
isClosed
public boolean isClosed()Checks if a stream is closed.- Returns:
- %TRUE if the stream is closed.
-
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
-
spliceAsync
public void spliceAsync(@Nonnull IOStream stream2, int flags, int io_priority, @Nullable Cancellable cancellable, IOStream.OnAsyncReadyCallback callback, @Nullable Pointer user_data) Asynchronously splice the output stream of @stream1 to the input stream of
@stream2, and splice the output stream of @stream2 to the input stream of
@stream1.
When the operation is finished @callback will be called.
You can then call g_io_stream_splice_finish() to get the
result of the operation.- Parameters:
stream2
- a #GIOStream.flags
- a set of #GIOStreamSpliceFlags.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 io stream splice operation.- Parameters:
result
- a #GAsyncResult.- Returns:
- %TRUE on success, %FALSE otherwise.
- Throws:
AllocationError
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-