Class FileLoader
- All Implemented Interfaces:
Proxy
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).
-
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 GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new FileLoader.FileLoader(MemorySegment address) Create a FileLoader instance for the provided memory address.FileLoader(Buffer buffer, File file) Creates a newGtkSourceFileLoaderobject. -
Method Summary
Modifier and TypeMethodDescriptionprotected FileLoaderasParent()Return 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 MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the FileLoader class.voidloadAsync(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, Cancellable, FileProgressCallback, AsyncReadyCallback).voidsetCandidateEncodings(SList<Encoding> candidateEncodings) Sets the candidate encodings for the file loading.Methods inherited from class 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, 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 TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
FileLoader
Create a FileLoader instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
FileLoader
Creates a new
GtkSourceFileLoaderobject. The contents is read from theFile'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, thebufferis emptied.- Parameters:
buffer- theGtkSourceBufferto load the contents into.file- theGtkSourceFile.
-
FileLoader
public FileLoader()Create a new FileLoader.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Return this instance as if it were its parent type. Comparable to the Javasuperkeyword, but ensures the parent typeclass is also used in native code. -
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 the
Buffer.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 with
loadAsync(int, Cancellable, FileProgressCallback, 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):
- If set, the
File's encoding as returned byFile.getEncoding(). - The default candidates as returned by
Encoding.getDefaultCandidates().
- Parameters:
candidateEncodings- a list ofGtkSourceEncodings.
- If set, the
-
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
-