Class BytePointer
java.lang.Object
org.bytedeco.javacpp.Pointer
org.bytedeco.javacpp.BytePointer
- All Implemented Interfaces:
AutoCloseable
The peer class to native pointers and arrays of
signed char, including strings.
All operations take into account the position and limit, when appropriate.-
Nested Class Summary
Nested classes/interfaces inherited from class Pointer
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.DeallocatorReference, Pointer.DeallocatorThread, Pointer.NativeDeallocator, Pointer.ProxyDeallocator, Pointer.ReferenceCounter -
Field Summary
FieldsFields inherited from class Pointer
address, capacity, deallocatorThread, limit, maxBytes, maxPhysicalBytes, maxRetries, position -
Constructor Summary
ConstructorsConstructorDescriptionBytePointer(byte... array) Allocates enough memory for the array and copies it.BytePointer(long size) Allocates a nativesigned chararray of the given size.Allocates enough memory for the encoded string and actually encodes it in the platform's default charset before copying it.BytePointer(String s, String charsetName) Allocates enough memory for the encoded string and actually encodes it in the named charset before copying it.BytePointer(String s, Charset charset) Allocates enough memory for the encoded string and actually encodes it in the given charset before copying it.BytePointer(ByteBuffer buffer) For direct buffers, callsPointer(Buffer), while for buffers backed with an array, allocates enough memory for the array and copies it. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidallocateArray(long size) final ByteBufferasBuffer()Same asPointer.asByteBuffer(), but can be overridden to return subclasses of Buffer.capacity(long capacity) Sets the capacity and returns this.byteget()get(byte[] array) get(byte[] array, int offset, int length) Reads a portion of the native array into a Java array.byteget(long i) booleangetBool()ReturnsgetBool(0).booleangetBool(long i) Returns theboolvalue at the i-thbytein the native array.chargetChar()ReturnsgetChar(0).chargetChar(long i) Returns thecharvalue at the i-thbytein the native array.doubleReturnsgetDouble(0).doublegetDouble(long i) Returns thedoublevalue at the i-thbytein the native array.floatgetFloat()ReturnsgetFloat(0).floatgetFloat(long i) Returns thefloatvalue at the i-thbytein the native array.intgetInt()ReturnsgetInt(0).intgetInt(long i) Returns theintvalue at the i-thbytein the native array.longgetLong()ReturnsgetLong(0).longgetLong(long i) Returns thelongvalue at the i-thbytein the native array.getPointer(long i) ReturnsgetPointer(getClass(), i).ReturnsgetPointerValue(0).getPointerValue(long i) Returns thePointervalue at the i-thbytein the native array.shortgetShort()ReturnsgetShort(0).shortgetShort(long i) Returns theshortvalue at the i-thbytein the native array.Decodes the native bytes assuming they are encoded in the platform's default charset.Decodes the native bytes assuming they are encoded in the named charset.Decodes the native bytes assuming they are encoded in the given charset.byte[]Returns the bytes, assuming a null-terminated string iflimit <= position.intReturnsgetUnsigned(0).intgetUnsigned(long i) Returns thebytevalue at the i-thbytein the native array, treated as unsigned.limit(long limit) Sets the limit and returns this.position(long position) Sets the position and returns this.put(byte b) put(byte... array) put(byte[] array, int offset, int length) Writes a portion of a Java array into the native array.put(long i, byte b) Copies thebytevalue to the i-th element of a native array.putBool(boolean b) ReturnsputBool(0, s).putBool(long i, boolean b) Sets theboolvalue at the i-thbytein the native array.putChar(char c) ReturnsputChar(0, s).putChar(long i, char c) Sets thecharvalue at the i-thbytein the native array.putDouble(double d) ReturnsputDouble(0, s).putDouble(long i, double d) Sets thedoublevalue at the i-thbytein the native array.putFloat(float f) ReturnsputFloat(0, s).putFloat(long i, float f) Sets thefloatvalue at the i-thbytein the native array.putInt(int j) ReturnsputInt(0, s).putInt(long i, int j) Sets theintvalue at the i-thbytein the native array.putLong(long j) ReturnsputLong(0, s).putLong(long i, long j) Sets thelongvalue at the i-thbytein the native array.putPointerValue(long i, Pointer p) Sets thePointervalue at the i-thbytein the native array.ReturnsputPointerValue(0, s).putShort(long i, short s) Sets theshortvalue at the i-thbytein the native array.putShort(short s) ReturnsputShort(0, s).Encodes the String into the platform's default charset and copies it in native memory, including a terminating null byte.Encodes the String into the named charset and copies it in native memory, including a terminating null byte.Encodes the String into the given charset and copies it in native memory, including a terminating null byte.putUnsigned(int b) ReturnsputUnsigned(0, b).putUnsigned(long i, int b) Sets thebytevalue at the i-thbytein the native array, treated as unsigned.intsizeof()Returns 1 for Pointer or BytePointer elseLoader.sizeof(getClass())or -1 on error.static BytePointerstrcat(BytePointer dst, BytePointer src) static BytePointerstrchr(BytePointer str, int ch) static intstrcmp(BytePointer str1, BytePointer str2) static intstrcoll(BytePointer str1, BytePointer str2) static BytePointerstrcpy(BytePointer dst, BytePointer src) static longstrcspn(BytePointer str1, BytePointer str2) static BytePointerstrerror(int errnum) static longstrlen(BytePointer str) static BytePointerstrncat(BytePointer dst, BytePointer src, long n) static intstrncmp(BytePointer str1, BytePointer str2, long n) static BytePointerstrncpy(BytePointer dst, BytePointer src, long n) static BytePointerstrpbrk(BytePointer str1, BytePointer str2) static BytePointerstrrchr(BytePointer str, int ch) static longstrspn(BytePointer str1, BytePointer str2) static BytePointerstrstr(BytePointer str1, BytePointer str2) static BytePointerstrtok(BytePointer str, BytePointer delim) static longstrxfrm(BytePointer dst, BytePointer src, long n) Methods inherited from class Pointer
address, asByteBuffer, availablePhysicalBytes, calloc, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, getDirectBufferAddress, getPointer, getPointer, getPointer, hashCode, init, interruptDeallocatorThread, isNull, isNull, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetAddress, offsetof, offsetof, parseBytes, physicalBytes, physicalBytesInaccurate, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, withDeallocator, zero
-
Field Details
-
logger
-
-
Constructor Details
-
BytePointer
Allocates enough memory for the encoded string and actually encodes it in the named charset before copying it.- Parameters:
s- the String to encode and copycharsetName- the charset in which the bytes are encoded- Throws:
UnsupportedEncodingException- See Also:
-
BytePointer
-
BytePointer
Allocates enough memory for the encoded string and actually encodes it in the platform's default charset before copying it.- Parameters:
s- the String to encode and copy- See Also:
-
BytePointer
public BytePointer(byte... array) Allocates enough memory for the array and copies it.- Parameters:
array- the array to copy- See Also:
-
BytePointer
For direct buffers, callsPointer(Buffer), while for buffers backed with an array, allocates enough memory for the array and copies it.- Parameters:
buffer- the Buffer to reference or copy- See Also:
-
BytePointer
public BytePointer(long size) Allocates a nativesigned chararray of the given size.- Parameters:
size- the number ofsigned charelements to allocate
-
BytePointer
public BytePointer()- See Also:
-
BytePointer
- See Also:
-
-
Method Details
-
allocateArray
private void allocateArray(long size) -
position
Description copied from class:PointerSets the position and returns this. That makes thearray.position(i)statement sort of equivalent to thearray[i]statement in C++. -
limit
Description copied from class:PointerSets the limit and returns this. Used to limit the size of an operation on this object. -
capacity
Description copied from class:PointerSets the capacity and returns this. Should not be called more than once after allocation. -
sizeof
-
getPointer
Description copied from class:PointerReturnsgetPointer(getClass(), i).- Overrides:
getPointerin classPointer
-
getStringBytes
public byte[] getStringBytes()Returns the bytes, assuming a null-terminated string iflimit <= position. -
getString
Decodes the native bytes assuming they are encoded in the named charset. Assumes a null-terminated string iflimit <= position.- Parameters:
charsetName- the charset in which the bytes are encoded- Returns:
- a String from the null-terminated string
- Throws:
UnsupportedEncodingException
-
getString
-
getString
Decodes the native bytes assuming they are encoded in the platform's default charset. Assumes a null-terminated string iflimit <= position.- Returns:
- a String from the null-terminated string
-
putString
Encodes the String into the named charset and copies it in native memory, including a terminating null byte. Sets the limit to just before the terminating null byte.- Parameters:
s- the String to encode and copycharsetName- the charset in which to encode the bytes- Returns:
- this
- Throws:
UnsupportedEncodingException- See Also:
-
putString
Encodes the String into the given charset and copies it in native memory, including a terminating null byte. Sets the limit to just before the terminating null byte.- Parameters:
s- the String to encode and copycharset- the charset in which to encode the bytes- Returns:
- this
- See Also:
-
putString
Encodes the String into the platform's default charset and copies it in native memory, including a terminating null byte. Sets the limit to just before the terminating null byte.- Parameters:
s- the String to encode and copy- Returns:
- this
- See Also:
-
get
public byte get()- Returns:
get(0)
-
get
public byte get(long i) - Returns:
- the i-th
bytevalue of a native array
-
put
- Returns:
put(0, b)
-
put
Copies thebytevalue to the i-th element of a native array.- Parameters:
i- the index into the arrayb- thebytevalue to copy- Returns:
- this
-
get
- Returns:
get(array, 0, array.length)
-
put
- Returns:
put(array, 0, array.length)
-
get
Reads a portion of the native array into a Java array.- Parameters:
array- the array to write tooffset- the offset into the array where to start writinglength- the length of data to read and write- Returns:
- this
-
put
Writes a portion of a Java array into the native array.- Parameters:
array- the array to read fromoffset- the offset into the array where to start readinglength- the length of data to read and write- Returns:
- this
-
asBuffer
Description copied from class:PointerSame asPointer.asByteBuffer(), but can be overridden to return subclasses of Buffer. -
getUnsigned
public int getUnsigned()ReturnsgetUnsigned(0). -
getUnsigned
public int getUnsigned(long i) Returns thebytevalue at the i-thbytein the native array, treated as unsigned. -
putUnsigned
ReturnsputUnsigned(0, b). -
putUnsigned
Sets thebytevalue at the i-thbytein the native array, treated as unsigned. -
getShort
public short getShort()ReturnsgetShort(0). -
getShort
Returns theshortvalue at the i-thbytein the native array. -
putShort
ReturnsputShort(0, s). -
putShort
Sets theshortvalue at the i-thbytein the native array. -
getInt
public int getInt()ReturnsgetInt(0). -
getInt
Returns theintvalue at the i-thbytein the native array. -
putInt
ReturnsputInt(0, s). -
putInt
Sets theintvalue at the i-thbytein the native array. -
getLong
public long getLong()ReturnsgetLong(0). -
getLong
Returns thelongvalue at the i-thbytein the native array. -
putLong
ReturnsputLong(0, s). -
putLong
Sets thelongvalue at the i-thbytein the native array. -
getFloat
public float getFloat()ReturnsgetFloat(0). -
getFloat
Returns thefloatvalue at the i-thbytein the native array. -
putFloat
ReturnsputFloat(0, s). -
putFloat
Sets thefloatvalue at the i-thbytein the native array. -
getDouble
public double getDouble()ReturnsgetDouble(0). -
getDouble
Returns thedoublevalue at the i-thbytein the native array. -
putDouble
ReturnsputDouble(0, s). -
putDouble
Sets thedoublevalue at the i-thbytein the native array. -
getBool
public boolean getBool()ReturnsgetBool(0). -
getBool
Returns theboolvalue at the i-thbytein the native array. -
putBool
ReturnsputBool(0, s). -
putBool
Sets theboolvalue at the i-thbytein the native array. -
getChar
public char getChar()ReturnsgetChar(0). -
getChar
Returns thecharvalue at the i-thbytein the native array. -
putChar
ReturnsputChar(0, s). -
putChar
Sets thecharvalue at the i-thbytein the native array. -
getPointerValue
ReturnsgetPointerValue(0). -
getPointerValue
Returns thePointervalue at the i-thbytein the native array. -
putPointerValue
ReturnsputPointerValue(0, s). -
putPointerValue
Sets thePointervalue at the i-thbytein the native array. -
strcat
@Cast("char*") public static BytePointer strcat(@Cast("char*") BytePointer dst, @Cast("char*") BytePointer src) -
strchr
-
strcmp
-
strcoll
-
strcpy
@Cast("char*") public static BytePointer strcpy(@Cast("char*") BytePointer dst, @Cast("char*") BytePointer src) -
strcspn
@Cast("size_t") public static long strcspn(@Cast("char*") BytePointer str1, @Cast("char*") BytePointer str2) -
strerror
-
strlen
-
strncat
@Cast("char*") public static BytePointer strncat(@Cast("char*") BytePointer dst, @Cast("char*") BytePointer src, @Cast("size_t") long n) -
strncmp
public static int strncmp(@Cast("char*") BytePointer str1, @Cast("char*") BytePointer str2, @Cast("size_t") long n) -
strncpy
@Cast("char*") public static BytePointer strncpy(@Cast("char*") BytePointer dst, @Cast("char*") BytePointer src, @Cast("size_t") long n) -
strpbrk
@Cast("char*") public static BytePointer strpbrk(@Cast("char*") BytePointer str1, @Cast("char*") BytePointer str2) -
strrchr
-
strspn
@Cast("size_t") public static long strspn(@Cast("char*") BytePointer str1, @Cast("char*") BytePointer str2) -
strstr
@Cast("char*") public static BytePointer strstr(@Cast("char*") BytePointer str1, @Cast("char*") BytePointer str2) -
strtok
@Cast("char*") public static BytePointer strtok(@Cast("char*") BytePointer str, @Cast("char*") BytePointer delim) -
strxfrm
@Cast("size_t") public static long strxfrm(@Cast("char*") BytePointer dst, @Cast("char*") BytePointer src, @Cast("size_t") long n)
-