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
Nested ClassesModifier and TypeClassDescriptionstatic classFileLoader.Builder<B extends FileLoader.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new FileLoader.FileLoader(MemorySegment address) Create a FileLoader proxy instance for the provided memory address.FileLoader(Buffer buffer, File file) Creates a newGtkSourceFileLoaderobject. -
Method Summary
Modifier and TypeMethodDescriptionprotected FileLoaderasParent()Returns this instance as if it were its parent type.static FileLoader.Builder<? extends FileLoader.Builder> builder()AFileLoader.Builderobject constructs aFileLoaderwith the specified properties.static FileLoaderfromStream(Buffer buffer, File file, InputStream stream) Creates a newGtkSourceFileLoaderobject.getFile()@Nullable InputStream@Nullable Filestatic @Nullable TypegetType()Get the GType of the FileLoader classvoidloadAsync(int ioPriority, @Nullable Cancellable cancellable, @Nullable FileProgressCallback progressCallback, @Nullable AsyncReadyCallback callback) Loads asynchronously the file or input stream contents into theBuffer.booleanloadFinish(AsyncResult result) Finishes a file loading started withloadAsync(int, org.gnome.gio.Cancellable, org.gnome.gio.FileProgressCallback, org.gnome.gio.AsyncReadyCallback).voidsetCandidateEncodings(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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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 newGtkSourceFileLoaderobject. 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, thebufferis emptied.- Parameters:
buffer- theGtkSourceBufferto load the contents into.file- theGtkSourceFile.
-
FileLoader
public FileLoader()Creates a new FileLoader.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, 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 newGtkSourceFileLoaderobject. The contents is read fromstream.- Parameters:
buffer- theGtkSourceBufferto load the contents into.file- theGtkSourceFile.stream- theGInputStreamto load, e.g. stdin.- Returns:
- a new
GtkSourceFileLoaderobject.
-
getBuffer
-
getCompressionType
-
getEncoding
-
getFile
-
getInputStream
-
getLocation
-
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 theBuffer.See the
AsyncResultdocumentation to know how to use this function.- Parameters:
ioPriority- the I/O priority of the request. E.g.G_PRIORITY_LOW,G_PRIORITY_DEFAULTorG_PRIORITY_HIGH.cancellable- optionalGCancellableobject,nullto ignore.progressCallback- function to call back with progress information, ornullif progress information is not needed.callback- aGAsyncReadyCallbackto 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
Fileproperties 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,
candidateEncodingscan 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.Builderobject constructs aFileLoaderwith the specified properties. Use the variousset...()methods to set properties, and finish construction withFileLoader.Builder.build().- Returns:
- the builder object
-