Class OutputStream
- All Implemented Interfaces:
Proxy
,AutoCloseable
,AutoCloseable
- Direct Known Subclasses:
FileOutputStream
,FilterOutputStream
,MemoryOutputStream
,OutputStream.OutputStreamImpl
,PollableOutputStream.PollableOutputStreamImpl
,UnixOutputStream
,Win32OutputStream
GOutputStream
is a base class for implementing streaming output.
It has functions to write to a stream (write(byte[], org.gnome.gio.Cancellable)
),
to close a stream (close(org.gnome.gio.Cancellable)
) and to flush pending
writes (flush(org.gnome.gio.Cancellable)
).
To copy the content of an input stream to an output stream without
manually handling the reads and writes, use splice(org.gnome.gio.InputStream, java.util.Set<org.gnome.gio.OutputStreamSpliceFlags>, org.gnome.gio.Cancellable)
.
See the documentation for IOStream
for details of thread safety
of streaming APIs.
All of these functions have async variants too.
All classes derived from GOutputStream
should implement synchronous
writing, splicing, flushing and closing streams, but may implement
asynchronous versions.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
OutputStream.Builder<B extends OutputStream.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
static class
The OutputStreamImpl type represents a native instance of the abstract OutputStream class.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionOutputStream
(MemorySegment address) Create a OutputStream proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected OutputStream
asParent()
Returns this instance as if it were its parent type.static OutputStream.Builder
<? extends OutputStream.Builder> builder()
AOutputStream.Builder
object constructs aOutputStream
with the specified properties.void
Clears the pending flag on this OutputStream.boolean
close
(@Nullable Cancellable cancellable) Closes the stream, releasing resources related to it.void
closeAsync
(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Requests an asynchronous close of the stream, releasing resources related to it.boolean
closeFinish
(AsyncResult result) Closes an output stream.protected boolean
closeFn
(@Nullable Cancellable cancellable) boolean
flush
(@Nullable Cancellable cancellable) Forces a write of all user-space buffered data for the given this OutputStream.void
flushAsync
(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Forces an asynchronous write of all user-space buffered data for the given this OutputStream.boolean
flushFinish
(AsyncResult result) Finishes flushing an output stream.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the OutputStream classboolean
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
printf
(@Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable, GError[] error, String format, Object... varargs) This is a utility function around g_output_stream_write_all().boolean
Sets this OutputStream to have actions pending.long
splice
(InputStream source, Set<OutputStreamSpliceFlags> flags, @Nullable Cancellable cancellable) Splices an input stream into an output stream.long
splice
(InputStream source, OutputStreamSpliceFlags flags, @Nullable Cancellable cancellable) Splices an input stream into an output stream.void
spliceAsync
(InputStream source, Set<OutputStreamSpliceFlags> flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Splices a stream asynchronously.void
spliceAsync
(InputStream source, OutputStreamSpliceFlags flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Splices a stream asynchronously.long
spliceFinish
(AsyncResult result) Finishes an asynchronous stream splice operation.long
write
(byte[] buffer, @Nullable Cancellable cancellable) Tries to writecount
bytes frombuffer
into the stream.boolean
writeAll
(byte[] buffer, @Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable) Tries to writecount
bytes frombuffer
into the stream.void
writeAllAsync
(byte[] buffer, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write ofcount
bytes frombuffer
into the stream.boolean
writeAllFinish
(AsyncResult result, @Nullable Out<Long> bytesWritten) Finishes an asynchronous stream write operation started with g_output_stream_write_all_async().void
writeAsync
(byte[] buffer, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write ofcount
bytes frombuffer
into the stream.long
writeBytes
(Bytes bytes, @Nullable Cancellable cancellable) A wrapper function for g_output_stream_write() which takes aGBytes
as input.void
writeBytesAsync
(Bytes bytes, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) This function is similar to g_output_stream_write_async(), but takes aGBytes
as input.long
writeBytesFinish
(AsyncResult result) Finishes a stream write-from-GBytes
operation.long
writeFinish
(AsyncResult result) Finishes a stream write operation.boolean
writev
(OutputVector[] vectors, @Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable) Tries to write the bytes contained in thenVectors
vectors
into the stream.boolean
writevAll
(OutputVector[] vectors, @Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable) Tries to write the bytes contained in thenVectors
vectors
into the stream.void
writevAllAsync
(OutputVector[] vectors, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write of the bytes contained in thenVectors
vectors
into the stream.boolean
writevAllFinish
(AsyncResult result, @Nullable Out<Long> bytesWritten) Finishes an asynchronous stream write operation started with g_output_stream_writev_all_async().void
writevAsync
(OutputVector[] vectors, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write of the bytes contained innVectors
vectors
into the stream.boolean
writevFinish
(AsyncResult result, @Nullable Out<Long> bytesWritten) Finishes a stream writev operation.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.github.jwharm.javagi.gio.AutoCloseable
close
-
Constructor Details
-
OutputStream
Create a OutputStream proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
clearPending
public void clearPending()Clears the pending flag on this OutputStream. -
close
Closes the stream, releasing resources related to it.Once the stream is closed, all other operations will return
IOErrorEnum.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
IOErrorEnum.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 notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.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.- Specified by:
close
in interfaceAutoCloseable
- Parameters:
cancellable
- optional cancellable object- Returns:
true
on success,false
on failure- Throws:
GErrorException
- seeGError
-
closeAsync
public void closeAsync(int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finishedcallback
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:
ioPriority
- the io priority of the request.cancellable
- optional cancellable objectcallback
- aGAsyncReadyCallback
to call when the request is satisfied
-
closeFinish
Closes an output stream.- Parameters:
result
- aGAsyncResult
.- Returns:
true
if stream was successfully closed,false
otherwise.- Throws:
GErrorException
- seeGError
-
flush
Forces a write of all user-space buffered data for the given this OutputStream. Will block during the operation. Closing the stream will implicitly cause a flush.This function is optional for inherited classes.
If
cancellable
is notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLED
will be returned.- Parameters:
cancellable
- optional cancellable object- Returns:
true
on success,false
on error- Throws:
GErrorException
- seeGError
-
flushAsync
public void flushAsync(int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Forces an asynchronous write of all user-space buffered data for the given this OutputStream. 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:
ioPriority
- the io priority of the request.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
to call when the request is satisfied
-
flushFinish
Finishes flushing an output stream.- Parameters:
result
- a GAsyncResult.- Returns:
true
if flush operation succeeded,false
otherwise.- Throws:
GErrorException
- seeGError
-
hasPending
public boolean hasPending()Checks if an output stream has pending actions.- Returns:
true
if this OutputStream has pending actions.
-
isClosed
public boolean isClosed()Checks if an output stream has already been closed.- Returns:
true
if this OutputStream 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 this OutputStream is being closed.false
otherwise.
-
printf
public boolean printf(@Nullable @Nullable Out<Long> bytesWritten, @Nullable @Nullable Cancellable cancellable, GError[] error, String format, Object... varargs) This is a utility function around g_output_stream_write_all(). It uses g_strdup_vprintf() to turnformat
and.
.. into a string that is then written to this OutputStream.See the documentation of g_output_stream_write_all() about the behavior of the actual write operation.
Note that partial writes cannot be properly checked with this function due to the variable length of the written string, if you need precise control over partial write failures, you need to create you own printf()-like wrapper around g_output_stream_write() or g_output_stream_write_all().
- Parameters:
bytesWritten
- location to store the number of bytes that was written to the streamcancellable
- optionalGCancellable
object,null
to ignore.error
- location to store the error occurring, ornull
to ignoreformat
- the format string. See the printf() documentationvarargs
- the parameters to insert into the format string- Returns:
true
on success,false
if there was an error
-
setPending
Sets this OutputStream to have actions pending. If the pending flag is already set or this OutputStream is closed, it will returnfalse
and seterror
.- Returns:
true
if pending was previously unset and is now set.- Throws:
GErrorException
- seeGError
-
splice
public long splice(InputStream source, Set<OutputStreamSpliceFlags> flags, @Nullable @Nullable Cancellable cancellable) throws GErrorException Splices an input stream into an output stream.- Parameters:
source
- aGInputStream
.flags
- a set ofGOutputStreamSpliceFlags
.cancellable
- optionalGCancellable
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 thanG_MAXSSIZE
, then that will be returned, and there is no way to determine the actual number of bytes spliced. - Throws:
GErrorException
- seeGError
-
splice
public long splice(InputStream source, OutputStreamSpliceFlags flags, @Nullable @Nullable Cancellable cancellable) throws GErrorException Splices an input stream into an output stream.- Parameters:
source
- aGInputStream
.flags
- a set ofGOutputStreamSpliceFlags
.cancellable
- optionalGCancellable
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 thanG_MAXSSIZE
, then that will be returned, and there is no way to determine the actual number of bytes spliced. - Throws:
GErrorException
- seeGError
-
spliceAsync
public void spliceAsync(InputStream source, Set<OutputStreamSpliceFlags> flags, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Splices a stream asynchronously. When the operation is finishedcallback
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
- aGInputStream
.flags
- a set ofGOutputStreamSpliceFlags
.ioPriority
- the io priority of the request.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
to call when the request is satisfied
-
spliceAsync
public void spliceAsync(InputStream source, OutputStreamSpliceFlags flags, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Splices a stream asynchronously. When the operation is finishedcallback
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
- aGInputStream
.flags
- a set ofGOutputStreamSpliceFlags
.ioPriority
- the io priority of the request.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
to call when the request is satisfied
-
spliceFinish
Finishes an asynchronous stream splice operation.- Parameters:
result
- aGAsyncResult
.- Returns:
- a
gssize
of the number of bytes spliced. Note that if the number of bytes spliced is greater thanG_MAXSSIZE
, then that will be returned, and there is no way to determine the actual number of bytes spliced. - Throws:
GErrorException
- seeGError
-
write
public long write(byte[] buffer, @Nullable @Nullable Cancellable cancellable) throws GErrorException Tries to writecount
bytes frombuffer
into the stream. Will block during the operation.If count is 0, returns 0 and does nothing. A value of
count
larger thanG_MAXSSIZE
will cause aIOErrorEnum.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 notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.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.cancellable
- optional cancellable object- Returns:
- Number of bytes written, or -1 on error
- Throws:
GErrorException
- seeGError
-
writeAll
public boolean writeAll(byte[] buffer, @Nullable @Nullable Out<Long> bytesWritten, @Nullable @Nullable Cancellable cancellable) throws GErrorException Tries to writecount
bytes frombuffer
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, andbytesWritten
is set tocount
.If there is an error during the operation
false
is returned anderror
is set to indicate the error status.As a special exception to the normal conventions for functions that use
GError
, if this function returnsfalse
(and setserror
) thenbytesWritten
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.bytesWritten
- location to store the number of bytes that was written to the streamcancellable
- optionalGCancellable
object,null
to ignore.- Returns:
true
on success,false
if there was an error- Throws:
GErrorException
- seeGError
-
writeAllAsync
public void writeAllAsync(byte[] buffer, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Request an asynchronous write ofcount
bytes frombuffer
into the stream. When the operation is finishedcallback
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 untilcallback
is called.- Parameters:
buffer
- the buffer containing the data to writeioPriority
- the io priority of the requestcancellable
- optionalGCancellable
object,null
to ignorecallback
- aGAsyncReadyCallback
to call when the request is satisfied
-
writeAllFinish
public boolean writeAllFinish(AsyncResult result, @Nullable @Nullable Out<Long> bytesWritten) throws GErrorException 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 returnsfalse
(and setserror
) thenbytesWritten
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
- aGAsyncResult
bytesWritten
- location to store the number of bytes that was written to the stream- Returns:
true
on success,false
if there was an error- Throws:
GErrorException
- seeGError
-
writeAsync
public void writeAsync(byte[] buffer, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Request an asynchronous write ofcount
bytes frombuffer
into the stream. When the operation is finishedcallback
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
IOErrorEnum.PENDING
errors.A value of
count
larger thanG_MAXSSIZE
will cause aIOErrorEnum.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
IOErrorEnum.WOULD_BLOCK
- if this OutputStream 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 untilcallback
is called. See g_output_stream_write_bytes_async() for aGBytes
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.ioPriority
- the io priority of the request.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
to call when the request is satisfied
-
writeBytes
public long writeBytes(Bytes bytes, @Nullable @Nullable Cancellable cancellable) throws GErrorException A wrapper function for g_output_stream_write() which takes aGBytes
as input. This can be more convenient for use by language bindings or in other cases where the refcounted nature ofGBytes
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 sameGBytes
instance multiple times potentially can result in duplicated data in the output stream.- Parameters:
bytes
- theGBytes
to writecancellable
- optional cancellable object- Returns:
- Number of bytes written, or -1 on error
- Throws:
GErrorException
- seeGError
-
writeBytesAsync
public void writeBytesAsync(Bytes bytes, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) This function is similar to g_output_stream_write_async(), but takes aGBytes
as input. Due to the refcounted nature ofGBytes
, 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 sameGBytes
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 writeioPriority
- the io priority of the request.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
to call when the request is satisfied
-
writeBytesFinish
Finishes a stream write-from-GBytes
operation.- Parameters:
result
- aGAsyncResult
.- Returns:
- a
gssize
containing the number of bytes written to the stream. - Throws:
GErrorException
- seeGError
-
writeFinish
Finishes a stream write operation.- Parameters:
result
- aGAsyncResult
.- Returns:
- a
gssize
containing the number of bytes written to the stream. - Throws:
GErrorException
- seeGError
-
writev
public boolean writev(OutputVector[] vectors, @Nullable @Nullable Out<Long> bytesWritten, @Nullable @Nullable Cancellable cancellable) throws GErrorException Tries to write the bytes contained in thenVectors
vectors
into the stream. Will block during the operation.If
nVectors
is 0 or the sum of all bytes invectors
is 0, returns 0 and does nothing.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
nVectors
is 0 or the sum of all bytes invectors
is 0).If
cancellable
is notnull
, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLED
will be returned. If an operation was partially finished when the operation was cancelled the partial result will be returned, without an error.Some implementations of g_output_stream_writev() may have limitations on the aggregate buffer size, and will return
IOErrorEnum.INVALID_ARGUMENT
if these are exceeded. For example, when writing to a local file on UNIX platforms, the aggregate buffer size must not exceedG_MAXSSIZE
bytes.- Parameters:
vectors
- the buffer containing theGOutputVectors
to write.bytesWritten
- location to store the number of bytes that were written to the streamcancellable
- optional cancellable object- Returns:
true
on success,false
if there was an error- Throws:
GErrorException
- seeGError
-
writevAll
public boolean writevAll(OutputVector[] vectors, @Nullable @Nullable Out<Long> bytesWritten, @Nullable @Nullable Cancellable cancellable) throws GErrorException Tries to write the bytes contained in thenVectors
vectors
into the stream. Will block during the operation.This function is similar to g_output_stream_writev(), except it tries to write as many bytes as requested, only stopping on an error.
On a successful write of all
nVectors
vectors,true
is returned, andbytesWritten
is set to the sum of all the sizes ofvectors
.If there is an error during the operation
false
is returned anderror
is set to indicate the error status.As a special exception to the normal conventions for functions that use
GError
, if this function returnsfalse
(and setserror
) thenbytesWritten
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().The content of the individual elements of
vectors
might be changed by this function.- Parameters:
vectors
- the buffer containing theGOutputVectors
to write.bytesWritten
- location to store the number of bytes that were written to the streamcancellable
- optionalGCancellable
object,null
to ignore.- Returns:
true
on success,false
if there was an error- Throws:
GErrorException
- seeGError
-
writevAllAsync
public void writevAllAsync(OutputVector[] vectors, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Request an asynchronous write of the bytes contained in thenVectors
vectors
into the stream. When the operation is finishedcallback
will be called. You can then call g_output_stream_writev_all_finish() to get the result of the operation.This is the asynchronous version of g_output_stream_writev_all().
Call g_output_stream_writev_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
vectors
will be made, so it must stay valid untilcallback
is called. The content of the individual elements ofvectors
might be changed by this function.- Parameters:
vectors
- the buffer containing theGOutputVectors
to write.ioPriority
- the I/O priority of the requestcancellable
- optionalGCancellable
object,null
to ignorecallback
- aGAsyncReadyCallback
to call when the request is satisfied
-
writevAllFinish
public boolean writevAllFinish(AsyncResult result, @Nullable @Nullable Out<Long> bytesWritten) throws GErrorException 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 returnsfalse
(and setserror
) thenbytesWritten
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
- aGAsyncResult
bytesWritten
- location to store the number of bytes that were written to the stream- Returns:
true
on success,false
if there was an error- Throws:
GErrorException
- seeGError
-
writevAsync
public void writevAsync(OutputVector[] vectors, int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable AsyncReadyCallback callback) Request an asynchronous write of the bytes contained innVectors
vectors
into the stream. When the operation is finishedcallback
will be called. You can then call g_output_stream_writev_finish() to get the result of the operation.During an async request no other sync and async calls are allowed, and will result in
IOErrorEnum.PENDING
errors.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
IOErrorEnum.WOULD_BLOCK
— if this OutputStream 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_writev().
Note that no copy of
vectors
will be made, so it must stay valid untilcallback
is called.- Parameters:
vectors
- the buffer containing theGOutputVectors
to write.ioPriority
- the I/O priority of the request.cancellable
- optionalGCancellable
object,null
to ignore.callback
- aGAsyncReadyCallback
to call when the request is satisfied
-
writevFinish
public boolean writevFinish(AsyncResult result, @Nullable @Nullable Out<Long> bytesWritten) throws GErrorException Finishes a stream writev operation.- Parameters:
result
- aGAsyncResult
.bytesWritten
- location to store the number of bytes that were written to the stream- Returns:
true
on success,false
if there was an error- Throws:
GErrorException
- seeGError
-
closeFn
- Throws:
GErrorException
-
builder
AOutputStream.Builder
object constructs aOutputStream
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withOutputStream.Builder.build()
.
-