Class FileLoader
- All Implemented Interfaces:
Proxy
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, org.gnome.gio.Cancellable, org.gnome.gio.FileProgressCallback, org.gnome.gio.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(boolean)
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(boolean)
with true
after calling
loadFinish(org.gnome.gio.AsyncResult)
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
FileLoader.Builder<B extends FileLoader.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionFileLoader
(MemorySegment address) Create a FileLoader proxy instance for the provided memory address.FileLoader
(Buffer buffer, File file) Creates a newGtkSourceFileLoader
object. -
Method Summary
Modifier and TypeMethodDescriptionprotected FileLoader
asParent()
Returns this instance as if it were its parent type.static FileLoader.Builder
<? extends FileLoader.Builder> builder()
AFileLoader.Builder
object constructs aFileLoader
with the specified properties.static FileLoader
fromStream
(Buffer buffer, File file, InputStream stream) Creates a newGtkSourceFileLoader
object.getFile()
static Type
getType()
Get the GType of the FileLoader classvoid
loadAsync
(int ioPriority, @Nullable Cancellable cancellable, @Nullable FileProgressCallback progressCallback, @Nullable AsyncReadyCallback callback) Loads asynchronously the file or input stream contents into theBuffer
.boolean
loadFinish
(AsyncResult result) Finishes a file loading started withloadAsync(int, org.gnome.gio.Cancellable, org.gnome.gio.FileProgressCallback, org.gnome.gio.AsyncReadyCallback)
.void
setCandidateEncodings
(SList<Encoding> candidateEncodings) Sets the candidate encodings for the file loading.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
FileLoader
Create a FileLoader proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
FileLoader
Creates a newGtkSourceFileLoader
object. The contents is read from theFile
's location.If not already done, call
File.setLocation(org.gnome.gio.File)
before calling this constructor. The previous location is anyway not needed, because as soon as the file loading begins, thebuffer
is emptied.- Parameters:
buffer
- theGtkSourceBuffer
to load the contents into.file
- theGtkSourceFile
.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, 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. -
fromStream
Creates a newGtkSourceFileLoader
object. The contents is read fromstream
.- Parameters:
buffer
- theGtkSourceBuffer
to load the contents into.file
- theGtkSourceFile
.stream
- theGInputStream
to load, e.g. stdin.- Returns:
- a new
GtkSourceFileLoader
object.
-
getBuffer
-
getCompressionType
-
getEncoding
-
getFile
-
getInputStream
-
getLocation
-
getNewlineType
-
loadAsync
public void loadAsync(int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable FileProgressCallback progressCallback, @Nullable @Nullable AsyncReadyCallback callback) Loads asynchronously the file or input stream contents into theBuffer
.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
orG_PRIORITY_HIGH
.cancellable
- optionalGCancellable
object,null
to ignore.progressCallback
- function to call back with progress information, ornull
if progress information is not needed.callback
- aGAsyncReadyCallback
to call when the request is satisfied.
-
loadFinish
Finishes a file loading started withloadAsync(int, org.gnome.gio.Cancellable, org.gnome.gio.FileProgressCallback, org.gnome.gio.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
- aGAsyncResult
.- Returns:
- whether the contents has been loaded successfully.
- Throws:
GErrorException
- seeGError
-
setCandidateEncodings
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 byFile.getEncoding()
. 2. The default candidates as returned byEncoding.getDefaultCandidates()
.- Parameters:
candidateEncodings
- a list ofGtkSourceEncoding
<!-- -->s.
-
builder
AFileLoader.Builder
object constructs aFileLoader
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withFileLoader.Builder.build()
.
-