Class FileOutputStream

All Implemented Interfaces:
AutoCloseable, Seekable, Proxy, AutoCloseable

@Generated("org.javagi.JavaGI") public class FileOutputStream extends OutputStream implements Seekable

GFileOutputStream provides output streams that write their content to a file.

GFileOutputStream implements Seekable, which allows the output stream to jump to arbitrary positions in the file and to truncate the file, provided the filesystem of the file supports these operations.

To find the position of a file output stream, use Seekable.tell(). To find out if a file output stream supports seeking, use Seekable.canSeek().To position a file output stream, use Seekable.seek(long, SeekType, Cancellable). To find out if a file output stream supports truncating, use Seekable.canTruncate(). To truncate a file output stream, use Seekable.truncate(long, Cancellable).

  • Constructor Details

    • FileOutputStream

      public FileOutputStream(MemorySegment address)
      Create a FileOutputStream instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • FileOutputStream

      public FileOutputStream()
      Create a new FileOutputStream.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the FileOutputStream class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected FileOutputStream asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class OutputStream
      Returns:
      the instance as if it were its parent type
    • getEtag

      public @Nullable String getEtag()
      Gets the entity tag for the file when it has been written. This must be called after the stream has been written and closed, as the etag can change while writing.
      Returns:
      the entity tag for the stream.
    • queryInfo

      public FileInfo queryInfo(String attributes, @Nullable Cancellable cancellable) throws GErrorException

      Queries a file output stream for the given attributes. This function blocks while querying the stream. For the asynchronous version of this function, see g_file_output_stream_query_info_async(). While the stream is blocked, the stream will set the pending flag internally, and any other operations on the stream will fail with IOErrorEnum.PENDING.

      Can fail if the stream was already closed (with error being set to IOErrorEnum.CLOSED), the stream has pending operations (with error being set to IOErrorEnum.PENDING), or if querying info is not supported for the stream's interface (with error being set to IOErrorEnum.NOT_SUPPORTED). In all cases of failure, null will be returned.

      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 IOErrorEnum.CANCELLED will be set, and null will be returned.

      Parameters:
      attributes - a file attribute query string.
      cancellable - optional GCancellable object, null to ignore.
      Returns:
      a GFileInfo for the stream, or null on error.
      Throws:
      GErrorException - see GError
    • queryInfoAsync

      public void queryInfoAsync(String attributes, int ioPriority, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Asynchronously queries the this FileOutputStream for a GFileInfo. When completed, callback will be called with a GAsyncResult which can be used to finish the operation with g_file_output_stream_query_info_finish().

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

      Parameters:
      attributes - a file attribute query string.
      ioPriority - the I/O priority of the request
      cancellable - optional GCancellable object, null to ignore.
      callback - callback to call when the request is satisfied
    • queryInfoFinish

      public FileInfo queryInfoFinish(AsyncResult result) throws GErrorException
      Finalizes the asynchronous query started by g_file_output_stream_query_info_async().
      Parameters:
      result - a GAsyncResult.
      Returns:
      A GFileInfo for the finished query.
      Throws:
      GErrorException - see GError
    • truncateFn

      protected boolean truncateFn(long size, @Nullable Cancellable cancellable) throws GErrorException
      Throws:
      GErrorException
    • builder

      public static FileOutputStream.Builder<? extends FileOutputStream.Builder> builder()
      A FileOutputStream.Builder object constructs a FileOutputStream with the specified properties. Use the various set...() methods to set properties, and finish construction with FileOutputStream.Builder.build().
      Returns:
      the builder object