public final class CTypeConversion extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
CTypeConversion.CCharPointerHolder
An auto-closable that holds a Java
CharSequence as a null-terminated C char[] array. |
static class |
CTypeConversion.CCharPointerPointerHolder
An auto-closable that holds a Java
CharSequence [] array as a null-terminated array of
null-terminated C char[]s. |
Modifier and Type | Method and Description |
---|---|
static ByteBuffer |
asByteBuffer(PointerBase address,
int size)
Creates a
ByteBuffer that refers to the native memory at the specified address. |
static boolean |
toBoolean(int value)
Converts a C int containing boolean values into a Java boolean.
|
static boolean |
toBoolean(PointerBase pointer)
Converts a C pointer into a Java boolean.
|
static byte |
toCBoolean(boolean value)
Converts a Java boolean into a C int containing boolean values.
|
static CTypeConversion.CCharPointerHolder |
toCBytes(byte[] bytes)
Provides access to a C pointer for the provided Java byte array.
|
static CTypeConversion.CCharPointerHolder |
toCString(CharSequence javaString)
Provides access to a C pointer for the provided Java String, encoded with the default
charset.
|
static UnsignedWord |
toCString(CharSequence javaString,
CCharPointer buffer,
UnsignedWord bufferSize)
Copies the
javaString into the buffer as a 0 terminated C string encoded with the
default character set. |
static UnsignedWord |
toCString(CharSequence javaString,
Charset charset,
CCharPointer buffer,
UnsignedWord bufferSize)
Copies the
javaString into the buffer as a 0 terminated C string encoded with the
charset character set. |
static CTypeConversion.CCharPointerPointerHolder |
toCStrings(CharSequence[] javaStrings)
Provides access to C pointers for the provided Java Strings, encoded with the default
charset.
|
static String |
toJavaString(CCharPointer cString)
Decodes a 0 terminated C
char* to a Java string using the platform's default charset. |
static String |
toJavaString(CCharPointer cString,
UnsignedWord length)
Decodes a C
char* of length length to a Java string using the platform's
default charset. |
static String |
toJavaString(CCharPointer cString,
UnsignedWord length,
Charset charset)
Decodes a C
char* of length length to a Java string using charset . |
static String |
utf8ToJavaString(CCharPointer utf8String)
Decodes a UTF-8 encoded, 0 terminated C
char* to a Java string. |
public static CTypeConversion.CCharPointerHolder toCString(CharSequence javaString)
public static UnsignedWord toCString(CharSequence javaString, CCharPointer buffer, UnsignedWord bufferSize)
javaString
into the buffer as a 0 terminated C string encoded with the
default character set.
When a nullptr is passed as the buffer and the buffer size is zero, then no copying is
performed but the byte-sized length of the javaString
is still returned.
In case the string is larger than the buffer
, then an
IllegalArgumentException
is thrown.
javaString
- managed Java stringbuffer
- to store the bytes of 0 terminated javaString encoded with the default charset
or a nullptrbufferSize
- size of the buffer or 0 when the buffer is a nullptrjavaString
when represented as a C string
encoded with the default character set. This length does not include the 0
terminator.public static UnsignedWord toCString(CharSequence javaString, Charset charset, CCharPointer buffer, UnsignedWord bufferSize)
javaString
into the buffer as a 0 terminated C string encoded with the
charset
character set.
When a nullptr is passed as the buffer and the buffer size is zero, then no copying is
performed but the byte-sized length of the javaString
is still returned.
In case the string is larger than the buffer
, then an
IllegalArgumentException
is thrown.
javaString
- managed Java stringcharset
- desired character set for the returned stringbuffer
- to store the bytes of 0 terminated javaString encoded with charset or a nullptrbufferSize
- size of the buffer or 0 when the buffer is a nullptrjavaString
when represented as C string encoded
with the charset
character set. This length does not include the 0
terminator.public static String toJavaString(CCharPointer cString)
char*
to a Java string using the platform's default charset.cString
- the pointer to a 0 terminated C stringpublic static String toJavaString(CCharPointer cString, UnsignedWord length)
char*
of length length
to a Java string using the platform's
default charset.cString
- the pointer to a 0 terminated C stringpublic static String toJavaString(CCharPointer cString, UnsignedWord length, Charset charset)
char*
of length length
to a Java string using charset
.cString
- the pointer to a 0 terminated C stringpublic static String utf8ToJavaString(CCharPointer utf8String)
char*
to a Java string.utf8String
- the pointer to a UTF-8 encoded, 0 terminated C stringpublic static byte toCBoolean(boolean value)
value
- the Java boolean valuepublic static boolean toBoolean(int value)
public static boolean toBoolean(PointerBase pointer)
public static CTypeConversion.CCharPointerPointerHolder toCStrings(CharSequence[] javaStrings)
public static ByteBuffer asByteBuffer(PointerBase address, int size)
ByteBuffer
that refers to the native memory at the specified address. The
passed size becomes the capacity of the byte buffer, and the
buffer's byte order is set to
native byte order. The caller is responsible for
ensuring that the memory can be safely accessed while the ByteBuffer is used, and for freeing
the memory afterwards.public static CTypeConversion.CCharPointerHolder toCBytes(byte[] bytes)