Class FileSaver

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class FileSaver extends GObject

Save a Buffer into a file.

A GtkSourceFileSaver object permits to save a Buffer into a File.

A file saver should be used only for one save operation, including errors handling. If an error occurs, you can reconfigure the saver and relaunch the operation with saveAsync(int, Cancellable, FileProgressCallback, AsyncReadyCallback).

  • Constructor Details

    • FileSaver

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

      public FileSaver(Buffer buffer, File file)

      Creates a new GtkSourceFileSaver object. The buffer will be saved to the File's location.

      This constructor is suitable for a simple "save" operation, when the file already contains a non-null File:location.

      Parameters:
      buffer - the GtkSourceBuffer to save.
      file - the GtkSourceFile.
    • FileSaver

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

    • getType

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

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

      protected FileSaver 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 GObject
      Returns:
      the instance as if it were its parent type
    • withTarget

      public static FileSaver withTarget(Buffer buffer, File file, File targetLocation)

      Creates a new GtkSourceFileSaver object with a target location.

      When the file saving is finished successfully, targetLocation is set to the file's File:location property. If an error occurs, the previous valid location is still available in File.

      This constructor is suitable for a "save as" operation, or for saving a new buffer for the first time.

      Parameters:
      buffer - the GtkSourceBuffer to save.
      file - the GtkSourceFile.
      targetLocation - the GFile where to save the buffer to.
      Returns:
      a new GtkSourceFileSaver object.
    • getBuffer

      public Buffer getBuffer()
    • getCompressionType

      public CompressionType getCompressionType()
    • getEncoding

      public Encoding getEncoding()
    • getFile

      public File getFile()
    • getFlags

      public Set<FileSaverFlags> getFlags()
    • getLocation

      public File getLocation()
    • getNewlineType

      public NewlineType getNewlineType()
    • saveAsync

      public void saveAsync(int ioPriority, @Nullable Cancellable cancellable, @Nullable FileProgressCallback progressCallback, @Nullable AsyncReadyCallback callback)

      Saves asynchronously the buffer into the file.

      See the AsyncResult documentation to know how to use this function.

      Parameters:
      ioPriority - the I/O priority of the request. E.g. G_PRIORITY_LOW, G_PRIORITY_DEFAULT or G_PRIORITY_HIGH.
      cancellable - optional GCancellable object, null to ignore.
      progressCallback - function to call back with progress information, or null if progress information is not needed.
      callback - a GAsyncReadyCallback to call when the request is satisfied.
    • saveFinish

      public boolean saveFinish(AsyncResult result) throws GErrorException

      Finishes a file saving started with saveAsync(int, Cancellable, FileProgressCallback, AsyncReadyCallback).

      If the file has been saved successfully, the following File properties will be updated: the location, the encoding, the newline type and the compression type.

      Since the 3.20 version, TextBuffer#setModified is called with false if the file has been saved successfully.

      Parameters:
      result - a GAsyncResult.
      Returns:
      whether the file was saved successfully.
      Throws:
      GErrorException - see GError
    • setCompressionType

      public void setCompressionType(CompressionType compressionType)
      Sets the compression type. By default the compression type is taken from the GtkSourceFile.
      Parameters:
      compressionType - the new compression type.
    • setEncoding

      public void setEncoding(@Nullable Encoding encoding)

      Sets the encoding. If encoding is null, the UTF-8 encoding will be set.

      By default the encoding is taken from the GtkSourceFile.

      Parameters:
      encoding - the new encoding, or null for UTF-8.
    • setFlags

      public void setFlags(Set<FileSaverFlags> flags)
    • setFlags

      public void setFlags(FileSaverFlags... flags)
    • setNewlineType

      public void setNewlineType(NewlineType newlineType)
      Sets the newline type. By default the newline type is taken from the GtkSourceFile.
      Parameters:
      newlineType - the new newline type.
    • builder

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