@Properties(inherit=javacpp.class) public class BytePointer extends Pointer
signed char
, including strings.
All operations take into account the position and limit, when appropriate.Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.DeallocatorReference, Pointer.DeallocatorThread, Pointer.NativeDeallocator, Pointer.ProxyDeallocator, Pointer.ReferenceCounter
Modifier and Type | Field and Description |
---|---|
private static Logger |
logger |
address, capacity, deallocatorThread, limit, maxBytes, maxPhysicalBytes, maxRetries, position
Constructor and Description |
---|
BytePointer() |
BytePointer(byte... array)
Allocates enough memory for the array and copies it.
|
BytePointer(ByteBuffer buffer)
For direct buffers, calls
Pointer(Buffer) , while for buffers
backed with an array, allocates enough memory for the array and copies it. |
BytePointer(long size)
Allocates a native
signed char array of the given size. |
BytePointer(Pointer p) |
BytePointer(String s)
Allocates enough memory for the encoded string and actually encodes it
in the platform's default 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(String s,
String charsetName)
Allocates enough memory for the encoded string and actually encodes it
in the named charset before copying it.
|
Modifier and Type | Method and Description |
---|---|
private void |
allocateArray(long size) |
ByteBuffer |
asBuffer()
Same as
Pointer.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()
Returns
getBool(0) . |
boolean |
getBool(long i)
Returns the
bool value at the i-th byte in the native array. |
char |
getChar()
Returns
getChar(0) . |
char |
getChar(long i)
Returns the
char value at the i-th byte in the native array. |
double |
getDouble()
Returns
getDouble(0) . |
double |
getDouble(long i)
Returns the
double value at the i-th byte in the native array. |
float |
getFloat()
Returns
getFloat(0) . |
float |
getFloat(long i)
Returns the
float value at the i-th byte in the native array. |
int |
getInt()
Returns
getInt(0) . |
int |
getInt(long i)
Returns the
int value at the i-th byte in the native array. |
long |
getLong()
Returns
getLong(0) . |
long |
getLong(long i)
Returns the
long value at the i-th byte in the native array. |
BytePointer |
getPointer(long i)
Returns
getPointer(getClass(), i) . |
Pointer |
getPointerValue()
Returns
getPointerValue(0) . |
Pointer |
getPointerValue(long i)
Returns the
Pointer value at the i-th byte in the native array. |
short |
getShort()
Returns
getShort(0) . |
short |
getShort(long i)
Returns the
short value at the i-th byte in the native array. |
String |
getString()
Decodes the native bytes assuming they are encoded in the platform's default charset.
|
String |
getString(Charset charset)
Decodes the native bytes assuming they are encoded in the given charset.
|
String |
getString(String charsetName)
Decodes the native bytes assuming they are encoded in the named charset.
|
byte[] |
getStringBytes()
Returns the bytes, assuming a null-terminated string if
limit <= position . |
int |
getUnsigned()
Returns
getUnsigned(0) . |
int |
getUnsigned(long i)
Returns the
byte value at the i-th byte 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... array) |
BytePointer |
put(byte b) |
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 the
byte value to the i-th element of a native array. |
BytePointer |
putBool(boolean b)
Returns
putBool(0, s) . |
BytePointer |
putBool(long i,
boolean b)
Sets the
bool value at the i-th byte in the native array. |
BytePointer |
putChar(char c)
Returns
putChar(0, s) . |
BytePointer |
putChar(long i,
char c)
Sets the
char value at the i-th byte in the native array. |
BytePointer |
putDouble(double d)
Returns
putDouble(0, s) . |
BytePointer |
putDouble(long i,
double d)
Sets the
double value at the i-th byte in the native array. |
BytePointer |
putFloat(float f)
Returns
putFloat(0, s) . |
BytePointer |
putFloat(long i,
float f)
Sets the
float value at the i-th byte in the native array. |
BytePointer |
putInt(int j)
Returns
putInt(0, s) . |
BytePointer |
putInt(long i,
int j)
Sets the
int value at the i-th byte in the native array. |
BytePointer |
putLong(long j)
Returns
putLong(0, s) . |
BytePointer |
putLong(long i,
long j)
Sets the
long value at the i-th byte in the native array. |
BytePointer |
putPointerValue(long i,
Pointer p)
Sets the
Pointer value at the i-th byte in the native array. |
BytePointer |
putPointerValue(Pointer p)
Returns
putPointerValue(0, s) . |
BytePointer |
putShort(long i,
short s)
Sets the
short value at the i-th byte in the native array. |
BytePointer |
putShort(short s)
Returns
putShort(0, s) . |
BytePointer |
putString(String s)
Encodes the String into the platform's default charset and copies it in
native memory, including a terminating null byte.
|
BytePointer |
putString(String s,
Charset charset)
Encodes the String into the given charset and copies it in native memory,
including a terminating null byte.
|
BytePointer |
putString(String s,
String charsetName)
Encodes the String into the named charset and copies it in native memory,
including a terminating null byte.
|
BytePointer |
putUnsigned(int b)
Returns
putUnsigned(0, b) . |
BytePointer |
putUnsigned(long i,
int b)
Sets the
byte value at the i-th byte in the native array, treated as unsigned. |
int |
sizeof()
Returns 1 for Pointer or BytePointer else
Loader.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) |
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
private static final Logger logger
public BytePointer(String s, String charsetName) throws UnsupportedEncodingException
s
- the String to encode and copycharsetName
- the charset in which the bytes are encodedUnsupportedEncodingException
putString(String, String)
public BytePointer(String s, Charset charset)
s
- the String to encode and copycharset
- the charset in which the bytes are encodedputString(String, Charset)
public BytePointer(String s)
s
- the String to encode and copyputString(String)
public BytePointer(byte... array)
array
- the array to copyput(byte[])
public BytePointer(ByteBuffer buffer)
Pointer(Buffer)
, while for buffers
backed with an array, allocates enough memory for the array and copies it.buffer
- the Buffer to reference or copyput(byte[])
public BytePointer(long size)
signed char
array of the given size.size
- the number of signed char
elements to allocatepublic BytePointer()
Pointer()
public BytePointer(Pointer p)
Pointer(Pointer)
private void allocateArray(long size)
public BytePointer position(long position)
Pointer
array.position(i)
statement sort of equivalent to the array[i]
statement in C++.position
in class Pointer
position
- the new positionPointer.position(long)
public BytePointer limit(long limit)
Pointer
limit
in class Pointer
limit
- the new limitPointer.limit(long)
public BytePointer capacity(long capacity)
Pointer
capacity
in class Pointer
capacity
- the new capacityPointer.capacity(long)
public int sizeof()
Pointer
Loader.sizeof(getClass())
or -1 on error.public BytePointer getPointer(long i)
Pointer
getPointer(getClass(), i)
.getPointer
in class Pointer
public byte[] getStringBytes()
limit <= position
.public String getString(String charsetName) throws UnsupportedEncodingException
limit <= position
.charsetName
- the charset in which the bytes are encodedUnsupportedEncodingException
public String getString(Charset charset)
limit <= position
.charset
- the charset in which the bytes are encodedpublic String getString()
limit <= position
.public BytePointer putString(String s, String charsetName) throws UnsupportedEncodingException
s
- the String to encode and copycharsetName
- the charset in which to encode the bytesUnsupportedEncodingException
String.getBytes(String)
,
put(byte[])
public BytePointer putString(String s, Charset charset)
s
- the String to encode and copycharset
- the charset in which to encode the bytesString.getBytes(Charset)
,
put(byte[])
public BytePointer putString(String s)
s
- the String to encode and copyString.getBytes()
,
put(byte[])
public byte get()
get(0)
public byte get(long i)
byte
value of a native arraypublic BytePointer put(byte b)
put(0, b)
public BytePointer put(long i, byte b)
byte
value to the i-th element of a native array.i
- the index into the arrayb
- the byte
value to copypublic BytePointer get(byte[] array)
get(array, 0, array.length)
public BytePointer put(byte... array)
put(array, 0, array.length)
public BytePointer get(byte[] array, int offset, int length)
array
- the array to write tooffset
- the offset into the array where to start writinglength
- the length of data to read and writepublic BytePointer put(byte[] array, int offset, int length)
array
- the array to read fromoffset
- the offset into the array where to start readinglength
- the length of data to read and writepublic final ByteBuffer asBuffer()
Pointer
Pointer.asByteBuffer()
, but can be overridden to return subclasses of Buffer.asBuffer
in class Pointer
asByteBuffer()
asBuffer()
,
ShortPointer.asBuffer()
,
IntPointer.asBuffer()
,
LongPointer.asBuffer()
,
FloatPointer.asBuffer()
,
DoublePointer.asBuffer()
,
CharPointer.asBuffer()
public int getUnsigned()
getUnsigned(0)
.public int getUnsigned(long i)
byte
value at the i-th byte
in the native array, treated as unsigned.public BytePointer putUnsigned(int b)
putUnsigned(0, b)
.public BytePointer putUnsigned(long i, int b)
byte
value at the i-th byte
in the native array, treated as unsigned.public short getShort()
getShort(0)
.@ValueGetter @Cast(value="short") public short getShort(long i)
short
value at the i-th byte
in the native array.public BytePointer putShort(short s)
putShort(0, s)
.@ValueSetter @Cast(value="short") public BytePointer putShort(long i, short s)
short
value at the i-th byte
in the native array.public int getInt()
getInt(0)
.@ValueGetter @Cast(value="int") public int getInt(long i)
int
value at the i-th byte
in the native array.public BytePointer putInt(int j)
putInt(0, s)
.@ValueSetter @Cast(value="int") public BytePointer putInt(long i, int j)
int
value at the i-th byte
in the native array.public long getLong()
getLong(0)
.@ValueGetter @Cast(value="long long") public long getLong(long i)
long
value at the i-th byte
in the native array.public BytePointer putLong(long j)
putLong(0, s)
.@ValueSetter @Cast(value="long long") public BytePointer putLong(long i, long j)
long
value at the i-th byte
in the native array.public float getFloat()
getFloat(0)
.@ValueGetter @Cast(value="float") public float getFloat(long i)
float
value at the i-th byte
in the native array.public BytePointer putFloat(float f)
putFloat(0, s)
.@ValueSetter @Cast(value="float") public BytePointer putFloat(long i, float f)
float
value at the i-th byte
in the native array.public double getDouble()
getDouble(0)
.@ValueGetter @Cast(value="double") public double getDouble(long i)
double
value at the i-th byte
in the native array.public BytePointer putDouble(double d)
putDouble(0, s)
.@ValueSetter @Cast(value="double") public BytePointer putDouble(long i, double d)
double
value at the i-th byte
in the native array.public boolean getBool()
getBool(0)
.@ValueGetter @Cast(value="bool") public boolean getBool(long i)
bool
value at the i-th byte
in the native array.public BytePointer putBool(boolean b)
putBool(0, s)
.@ValueSetter @Cast(value="bool") public BytePointer putBool(long i, boolean b)
bool
value at the i-th byte
in the native array.public char getChar()
getChar(0)
.@ValueGetter @Cast(value="short") public char getChar(long i)
char
value at the i-th byte
in the native array.public BytePointer putChar(char c)
putChar(0, s)
.@ValueSetter @Cast(value="short") public BytePointer putChar(long i, char c)
char
value at the i-th byte
in the native array.public Pointer getPointerValue()
getPointerValue(0)
.@ValueGetter @Cast(value="void*") public Pointer getPointerValue(long i)
Pointer
value at the i-th byte
in the native array.public BytePointer putPointerValue(Pointer p)
putPointerValue(0, s)
.@ValueSetter @Cast(value="void*") public BytePointer putPointerValue(long i, Pointer p)
Pointer
value at the i-th byte
in the native array.@Cast(value="char*") public static BytePointer strcat(@Cast(value="char*") BytePointer dst, @Cast(value="char*") BytePointer src)
@Cast(value="char*") public static BytePointer strchr(@Cast(value="char*") BytePointer str, int ch)
public static int strcmp(@Cast(value="char*") BytePointer str1, @Cast(value="char*") BytePointer str2)
public static int strcoll(@Cast(value="char*") BytePointer str1, @Cast(value="char*") BytePointer str2)
@Cast(value="char*") public static BytePointer strcpy(@Cast(value="char*") BytePointer dst, @Cast(value="char*") BytePointer src)
@Cast(value="size_t") public static long strcspn(@Cast(value="char*") BytePointer str1, @Cast(value="char*") BytePointer str2)
@Cast(value="char*") public static BytePointer strerror(int errnum)
@Cast(value="size_t") public static long strlen(@Cast(value="char*") BytePointer str)
@Cast(value="char*") public static BytePointer strncat(@Cast(value="char*") BytePointer dst, @Cast(value="char*") BytePointer src, @Cast(value="size_t") long n)
public static int strncmp(@Cast(value="char*") BytePointer str1, @Cast(value="char*") BytePointer str2, @Cast(value="size_t") long n)
@Cast(value="char*") public static BytePointer strncpy(@Cast(value="char*") BytePointer dst, @Cast(value="char*") BytePointer src, @Cast(value="size_t") long n)
@Cast(value="char*") public static BytePointer strpbrk(@Cast(value="char*") BytePointer str1, @Cast(value="char*") BytePointer str2)
@Cast(value="char*") public static BytePointer strrchr(@Cast(value="char*") BytePointer str, int ch)
@Cast(value="size_t") public static long strspn(@Cast(value="char*") BytePointer str1, @Cast(value="char*") BytePointer str2)
@Cast(value="char*") public static BytePointer strstr(@Cast(value="char*") BytePointer str1, @Cast(value="char*") BytePointer str2)
@Cast(value="char*") public static BytePointer strtok(@Cast(value="char*") BytePointer str, @Cast(value="char*") BytePointer delim)
@Cast(value="size_t") public static long strxfrm(@Cast(value="char*") BytePointer dst, @Cast(value="char*") BytePointer src, @Cast(value="size_t") long n)
Copyright © 2024. All rights reserved.