Class FileLoader

All Implemented Interfaces:
Proxy

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

Load a file into a GtkSourceBuffer.

A GtkSourceFileLoader object permits to load the contents of a File or a InputStream into a Buffer.

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

Running a GtkSourceFileLoader is an undoable action for the Buffer.

After a file loading, the buffer is reset to the contents provided by the File or InputStream, so the buffer is set as “unmodified”, that is, TextBuffer#setModified is called with false. If the contents isn't saved somewhere (for example if you load from stdin), then you should probably call TextBuffer#setModified with true after calling loadFinish(AsyncResult).

  • Constructor Details

    • FileLoader

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

      public FileLoader(Buffer buffer, File file)

      Creates a new GtkSourceFileLoader object. The contents is read from the File's location.

      If not already done, call File.setLocation(File) before calling this constructor. The previous location is anyway not needed, because as soon as the file loading begins, the buffer is emptied.

      Parameters:
      buffer - the GtkSourceBuffer to load the contents into.
      file - the GtkSourceFile.
    • FileLoader

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

    • getType

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

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

      protected FileLoader 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
    • fromStream

      public static FileLoader fromStream(Buffer buffer, File file, InputStream stream)
      Creates a new GtkSourceFileLoader object. The contents is read from stream.
      Parameters:
      buffer - the GtkSourceBuffer to load the contents into.
      file - the GtkSourceFile.
      stream - the GInputStream to load, e.g. stdin.
      Returns:
      a new GtkSourceFileLoader object.
    • getBuffer

      public Buffer getBuffer()
    • getCompressionType

      public CompressionType getCompressionType()
    • getEncoding

      public Encoding getEncoding()
    • getFile

      public File getFile()
    • getInputStream

      public @Nullable InputStream getInputStream()
    • getLocation

      public @Nullable File getLocation()
    • getNewlineType

      public NewlineType getNewlineType()
    • loadAsync

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

      Loads asynchronously the file or input stream contents into the Buffer.

      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.
    • loadFinish

      public boolean loadFinish(AsyncResult result) throws GErrorException

      Finishes a file loading started with loadAsync(int, Cancellable, FileProgressCallback, AsyncReadyCallback).

      If the contents has been loaded, the following File properties will be updated: the location, the encoding, the newline type and the compression type.

      Parameters:
      result - a GAsyncResult.
      Returns:
      whether the contents has been loaded successfully.
      Throws:
      GErrorException - see GError
    • setCandidateEncodings

      public void setCandidateEncodings(SList<Encoding> candidateEncodings)

      Sets the candidate encodings for the file loading.

      The encodings are tried in the same order as the list.

      For convenience, candidateEncodings can contain duplicates. Only the first occurrence of a duplicated encoding is kept in the list.

      By default the candidate encodings are (in that order in the list):

      1. If set, the File's encoding as returned by File.getEncoding().
      2. The default candidates as returned by Encoding.getDefaultCandidates().
      Parameters:
      candidateEncodings - a list of GtkSourceEncodings.
    • builder

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