Class OutputStream
- All Implemented Interfaces:
AutoCloseable,Proxy,AutoCloseable
- Direct Known Subclasses:
FileOutputStream,FilterOutputStream,MemoryOutputStream,OutputStream.OutputStream$Impl,PollableOutputStream.PollableOutputStream$Impl
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
Nested ClassesModifier and TypeClassDescriptionstatic classOutputStream.Builder<B extends OutputStream.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classThe OutputStream$Impl type represents a native instance of the abstract OutputStream class.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new OutputStream.OutputStream(MemorySegment address) Create a OutputStream proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected OutputStreamasParent()Returns this instance as if it were its parent type.voidClears the pending flag onstream.booleanclose(@Nullable Cancellable cancellable) Closes the stream, releasing resources related to it.voidcloseAsync(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Requests an asynchronous close of the stream, releasing resources related to it.booleancloseFinish(AsyncResult result) Closes an output stream.protected booleancloseFn(@Nullable Cancellable cancellable) booleanflush(@Nullable Cancellable cancellable) Forces a write of all user-space buffered data for the givenstream.Will block during the operation.voidflushAsync(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Forces an asynchronous write of all user-space buffered data for the givenstream.For behaviour details see g_output_stream_flush().booleanflushFinish(AsyncResult result) Finishes flushing an output stream.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the OutputStream classbooleanChecks if an output stream has pending actions.booleanisClosed()Checks if an output stream has already been closed.booleanChecks if an output stream is being closed.booleanprintf(@Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable, GError[] error, String format, Object... varargs) This is a utility function around g_output_stream_write_all().booleanSets this OutputStream to have actions pending.longsplice(InputStream source, Set<OutputStreamSpliceFlags> flags, @Nullable Cancellable cancellable) Splices an input stream into an output stream.longsplice(InputStream source, OutputStreamSpliceFlags flags, @Nullable Cancellable cancellable) Splices an input stream into an output stream.voidspliceAsync(InputStream source, Set<OutputStreamSpliceFlags> flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Splices a stream asynchronously.voidspliceAsync(InputStream source, OutputStreamSpliceFlags flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Splices a stream asynchronously.longspliceFinish(AsyncResult result) Finishes an asynchronous stream splice operation.longwrite(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, @Nullable Cancellable cancellable) Tries to writecountbytes frombufferinto the stream.booleanwriteAll(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, @Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable) Tries to writecountbytes frombufferinto the stream.voidwriteAllAsync(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write ofcountbytes frombufferinto the stream.booleanwriteAllFinish(AsyncResult result, @Nullable Out<Long> bytesWritten) Finishes an asynchronous stream write operation started with g_output_stream_write_all_async().voidwriteAsync(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write ofcountbytes frombufferinto the stream.longwriteBytes(byte[] bytes, @Nullable Cancellable cancellable) A wrapper function for g_output_stream_write() which takes aGBytesas input.voidwriteBytesAsync(byte[] bytes, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) This function is similar to g_output_stream_write_async(), but takes aGBytesas input.longwriteBytesFinish(AsyncResult result) Finishes a stream write-from-GBytesoperation.longwriteFinish(AsyncResult result) Finishes a stream write operation.booleanwritev(@Nullable OutputVector @Nullable [] vectors, @Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable) Tries to write the bytes contained in thenVectorsvectorsinto the stream.booleanwritevAll(@Nullable OutputVector @Nullable [] vectors, @Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable) Tries to write the bytes contained in thenVectorsvectorsinto the stream.voidwritevAllAsync(@Nullable OutputVector @Nullable [] vectors, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write of the bytes contained in thenVectorsvectorsinto the stream.booleanwritevAllFinish(AsyncResult result, @Nullable Out<Long> bytesWritten) Finishes an asynchronous stream write operation started with g_output_stream_writev_all_async().voidwritevAsync(@Nullable OutputVector @Nullable [] vectors, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write of the bytes contained innVectorsvectorsinto the stream.booleanwritevFinish(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, builder, 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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.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
-
OutputStream
public OutputStream()Creates a new OutputStream.
-
-
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 Javasuperkeyword, 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 onstream. -
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.CLOSEDfor 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
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill 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:
closein interfaceAutoCloseable- Parameters:
cancellable- optional cancellable object- Returns:
trueon success,falseon failure- Throws:
GErrorException- seeGError
-
closeAsync
public void closeAsync(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Requests an asynchronous close of the stream, releasing resources related to it. When the operation is finishedcallbackwill 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- aGAsyncReadyCallbackto call when the request is satisfied
-
closeFinish
Closes an output stream.- Parameters:
result- aGAsyncResult.- Returns:
trueif stream was successfully closed,falseotherwise.- Throws:
GErrorException- seeGError
-
flush
Forces a write of all user-space buffered data for the givenstream.Will block during the operation. Closing the stream will implicitly cause a flush.This function is optional for inherited classes.
If
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill be returned.- Parameters:
cancellable- optional cancellable object- Returns:
trueon success,falseon error- Throws:
GErrorException- seeGError
-
flushAsync
public void flushAsync(int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Forces an asynchronous write of all user-space buffered data for the givenstream.For behaviour details see g_output_stream_flush().When the operation is finished
callbackwill 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- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallbackto call when the request is satisfied
-
flushFinish
Finishes flushing an output stream.- Parameters:
result- a GAsyncResult.- Returns:
trueif flush operation succeeded,falseotherwise.- Throws:
GErrorException- seeGError
-
hasPending
public boolean hasPending()Checks if an output stream has pending actions.- Returns:
trueif this OutputStream has pending actions.
-
isClosed
public boolean isClosed()Checks if an output stream has already been closed.- Returns:
trueif this OutputStream is closed.falseotherwise.
-
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:
trueif this OutputStream is being closed.falseotherwise.- Since:
- 2.24
-
printf
public 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(). It uses g_strdup_vprintf() to turnformatand...into a string that is then written tostream.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- optionalGCancellableobject,nullto ignore.error- location to store the error occurring, ornullto ignoreformat- the format string. See the printf() documentationvarargs- the parameters to insert into the format string- Returns:
trueon success,falseif there was an error- Since:
- 2.40
-
setPending
Sets this OutputStream to have actions pending. If the pending flag is already set or this OutputStream is closed, it will returnfalseand seterror.- Returns:
trueif pending was previously unset and is now set.- Throws:
GErrorException- seeGError
-
splice
public long splice(InputStream source, Set<OutputStreamSpliceFlags> flags, @Nullable Cancellable cancellable) throws GErrorException Splices an input stream into an output stream.- Parameters:
source- aGInputStream.flags- a set ofGOutputStreamSpliceFlags.cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- a
gssizecontaining 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 Cancellable cancellable) throws GErrorException Splices an input stream into an output stream.- Parameters:
source- aGInputStream.flags- a set ofGOutputStreamSpliceFlags.cancellable- optionalGCancellableobject,nullto ignore.- Returns:
- a
gssizecontaining 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 Cancellable cancellable, @Nullable AsyncReadyCallback callback) Splices a stream asynchronously. When the operation is finishedcallbackwill 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- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallbackto call when the request is satisfied
-
spliceAsync
public void spliceAsync(InputStream source, OutputStreamSpliceFlags flags, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Splices a stream asynchronously. When the operation is finishedcallbackwill 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- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallbackto call when the request is satisfied
-
spliceFinish
Finishes an asynchronous stream splice operation.- Parameters:
result- aGAsyncResult.- Returns:
- a
gssizeof 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(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, @Nullable Cancellable cancellable) throws GErrorException Tries to writecountbytes frombufferinto the stream. Will block during the operation.If count is 0, returns 0 and does nothing. A value of
countlarger thanG_MAXSSIZEwill cause aIOErrorEnum.INVALID_ARGUMENTerror.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
countis 0).If
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill 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
erroris 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(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, @Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable) throws GErrorException Tries to writecountbytes frombufferinto 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
countbytes,trueis returned, andbytesWrittenis set tocount.If there is an error during the operation
falseis returned anderroris 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)thenbytesWrittenwill 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- optionalGCancellableobject,nullto ignore.- Returns:
trueon success,falseif there was an error- Throws:
GErrorException- seeGError
-
writeAllAsync
public void writeAllAsync(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write ofcountbytes frombufferinto the stream. When the operation is finishedcallbackwill 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
bufferwill be made, so it must stay valid untilcallbackis called.- Parameters:
buffer- the buffer containing the data to writeioPriority- the io priority of the requestcancellable- optionalGCancellableobject,nullto ignorecallback- aGAsyncReadyCallbackto call when the request is satisfied- Since:
- 2.44
-
writeAllFinish
public boolean writeAllFinish(AsyncResult result, @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)thenbytesWrittenwill 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- aGAsyncResultbytesWritten- location to store the number of bytes that was written to the stream- Returns:
trueon success,falseif there was an error- Throws:
GErrorException- seeGError- Since:
- 2.44
-
writeAsync
public void writeAsync(@org.jspecify.annotations.Nullable byte @Nullable [] buffer, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write ofcountbytes frombufferinto the stream. When the operation is finishedcallbackwill 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.PENDINGerrors.A value of
countlarger thanG_MAXSSIZEwill cause aIOErrorEnum.INVALID_ARGUMENTerror.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
bufferwill be made, so it must stay valid untilcallbackis called. See g_output_stream_write_bytes_async() for aGBytesversion 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- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallbackto call when the request is satisfied
-
writeBytes
A wrapper function for g_output_stream_write() which takes aGBytesas input. This can be more convenient for use by language bindings or in other cases where the refcounted nature ofGBytesis 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
GBytescontaining just the remaining bytes, using g_bytes_new_from_bytes(). Passing the sameGBytesinstance multiple times potentially can result in duplicated data in the output stream.- Parameters:
bytes- theGBytesto writecancellable- optional cancellable object- Returns:
- Number of bytes written, or -1 on error
- Throws:
GErrorException- seeGError
-
writeBytesAsync
public void writeBytesAsync(byte[] bytes, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) This function is similar to g_output_stream_write_async(), but takes aGBytesas 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
GBytescontaining just the remaining bytes, using g_bytes_new_from_bytes(). Passing the sameGBytesinstance 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- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallbackto call when the request is satisfied
-
writeBytesFinish
Finishes a stream write-from-GBytesoperation.- Parameters:
result- aGAsyncResult.- Returns:
- a
gssizecontaining the number of bytes written to the stream. - Throws:
GErrorException- seeGError
-
writeFinish
Finishes a stream write operation.- Parameters:
result- aGAsyncResult.- Returns:
- a
gssizecontaining the number of bytes written to the stream. - Throws:
GErrorException- seeGError
-
writev
public boolean writev(@Nullable OutputVector @Nullable [] vectors, @Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable) throws GErrorException Tries to write the bytes contained in thenVectorsvectorsinto the stream. Will block during the operation.If
nVectorsis 0 or the sum of all bytes invectorsis 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
nVectorsis 0 or the sum of all bytes invectorsis 0).If
cancellableis notnull, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the errorIOErrorEnum.CANCELLEDwill 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_ARGUMENTif these are exceeded. For example, when writing to a local file on UNIX platforms, the aggregate buffer size must not exceedG_MAXSSIZEbytes.- Parameters:
vectors- the buffer containing theGOutputVectorsto write.bytesWritten- location to store the number of bytes that were written to the streamcancellable- optional cancellable object- Returns:
trueon success,falseif there was an error- Throws:
GErrorException- seeGError- Since:
- 2.60
-
writevAll
public boolean writevAll(@Nullable OutputVector @Nullable [] vectors, @Nullable Out<Long> bytesWritten, @Nullable Cancellable cancellable) throws GErrorException Tries to write the bytes contained in thenVectorsvectorsinto 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
nVectorsvectors,trueis returned, andbytesWrittenis set to the sum of all the sizes ofvectors.If there is an error during the operation
falseis returned anderroris 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)thenbytesWrittenwill 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
vectorsmight be changed by this function.- Parameters:
vectors- the buffer containing theGOutputVectorsto write.bytesWritten- location to store the number of bytes that were written to the streamcancellable- optionalGCancellableobject,nullto ignore.- Returns:
trueon success,falseif there was an error- Throws:
GErrorException- seeGError- Since:
- 2.60
-
writevAllAsync
public void writevAllAsync(@Nullable OutputVector @Nullable [] vectors, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write of the bytes contained in thenVectorsvectorsinto the stream. When the operation is finishedcallbackwill 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
vectorswill be made, so it must stay valid untilcallbackis called. The content of the individual elements ofvectorsmight be changed by this function.- Parameters:
vectors- the buffer containing theGOutputVectorsto write.ioPriority- the I/O priority of the requestcancellable- optionalGCancellableobject,nullto ignorecallback- aGAsyncReadyCallbackto call when the request is satisfied- Since:
- 2.60
-
writevAllFinish
public boolean writevAllFinish(AsyncResult result, @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)thenbytesWrittenwill 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- aGAsyncResultbytesWritten- location to store the number of bytes that were written to the stream- Returns:
trueon success,falseif there was an error- Throws:
GErrorException- seeGError- Since:
- 2.60
-
writevAsync
public void writevAsync(@Nullable OutputVector @Nullable [] vectors, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback) Request an asynchronous write of the bytes contained innVectorsvectorsinto the stream. When the operation is finishedcallbackwill 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.PENDINGerrors.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
vectorswill be made, so it must stay valid untilcallbackis called.- Parameters:
vectors- the buffer containing theGOutputVectorsto write.ioPriority- the I/O priority of the request.cancellable- optionalGCancellableobject,nullto ignore.callback- aGAsyncReadyCallbackto call when the request is satisfied- Since:
- 2.60
-
writevFinish
public boolean writevFinish(AsyncResult result, @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:
trueon success,falseif there was an error- Throws:
GErrorException- seeGError- Since:
- 2.60
-
closeFn
- Throws:
GErrorException
-