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 Loggerlogger-
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 chararray 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 voidallocateArray(long size)java.nio.ByteBufferasBuffer()Same asPointer.asByteBuffer(), but can be overridden to return subclasses of Buffer.BytePointercapacity(long capacity)Sets the capacity and returns this.byteget()BytePointerget(byte[] array)BytePointerget(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.doublegetDouble()ReturnsgetDouble(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.BytePointergetPointer(long i)ReturnsgetPointer(getClass(), i).PointergetPointerValue()ReturnsgetPointerValue(0).PointergetPointerValue(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.java.lang.StringgetString()Decodes the native bytes assuming they are encoded in the platform's default charset.java.lang.StringgetString(java.lang.String charsetName)Decodes the native bytes assuming they are encoded in the named charset.java.lang.StringgetString(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.intgetUnsigned()ReturnsgetUnsigned(0).intgetUnsigned(long i)Returns thebytevalue at the i-thbytein the native array, treated as unsigned.BytePointerlimit(long limit)Sets the limit and returns this.BytePointerposition(long position)Sets the position and returns this.BytePointerput(byte b)BytePointerput(byte... array)BytePointerput(byte[] array, int offset, int length)Writes a portion of a Java array into the native array.BytePointerput(long i, byte b)Copies thebytevalue to the i-th element of a native array.BytePointerputBool(boolean b)ReturnsputBool(0, s).BytePointerputBool(long i, boolean b)Sets theboolvalue at the i-thbytein the native array.BytePointerputChar(char c)ReturnsputChar(0, s).BytePointerputChar(long i, char c)Sets thecharvalue at the i-thbytein the native array.BytePointerputDouble(double d)ReturnsputDouble(0, s).BytePointerputDouble(long i, double d)Sets thedoublevalue at the i-thbytein the native array.BytePointerputFloat(float f)ReturnsputFloat(0, s).BytePointerputFloat(long i, float f)Sets thefloatvalue at the i-thbytein the native array.BytePointerputInt(int j)ReturnsputInt(0, s).BytePointerputInt(long i, int j)Sets theintvalue at the i-thbytein the native array.BytePointerputLong(long j)ReturnsputLong(0, s).BytePointerputLong(long i, long j)Sets thelongvalue at the i-thbytein the native array.BytePointerputPointerValue(long i, Pointer p)Sets thePointervalue at the i-thbytein the native array.BytePointerputPointerValue(Pointer p)ReturnsputPointerValue(0, s).BytePointerputShort(long i, short s)Sets theshortvalue at the i-thbytein the native array.BytePointerputShort(short s)ReturnsputShort(0, s).BytePointerputString(java.lang.String s)Encodes the String into the platform's default charset and copies it in native memory, including a terminating null byte.BytePointerputString(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.BytePointerputString(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.BytePointerputUnsigned(int b)ReturnsputUnsigned(0, b).BytePointerputUnsigned(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 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.UnsupportedEncodingExceptionAllocates 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 chararray of the given size.- Parameters:
size- the number ofsigned charelements 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:PointerSets the position and returns this. That makes thearray.position(i)statement sort of equivalent to thearray[i]statement in C++.- Overrides:
positionin classPointer- Parameters:
position- the new position- Returns:
- this
- See Also:
Pointer.position(long)
-
limit
public BytePointer limit(long limit)
Description copied from class:PointerSets the limit and returns this. Used to limit the size of an operation on this object.- Overrides:
limitin classPointer- Parameters:
limit- the new limit- Returns:
- this
- See Also:
Pointer.limit(long)
-
capacity
public BytePointer capacity(long capacity)
Description copied from class:PointerSets the capacity and returns this. Should not be called more than once after allocation.- Overrides:
capacityin classPointer- Parameters:
capacity- the new capacity- Returns:
- this
- See Also:
Pointer.capacity(long)
-
sizeof
public int sizeof()
Description copied from class:PointerReturns 1 for Pointer or BytePointer elseLoader.sizeof(getClass())or -1 on error.
-
getPointer
public BytePointer getPointer(long i)
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
public java.lang.String getString(java.lang.String charsetName) throws java.io.UnsupportedEncodingExceptionDecodes 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
bytevalue of a native array
-
put
public BytePointer put(byte b)
- Returns:
put(0, b)
-
put
public BytePointer put(long i, byte b)
Copies thebytevalue to the i-th element of a native array.- Parameters:
i- the index into the arrayb- thebytevalue 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:PointerSame asPointer.asByteBuffer(), but can be overridden to return subclasses of Buffer.- Overrides:
asBufferin 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 thebytevalue at the i-thbytein the native array, treated as unsigned.
-
putUnsigned
public BytePointer putUnsigned(int b)
ReturnsputUnsigned(0, b).
-
putUnsigned
public BytePointer putUnsigned(long i, int b)
Sets thebytevalue at the i-thbytein the native array, treated as unsigned.
-
getShort
public short getShort()
ReturnsgetShort(0).
-
getShort
@ValueGetter @Cast("short") public short getShort(long i)
Returns theshortvalue at the i-thbytein the native array.
-
putShort
public BytePointer putShort(short s)
ReturnsputShort(0, s).
-
putShort
@ValueSetter @Cast("short") public BytePointer putShort(long i, short s)
Sets theshortvalue at the i-thbytein the native array.
-
getInt
public int getInt()
ReturnsgetInt(0).
-
getInt
@ValueGetter @Cast("int") public int getInt(long i)
Returns theintvalue at the i-thbytein the native array.
-
putInt
public BytePointer putInt(int j)
ReturnsputInt(0, s).
-
putInt
@ValueSetter @Cast("int") public BytePointer putInt(long i, int j)
Sets theintvalue at the i-thbytein the native array.
-
getLong
public long getLong()
ReturnsgetLong(0).
-
getLong
@ValueGetter @Cast("long long") public long getLong(long i)
Returns thelongvalue at the i-thbytein 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 thelongvalue at the i-thbytein the native array.
-
getFloat
public float getFloat()
ReturnsgetFloat(0).
-
getFloat
@ValueGetter @Cast("float") public float getFloat(long i)
Returns thefloatvalue at the i-thbytein the native array.
-
putFloat
public BytePointer putFloat(float f)
ReturnsputFloat(0, s).
-
putFloat
@ValueSetter @Cast("float") public BytePointer putFloat(long i, float f)
Sets thefloatvalue at the i-thbytein the native array.
-
getDouble
public double getDouble()
ReturnsgetDouble(0).
-
getDouble
@ValueGetter @Cast("double") public double getDouble(long i)
Returns thedoublevalue at the i-thbytein the native array.
-
putDouble
public BytePointer putDouble(double d)
ReturnsputDouble(0, s).
-
putDouble
@ValueSetter @Cast("double") public BytePointer putDouble(long i, double d)
Sets thedoublevalue at the i-thbytein the native array.
-
getBool
public boolean getBool()
ReturnsgetBool(0).
-
getBool
@ValueGetter @Cast("bool") public boolean getBool(long i)
Returns theboolvalue at the i-thbytein the native array.
-
putBool
public BytePointer putBool(boolean b)
ReturnsputBool(0, s).
-
putBool
@ValueSetter @Cast("bool") public BytePointer putBool(long i, boolean b)
Sets theboolvalue at the i-thbytein the native array.
-
getChar
public char getChar()
ReturnsgetChar(0).
-
getChar
@ValueGetter @Cast("short") public char getChar(long i)
Returns thecharvalue at the i-thbytein the native array.
-
putChar
public BytePointer putChar(char c)
ReturnsputChar(0, s).
-
putChar
@ValueSetter @Cast("short") public BytePointer putChar(long i, char c)
Sets thecharvalue at the i-thbytein the native array.
-
getPointerValue
public Pointer getPointerValue()
ReturnsgetPointerValue(0).
-
getPointerValue
@ValueGetter @Cast("void*") public Pointer getPointerValue(long i)
Returns thePointervalue at the i-thbytein the native array.
-
putPointerValue
public BytePointer putPointerValue(Pointer p)
ReturnsputPointerValue(0, s).
-
putPointerValue
@ValueSetter @Cast("void*") public BytePointer putPointerValue(long i, Pointer p)
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
@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)
-
-