Class Checksum
- All Implemented Interfaces:
Proxy
To create a new GChecksum
, use Checksum(org.gnome.glib.ChecksumType)
. To free
a GChecksum
, use free()
.
GLib supports incremental checksums using the GChecksum
data
structure, by calling update(byte[])
as long as there’s data
available and then using getString()
or
getDigest(byte[])
to compute the checksum and return it
either as a string in hexadecimal form, or as a raw sequence of bytes. To
compute the checksum for binary blobs and nul-terminated strings in
one go, use the convenience functions GLib.computeChecksumForData(org.gnome.glib.ChecksumType, byte[])
and GLib.computeChecksumForString(org.gnome.glib.ChecksumType, java.lang.String, long)
, respectively.
-
Constructor Summary
ConstructorDescriptionChecksum
(MemorySegment address) Create a Checksum proxy instance for the provided memory address.Checksum
(ChecksumType checksumType) Creates a newGChecksum
, using the checksum algorithmchecksumType
. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Copies aGChecksum
.void
free()
Frees the memory allocated for this Checksum.void
getDigest
(byte[] buffer) Gets the digest from this Checksum as a raw binary vector and places it intobuffer
.Gets the digest as a hexadecimal string.static Type
getType()
Get the GType of the Checksum classvoid
reset()
Resets the state of the this Checksum back to its initial state.static long
typeGetLength
(ChecksumType checksumType) Gets the length in bytes of digests of typechecksumType
void
update
(byte[] data) Feedsdata
into an existingGChecksum
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Checksum
Create a Checksum proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Checksum
Creates a newGChecksum
, using the checksum algorithmchecksumType
. If thechecksumType
is not known,null
is returned. AGChecksum
can be used to compute the checksum, or digest, of an arbitrary binary blob, using different hashing algorithms.A
GChecksum
works by feeding a binary blob through g_checksum_update() until there is data to be checked; the digest can then be extracted using g_checksum_get_string(), which will return the checksum as a hexadecimal string; or g_checksum_get_digest(), which will return a vector of raw bytes. Once either g_checksum_get_string() or g_checksum_get_digest() have been called on aGChecksum
, the checksum will be closed and it won't be possible to call g_checksum_update() on it anymore.- Parameters:
checksumType
- the desired type of checksum
-
-
Method Details
-
getType
-
typeGetLength
Gets the length in bytes of digests of typechecksumType
- Parameters:
checksumType
- aGChecksumType
- Returns:
- the checksum length, or -1 if
checksumType
is not supported.
-
copy
Copies aGChecksum
. If this Checksum has been closed, by calling g_checksum_get_string() or g_checksum_get_digest(), the copied checksum will be closed as well.- Returns:
- the copy of the passed
GChecksum
. Use g_checksum_free() when finished using it.
-
free
public void free()Frees the memory allocated for this Checksum. -
getDigest
public void getDigest(byte[] buffer) Gets the digest from this Checksum as a raw binary vector and places it intobuffer
. The size of the digest depends on the type of checksum.Once this function has been called, the
GChecksum
is closed and can no longer be updated with g_checksum_update().- Parameters:
buffer
- output buffer
-
getString
Gets the digest as a hexadecimal string.Once this function has been called the
GChecksum
can no longer be updated with g_checksum_update().The hexadecimal characters will be lower case.
- Returns:
- the hexadecimal representation of the checksum. The returned string is owned by the checksum and should not be modified or freed.
-
reset
public void reset()Resets the state of the this Checksum back to its initial state. -
update
public void update(byte[] data) Feedsdata
into an existingGChecksum
. The checksum must still be open, that is g_checksum_get_string() or g_checksum_get_digest() must not have been called on this Checksum.- Parameters:
data
- buffer used to compute the checksum
-