Class MappedFile
- All Implemented Interfaces:
Proxy
GMappedFile
represents a file mapping created with
g_mapped_file_new(). It has only private members and should
not be accessed directly.-
Constructor Summary
ConstructorDescriptionMappedFile
(MemorySegment address) Create a MappedFile proxy instance for the provided memory address.MappedFile
(String filename, boolean writable) Maps a file into memory. -
Method Summary
Modifier and TypeMethodDescriptionvoid
free()
Deprecated.Use g_mapped_file_unref() instead.static MappedFile
fromFd
(int fd, boolean writable) Maps a file into memory.getBytes()
Creates a newGBytes
which references the data mapped from this MappedFile.Returns the contents of aGMappedFile
.long
Returns the length of the contents of aGMappedFile
.static Type
getType()
Get the GType of the MappedFile classref()
Increments the reference count of this MappedFile by one.void
unref()
Decrements the reference count of this MappedFile by one.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
MappedFile
Create a MappedFile proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
MappedFile
Maps a file into memory. On UNIX, this is using the mmap() function.If
writable
istrue
, the mapped buffer may be modified, otherwise it is an error to modify the mapped buffer. Modifications to the buffer are not visible to other processes mapping the same file, and are not written back to the file.Note that modifications of the underlying file might affect the contents of the
GMappedFile
. Therefore, mapping should only be used if the file will not be modified, or if all modifications of the file are done atomically (e.g. using g_file_set_contents()).If
filename
is the name of an empty, regular file, the function will successfully return an emptyGMappedFile
. In other cases of size 0 (e.g. device files such as /dev/null),error
will be set to theGFileError
valueFileError.INVAL
.- Parameters:
filename
- The path of the file to load, in the GLib filename encodingwritable
- whether the mapping should be writable- Throws:
GErrorException
- seeGError
-
-
Method Details
-
getType
-
fromFd
Maps a file into memory. On UNIX, this is using the mmap() function.If
writable
istrue
, the mapped buffer may be modified, otherwise it is an error to modify the mapped buffer. Modifications to the buffer are not visible to other processes mapping the same file, and are not written back to the file.Note that modifications of the underlying file might affect the contents of the
GMappedFile
. Therefore, mapping should only be used if the file will not be modified, or if all modifications of the file are done atomically (e.g. using g_file_set_contents()).- Parameters:
fd
- The file descriptor of the file to loadwritable
- whether the mapping should be writable- Returns:
- a newly allocated
GMappedFile
which must be unref'd with g_mapped_file_unref(), ornull
if the mapping failed. - Throws:
GErrorException
- seeGError
-
free
Deprecated.Use g_mapped_file_unref() instead.This call existed beforeGMappedFile
had refcounting and is currently exactly the same as g_mapped_file_unref(). -
getBytes
Creates a newGBytes
which references the data mapped from this MappedFile. The mapped contents of the file must not be modified after creating this bytes object, because aGBytes
should be immutable.- Returns:
- A newly allocated
GBytes
referencing data from this MappedFile
-
getContents
Returns the contents of aGMappedFile
.Note that the contents may not be zero-terminated, even if the
GMappedFile
is backed by a text file.If the file is empty then
null
is returned.- Returns:
- the contents of this MappedFile, or
null
.
-
getLength
public long getLength()Returns the length of the contents of aGMappedFile
.- Returns:
- the length of the contents of this MappedFile.
-
ref
Increments the reference count of this MappedFile by one. It is safe to call this function from any thread.- Returns:
- the passed in
GMappedFile
.
-
unref
public void unref()Decrements the reference count of this MappedFile by one. If the reference count drops to 0, unmaps the buffer of this MappedFile and frees it.It is safe to call this function from any thread.
Since 2.22
-