Class FileSaver
- All Implemented Interfaces:
Proxy
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, org.gnome.gio.Cancellable, org.gnome.gio.FileProgressCallback, org.gnome.gio.AsyncReadyCallback)
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
FileSaver.Builder<B extends FileSaver.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
ConstructorDescriptionFileSaver
(MemorySegment address) Create a FileSaver proxy instance for the provided memory address.Creates a newGtkSourceFileSaver
object. -
Method Summary
Modifier and TypeMethodDescriptionprotected FileSaver
asParent()
Returns this instance as if it were its parent type.static FileSaver.Builder
<? extends FileSaver.Builder> builder()
AFileSaver.Builder
object constructs aFileSaver
with the specified properties.getFile()
getFlags()
static Type
getType()
Get the GType of the FileSaver classvoid
saveAsync
(int ioPriority, @Nullable Cancellable cancellable, @Nullable FileProgressCallback progressCallback, @Nullable AsyncReadyCallback callback) Saves asynchronously the buffer into the file.boolean
saveFinish
(AsyncResult result) Finishes a file saving started withsaveAsync(int, org.gnome.gio.Cancellable, org.gnome.gio.FileProgressCallback, org.gnome.gio.AsyncReadyCallback)
.void
setCompressionType
(CompressionType compressionType) Sets the compression type.void
setEncoding
(@Nullable Encoding encoding) Sets the encoding.void
setFlags
(Set<FileSaverFlags> flags) void
setFlags
(FileSaverFlags... flags) void
setNewlineType
(NewlineType newlineType) Sets the newline type.static FileSaver
withTarget
(Buffer buffer, File file, File targetLocation) Creates a newGtkSourceFileSaver
object with a target location.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
-
FileSaver
Create a FileSaver proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
FileSaver
Creates a newGtkSourceFileSaver
object. Thebuffer
will be saved to theFile
's location.This constructor is suitable for a simple "save" operation, when the
file
already contains a non-null
File:location
.- Parameters:
buffer
- theGtkSourceBuffer
to save.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. -
withTarget
Creates a newGtkSourceFileSaver
object with a target location.When the file saving is finished successfully,
targetLocation
is set to thefile
'sFile:location
property. If an error occurs, the previous valid location is still available inFile
.This constructor is suitable for a "save as" operation, or for saving a new buffer for the first time.
- Parameters:
buffer
- theGtkSourceBuffer
to save.file
- theGtkSourceFile
.targetLocation
- theGFile
where to save the buffer to.- Returns:
- a new
GtkSourceFileSaver
object.
-
getBuffer
-
getCompressionType
-
getEncoding
-
getFile
-
getFlags
-
getLocation
-
getNewlineType
-
saveAsync
public void saveAsync(int ioPriority, @Nullable @Nullable Cancellable cancellable, @Nullable @Nullable FileProgressCallback progressCallback, @Nullable @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
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.
-
saveFinish
Finishes a file saving started withsaveAsync(int, org.gnome.gio.Cancellable, org.gnome.gio.FileProgressCallback, org.gnome.gio.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(boolean)
is called withfalse
if the file has been saved successfully.- Parameters:
result
- aGAsyncResult
.- Returns:
- whether the file was saved successfully.
- Throws:
GErrorException
- seeGError
-
setCompressionType
Sets the compression type. By default the compression type is taken from theGtkSourceFile
.- Parameters:
compressionType
- the new compression type.
-
setEncoding
Sets the encoding. Ifencoding
isnull
, the UTF-8 encoding will be set.By default the encoding is taken from the
GtkSourceFile
.- Parameters:
encoding
- the new encoding, ornull
for UTF-8.
-
setFlags
-
setFlags
-
setNewlineType
Sets the newline type. By default the newline type is taken from theGtkSourceFile
.- Parameters:
newlineType
- the new newline type.
-
builder
AFileSaver.Builder
object constructs aFileSaver
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withFileSaver.Builder.build()
.
-