Package org.bytedeco.javacpp
Class BytePointer
- java.lang.Object
-
- org.bytedeco.javacpp.Pointer
-
- org.bytedeco.javacpp.BytePointer
-
- All Implemented Interfaces:
java.lang.AutoCloseable
@Properties(inherit=javacpp.class) public class BytePointer extends Pointer
The peer class to native pointers and arrays ofsigned 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
Fields Modifier and Type Field Description private static Logger
logger
-
Fields inherited from class org.bytedeco.javacpp.Pointer
address, capacity, deallocatorThread, limit, maxBytes, maxPhysicalBytes, maxRetries, position
-
-
Constructor Summary
Constructors Constructor Description BytePointer()
BytePointer(byte... array)
Allocates enough memory for the array and copies it.BytePointer(long size)
Allocates a nativesigned char
array of the given size.BytePointer(java.lang.String s)
Allocates enough memory for the encoded string and actually encodes it in the platform's default charset before copying it.BytePointer(java.lang.String s, java.lang.String charsetName)
Allocates enough memory for the encoded string and actually encodes it in the named charset before copying it.BytePointer(java.lang.String s, java.nio.charset.Charset charset)
Allocates enough memory for the encoded string and actually encodes it in the given charset before copying it.BytePointer(java.nio.ByteBuffer buffer)
For direct buffers, callsPointer(Buffer)
, while for buffers backed with an array, allocates enough memory for the array and copies it.BytePointer(Pointer p)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
allocateArray(long size)
java.nio.ByteBuffer
asBuffer()
Same asPointer.asByteBuffer()
, but can be overridden to return subclasses of Buffer.BytePointer
capacity(long capacity)
Sets the capacity and returns this.byte
get()
BytePointer
get(byte[] array)
BytePointer
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
getDouble()
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.BytePointer
getPointer(long i)
ReturnsgetPointer(getClass(), i)
.Pointer
getPointerValue()
ReturnsgetPointerValue(0)
.Pointer
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.java.lang.String
getString()
Decodes the native bytes assuming they are encoded in the platform's default charset.java.lang.String
getString(java.lang.String charsetName)
Decodes the native bytes assuming they are encoded in the named charset.java.lang.String
getString(java.nio.charset.Charset charset)
Decodes the native bytes assuming they are encoded in the given charset.byte[]
getStringBytes()
Returns the bytes, assuming a null-terminated string iflimit <= position
.int
getUnsigned()
ReturnsgetUnsigned(0)
.int
getUnsigned(long i)
Returns thebyte
value at the i-thbyte
in the native array, treated as unsigned.BytePointer
limit(long limit)
Sets the limit and returns this.BytePointer
position(long position)
Sets the position and returns this.BytePointer
put(byte b)
BytePointer
put(byte... array)
BytePointer
put(byte[] array, int offset, int length)
Writes a portion of a Java array into the native array.BytePointer
put(long i, byte b)
Copies thebyte
value to the i-th element of a native array.BytePointer
putBool(boolean b)
ReturnsputBool(0, s)
.BytePointer
putBool(long i, boolean b)
Sets thebool
value at the i-thbyte
in the native array.BytePointer
putChar(char c)
ReturnsputChar(0, s)
.BytePointer
putChar(long i, char c)
Sets thechar
value at the i-thbyte
in the native array.BytePointer
putDouble(double d)
ReturnsputDouble(0, s)
.BytePointer
putDouble(long i, double d)
Sets thedouble
value at the i-thbyte
in the native array.BytePointer
putFloat(float f)
ReturnsputFloat(0, s)
.BytePointer
putFloat(long i, float f)
Sets thefloat
value at the i-thbyte
in the native array.BytePointer
putInt(int j)
ReturnsputInt(0, s)
.BytePointer
putInt(long i, int j)
Sets theint
value at the i-thbyte
in the native array.BytePointer
putLong(long j)
ReturnsputLong(0, s)
.BytePointer
putLong(long i, long j)
Sets thelong
value at the i-thbyte
in the native array.BytePointer
putPointerValue(long i, Pointer p)
Sets thePointer
value at the i-thbyte
in the native array.BytePointer
putPointerValue(Pointer p)
ReturnsputPointerValue(0, s)
.BytePointer
putShort(long i, short s)
Sets theshort
value at the i-thbyte
in the native array.BytePointer
putShort(short s)
ReturnsputShort(0, s)
.BytePointer
putString(java.lang.String s)
Encodes the String into the platform's default charset and copies it in native memory, including a terminating null byte.BytePointer
putString(java.lang.String s, java.lang.String charsetName)
Encodes the String into the named charset and copies it in native memory, including a terminating null byte.BytePointer
putString(java.lang.String s, java.nio.charset.Charset charset)
Encodes the String into the given charset and copies it in native memory, including a terminating null byte.BytePointer
putUnsigned(int b)
ReturnsputUnsigned(0, b)
.BytePointer
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 Detail
-
logger
private static final Logger logger
-
-
Constructor Detail
-
BytePointer
public BytePointer(java.lang.String s, java.lang.String charsetName) throws java.io.UnsupportedEncodingException
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:
java.io.UnsupportedEncodingException
- See Also:
putString(String, String)
-
BytePointer
public BytePointer(java.lang.String s, java.nio.charset.Charset charset)
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:
putString(String, Charset)
-
BytePointer
public BytePointer(java.lang.String s)
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:
putString(String)
-
BytePointer
public BytePointer(byte... array)
Allocates enough memory for the array and copies it.- Parameters:
array
- the array to copy- See Also:
put(byte[])
-
BytePointer
public BytePointer(java.nio.ByteBuffer buffer)
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:
put(byte[])
-
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:
Pointer()
-
BytePointer
public BytePointer(Pointer p)
- See Also:
Pointer(Pointer)
-
-
Method Detail
-
allocateArray
private void allocateArray(long size)
-
position
public BytePointer position(long 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++.- Overrides:
position
in classPointer
- Parameters:
position
- the new position- Returns:
- this
- See Also:
Pointer.position(long)
-
limit
public BytePointer limit(long limit)
Description copied from class:Pointer
Sets the limit and returns this. Used to limit the size of an operation on this object.- Overrides:
limit
in classPointer
- Parameters:
limit
- the new limit- Returns:
- this
- See Also:
Pointer.limit(long)
-
capacity
public BytePointer capacity(long capacity)
Description copied from class:Pointer
Sets the capacity and returns this. Should not be called more than once after allocation.- Overrides:
capacity
in classPointer
- Parameters:
capacity
- the new capacity- Returns:
- this
- See Also:
Pointer.capacity(long)
-
sizeof
public int sizeof()
Description copied from class:Pointer
Returns 1 for Pointer or BytePointer elseLoader.sizeof(getClass())
or -1 on error.
-
getPointer
public BytePointer getPointer(long i)
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
public java.lang.String getString(java.lang.String charsetName) throws java.io.UnsupportedEncodingException
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:
java.io.UnsupportedEncodingException
-
getString
public java.lang.String getString(java.nio.charset.Charset charset)
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
public java.lang.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
public BytePointer putString(java.lang.String s, java.lang.String charsetName) throws java.io.UnsupportedEncodingException
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:
java.io.UnsupportedEncodingException
- See Also:
String.getBytes(String)
,put(byte[])
-
putString
public BytePointer putString(java.lang.String s, java.nio.charset.Charset charset)
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:
String.getBytes(Charset)
,put(byte[])
-
putString
public BytePointer putString(java.lang.String s)
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:
String.getBytes()
,put(byte[])
-
get
public byte get()
- Returns:
get(0)
-
get
public byte get(long i)
- Returns:
- the i-th
byte
value of a native array
-
put
public BytePointer put(byte b)
- Returns:
put(0, b)
-
put
public BytePointer put(long i, byte b)
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
public BytePointer get(byte[] array)
- Returns:
get(array, 0, array.length)
-
put
public BytePointer put(byte... array)
- Returns:
put(array, 0, array.length)
-
get
public BytePointer get(byte[] array, int offset, int length)
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
public BytePointer put(byte[] array, int offset, int length)
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
public final java.nio.ByteBuffer asBuffer()
Description copied from class:Pointer
Same asPointer.asByteBuffer()
, but can be overridden to return subclasses of Buffer.- Overrides:
asBuffer
in classPointer
- Returns:
asByteBuffer()
- See Also:
asBuffer()
,ShortPointer.asBuffer()
,IntPointer.asBuffer()
,LongPointer.asBuffer()
,FloatPointer.asBuffer()
,DoublePointer.asBuffer()
,CharPointer.asBuffer()
-
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
public BytePointer putUnsigned(int b)
ReturnsputUnsigned(0, b)
.
-
putUnsigned
public BytePointer putUnsigned(long i, int b)
Sets thebyte
value at the i-thbyte
in the native array, treated as unsigned.
-
getShort
public short getShort()
ReturnsgetShort(0)
.
-
getShort
@ValueGetter @Cast("short") public short getShort(long i)
Returns theshort
value at the i-thbyte
in the native array.
-
putShort
public BytePointer putShort(short s)
ReturnsputShort(0, s)
.
-
putShort
@ValueSetter @Cast("short") public BytePointer putShort(long i, short s)
Sets theshort
value at the i-thbyte
in the native array.
-
getInt
public int getInt()
ReturnsgetInt(0)
.
-
getInt
@ValueGetter @Cast("int") public int getInt(long i)
Returns theint
value at the i-thbyte
in the native array.
-
putInt
public BytePointer putInt(int j)
ReturnsputInt(0, s)
.
-
putInt
@ValueSetter @Cast("int") public BytePointer putInt(long i, int j)
Sets theint
value at the i-thbyte
in the native array.
-
getLong
public long getLong()
ReturnsgetLong(0)
.
-
getLong
@ValueGetter @Cast("long long") public long getLong(long i)
Returns thelong
value at the i-thbyte
in the native array.
-
putLong
public BytePointer putLong(long j)
ReturnsputLong(0, s)
.
-
putLong
@ValueSetter @Cast("long long") public BytePointer putLong(long i, long j)
Sets thelong
value at the i-thbyte
in the native array.
-
getFloat
public float getFloat()
ReturnsgetFloat(0)
.
-
getFloat
@ValueGetter @Cast("float") public float getFloat(long i)
Returns thefloat
value at the i-thbyte
in the native array.
-
putFloat
public BytePointer putFloat(float f)
ReturnsputFloat(0, s)
.
-
putFloat
@ValueSetter @Cast("float") public BytePointer putFloat(long i, float f)
Sets thefloat
value at the i-thbyte
in the native array.
-
getDouble
public double getDouble()
ReturnsgetDouble(0)
.
-
getDouble
@ValueGetter @Cast("double") public double getDouble(long i)
Returns thedouble
value at the i-thbyte
in the native array.
-
putDouble
public BytePointer putDouble(double d)
ReturnsputDouble(0, s)
.
-
putDouble
@ValueSetter @Cast("double") public BytePointer putDouble(long i, double d)
Sets thedouble
value at the i-thbyte
in the native array.
-
getBool
public boolean getBool()
ReturnsgetBool(0)
.
-
getBool
@ValueGetter @Cast("bool") public boolean getBool(long i)
Returns thebool
value at the i-thbyte
in the native array.
-
putBool
public BytePointer putBool(boolean b)
ReturnsputBool(0, s)
.
-
putBool
@ValueSetter @Cast("bool") public BytePointer putBool(long i, boolean b)
Sets thebool
value at the i-thbyte
in the native array.
-
getChar
public char getChar()
ReturnsgetChar(0)
.
-
getChar
@ValueGetter @Cast("short") public char getChar(long i)
Returns thechar
value at the i-thbyte
in the native array.
-
putChar
public BytePointer putChar(char c)
ReturnsputChar(0, s)
.
-
putChar
@ValueSetter @Cast("short") public BytePointer putChar(long i, char c)
Sets thechar
value at the i-thbyte
in the native array.
-
getPointerValue
public Pointer getPointerValue()
ReturnsgetPointerValue(0)
.
-
getPointerValue
@ValueGetter @Cast("void*") public Pointer getPointerValue(long i)
Returns thePointer
value at the i-thbyte
in the native array.
-
putPointerValue
public BytePointer putPointerValue(Pointer p)
ReturnsputPointerValue(0, s)
.
-
putPointerValue
@ValueSetter @Cast("void*") public BytePointer putPointerValue(long i, Pointer p)
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
@Cast("char*") public static BytePointer strchr(@Cast("char*") BytePointer str, int ch)
-
strcmp
public static int strcmp(@Cast("char*") BytePointer str1, @Cast("char*") BytePointer str2)
-
strcoll
public static int strcoll(@Cast("char*") BytePointer str1, @Cast("char*") BytePointer str2)
-
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
@Cast("char*") public static BytePointer strerror(int errnum)
-
strlen
@Cast("size_t") public static long strlen(@Cast("char*") BytePointer str)
-
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
@Cast("char*") public static BytePointer strrchr(@Cast("char*") BytePointer str, int ch)
-
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)
-
-