Class FileIOStream

All Implemented Interfaces:
AutoCloseable, Seekable, Proxy, AutoCloseable

@Generated("org.javagi.JavaGI") public class FileIOStream extends IOStream implements Seekable

GFileIOStream provides I/O streams that both read and write to the same file handle.

GFileIOStream implements Seekable, which allows the I/O 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 I/O stream, use Seekable.tell().

To find out if a file I/O stream supports seeking, use Seekable.canSeek(). To position a file I/O stream, use Seekable.seek(long, SeekType, Cancellable). To find out if a file I/O stream supports truncating, use Seekable.canTruncate(). To truncate a file I/O stream, use Seekable.truncate(long, Cancellable).

The default implementation of all the GFileIOStream operations and the implementation of Seekable just call into the same operations on the output stream.

Since:
2.22
  • Constructor Details

    • FileIOStream

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

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

    • getType

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

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

      protected FileIOStream 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 IOStream
      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.
      Since:
      2.22
    • queryInfo

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

      Queries a file io stream for the given attributes. This function blocks while querying the stream. For the asynchronous version of this function, see g_file_io_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). I 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
      Since:
      2.22
    • queryInfoAsync

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

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

      For the synchronous version of this function, see g_file_io_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 - a GAsyncReadyCallback to call when the request is satisfied
      Since:
      2.22
    • queryInfoFinish

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

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

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