Package org.bytedeco.javacpp
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 org.bytedeco.javacpp.Pointer
Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.DeallocatorReference, Pointer.DeallocatorThread, Pointer.NativeDeallocator, Pointer.ProxyDeallocator, Pointer.ReferenceCounter
-
Field Summary
FieldsFields inherited from class org.bytedeco.javacpp.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 char
array 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 void
allocateArray
(long size) final ByteBuffer
asBuffer()
Same asPointer.asByteBuffer()
, but can be overridden to return subclasses of Buffer.capacity
(long capacity) Sets the capacity and returns this.byte
get()
get
(byte[] array) get
(byte[] array, int offset, int length) Reads a portion of the native array into a Java array.byte
get
(long i) boolean
getBool()
ReturnsgetBool(0)
.boolean
getBool
(long i) Returns thebool
value at the i-thbyte
in the native array.char
getChar()
ReturnsgetChar(0)
.char
getChar
(long i) Returns thechar
value at the i-thbyte
in the native array.double
ReturnsgetDouble(0)
.double
getDouble
(long i) Returns thedouble
value at the i-thbyte
in the native array.float
getFloat()
ReturnsgetFloat(0)
.float
getFloat
(long i) Returns thefloat
value at the i-thbyte
in the native array.int
getInt()
ReturnsgetInt(0)
.int
getInt
(long i) Returns theint
value at the i-thbyte
in the native array.long
getLong()
ReturnsgetLong(0)
.long
getLong
(long i) Returns thelong
value at the i-thbyte
in the native array.getPointer
(long i) ReturnsgetPointer(getClass(), i)
.ReturnsgetPointerValue(0)
.getPointerValue
(long i) Returns thePointer
value at the i-thbyte
in the native array.short
getShort()
ReturnsgetShort(0)
.short
getShort
(long i) Returns theshort
value at the i-thbyte
in 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
.int
ReturnsgetUnsigned(0)
.int
getUnsigned
(long i) Returns thebyte
value at the i-thbyte
in 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 thebyte
value to the i-th element of a native array.putBool
(boolean b) ReturnsputBool(0, s)
.putBool
(long i, boolean b) Sets thebool
value at the i-thbyte
in the native array.putChar
(char c) ReturnsputChar(0, s)
.putChar
(long i, char c) Sets thechar
value at the i-thbyte
in the native array.putDouble
(double d) ReturnsputDouble(0, s)
.putDouble
(long i, double d) Sets thedouble
value at the i-thbyte
in the native array.putFloat
(float f) ReturnsputFloat(0, s)
.putFloat
(long i, float f) Sets thefloat
value at the i-thbyte
in the native array.putInt
(int j) ReturnsputInt(0, s)
.putInt
(long i, int j) Sets theint
value at the i-thbyte
in the native array.putLong
(long j) ReturnsputLong(0, s)
.putLong
(long i, long j) Sets thelong
value at the i-thbyte
in the native array.putPointerValue
(long i, Pointer p) Sets thePointer
value at the i-thbyte
in the native array.ReturnsputPointerValue(0, s)
.putShort
(long i, short s) Sets theshort
value at the i-thbyte
in 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 thebyte
value at the i-thbyte
in the native array, treated as unsigned.int
sizeof()
Returns 1 for Pointer or BytePointer elseLoader.sizeof(getClass())
or -1 on error.static BytePointer
strcat
(BytePointer dst, BytePointer src) static BytePointer
strchr
(BytePointer str, int ch) static int
strcmp
(BytePointer str1, BytePointer str2) static int
strcoll
(BytePointer str1, BytePointer str2) static BytePointer
strcpy
(BytePointer dst, BytePointer src) static long
strcspn
(BytePointer str1, BytePointer str2) static BytePointer
strerror
(int errnum) static long
strlen
(BytePointer str) static BytePointer
strncat
(BytePointer dst, BytePointer src, long n) static int
strncmp
(BytePointer str1, BytePointer str2, long n) static BytePointer
strncpy
(BytePointer dst, BytePointer src, long n) static BytePointer
strpbrk
(BytePointer str1, BytePointer str2) static BytePointer
strrchr
(BytePointer str, int ch) static long
strspn
(BytePointer str1, BytePointer str2) static BytePointer
strstr
(BytePointer str1, BytePointer str2) static BytePointer
strtok
(BytePointer str, BytePointer delim) static long
strxfrm
(BytePointer dst, BytePointer src, long n) Methods inherited from class org.bytedeco.javacpp.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
Allocates enough memory for the encoded string and actually encodes it in the given charset before copying it.- Parameters:
s
- the String to encode and copycharset
- the charset in which the bytes are encoded- See Also:
-
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 char
array of the given size.- Parameters:
size
- the number ofsigned char
elements to allocate
-
BytePointer
public BytePointer()- See Also:
-
BytePointer
- See Also:
-
-
Method Details
-
allocateArray
private void allocateArray(long size) -
position
Description copied from class:Pointer
Sets 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:Pointer
Sets the limit and returns this. Used to limit the size of an operation on this object. -
capacity
Description copied from class:Pointer
Sets the capacity and returns this. Should not be called more than once after allocation. -
sizeof
public int sizeof()Description copied from class:Pointer
Returns 1 for Pointer or BytePointer elseLoader.sizeof(getClass())
or -1 on error. -
getPointer
Description copied from class:Pointer
ReturnsgetPointer(getClass(), i)
.- Overrides:
getPointer
in 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
Decodes the native bytes assuming they are encoded in the given charset. Assumes a null-terminated string iflimit <= position
.- Parameters:
charset
- the charset in which the bytes are encoded- Returns:
- a String from the null-terminated string
-
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
byte
value of a native array
-
put
- Returns:
put(0, b)
-
put
Copies thebyte
value to the i-th element of a native array.- Parameters:
i
- the index into the arrayb
- thebyte
value 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:Pointer
Same asPointer.asByteBuffer()
, but can be overridden to return subclasses of Buffer. -
getUnsigned
public int getUnsigned()ReturnsgetUnsigned(0)
. -
getUnsigned
public int getUnsigned(long i) Returns thebyte
value at the i-thbyte
in the native array, treated as unsigned. -
putUnsigned
ReturnsputUnsigned(0, b)
. -
putUnsigned
Sets thebyte
value at the i-thbyte
in the native array, treated as unsigned. -
getShort
public short getShort()ReturnsgetShort(0)
. -
getShort
Returns theshort
value at the i-thbyte
in the native array. -
putShort
ReturnsputShort(0, s)
. -
putShort
Sets theshort
value at the i-thbyte
in the native array. -
getInt
public int getInt()ReturnsgetInt(0)
. -
getInt
Returns theint
value at the i-thbyte
in the native array. -
putInt
ReturnsputInt(0, s)
. -
putInt
Sets theint
value at the i-thbyte
in the native array. -
getLong
public long getLong()ReturnsgetLong(0)
. -
getLong
Returns thelong
value at the i-thbyte
in the native array. -
putLong
ReturnsputLong(0, s)
. -
putLong
Sets thelong
value at the i-thbyte
in the native array. -
getFloat
public float getFloat()ReturnsgetFloat(0)
. -
getFloat
Returns thefloat
value at the i-thbyte
in the native array. -
putFloat
ReturnsputFloat(0, s)
. -
putFloat
Sets thefloat
value at the i-thbyte
in the native array. -
getDouble
public double getDouble()ReturnsgetDouble(0)
. -
getDouble
Returns thedouble
value at the i-thbyte
in the native array. -
putDouble
ReturnsputDouble(0, s)
. -
putDouble
Sets thedouble
value at the i-thbyte
in the native array. -
getBool
public boolean getBool()ReturnsgetBool(0)
. -
getBool
Returns thebool
value at the i-thbyte
in the native array. -
putBool
ReturnsputBool(0, s)
. -
putBool
Sets thebool
value at the i-thbyte
in the native array. -
getChar
public char getChar()ReturnsgetChar(0)
. -
getChar
Returns thechar
value at the i-thbyte
in the native array. -
putChar
ReturnsputChar(0, s)
. -
putChar
Sets thechar
value at the i-thbyte
in the native array. -
getPointerValue
ReturnsgetPointerValue(0)
. -
getPointerValue
Returns thePointer
value at the i-thbyte
in the native array. -
putPointerValue
ReturnsputPointerValue(0, s)
. -
putPointerValue
Sets thePointer
value at the i-thbyte
in 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)
-