Class BytePointer

java.lang.Object
org.bytedeco.javacpp.Pointer
org.bytedeco.javacpp.BytePointer
All Implemented Interfaces:
AutoCloseable

@Properties(inherit=javacpp.class) public class BytePointer extends Pointer
The peer class to native pointers and arrays of signed char, including strings. All operations take into account the position and limit, when appropriate.
  • Field Details

    • logger

      private static final Logger logger
  • Constructor Details

    • BytePointer

      public BytePointer(String s, String charsetName) throws 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 copy
      charsetName - the charset in which the bytes are encoded
      Throws:
      UnsupportedEncodingException
      See Also:
    • BytePointer

      public BytePointer(String s, 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 copy
      charset - the charset in which the bytes are encoded
      See Also:
    • BytePointer

      public BytePointer(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:
    • BytePointer

      public BytePointer(byte... array)
      Allocates enough memory for the array and copies it.
      Parameters:
      array - the array to copy
      See Also:
    • BytePointer

      public 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.
      Parameters:
      buffer - the Buffer to reference or copy
      See Also:
    • BytePointer

      public BytePointer(long size)
      Allocates a native signed char array of the given size.
      Parameters:
      size - the number of signed char elements to allocate
    • BytePointer

      public BytePointer()
      See Also:
    • BytePointer

      public BytePointer(Pointer p)
      See Also:
  • Method Details

    • 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 the array.position(i) statement sort of equivalent to the array[i] statement in C++.
      Overrides:
      position in class Pointer
      Parameters:
      position - the new position
      Returns:
      this
      See Also:
    • 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 class Pointer
      Parameters:
      limit - the new limit
      Returns:
      this
      See Also:
    • 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 class Pointer
      Parameters:
      capacity - the new capacity
      Returns:
      this
      See Also:
    • sizeof

      public int sizeof()
      Description copied from class: Pointer
      Returns 1 for Pointer or BytePointer else Loader.sizeof(getClass()) or -1 on error.
      Overrides:
      sizeof in class Pointer
    • getPointer

      public BytePointer getPointer(long i)
      Description copied from class: Pointer
      Returns getPointer(getClass(), i).
      Overrides:
      getPointer in class Pointer
    • getStringBytes

      public byte[] getStringBytes()
      Returns the bytes, assuming a null-terminated string if limit <= position.
    • getString

      public String getString(String charsetName) throws UnsupportedEncodingException
      Decodes the native bytes assuming they are encoded in the named charset. Assumes a null-terminated string if limit <= position.
      Parameters:
      charsetName - the charset in which the bytes are encoded
      Returns:
      a String from the null-terminated string
      Throws:
      UnsupportedEncodingException
    • getString

      public String getString(Charset charset)
      Decodes the native bytes assuming they are encoded in the given charset. Assumes a null-terminated string if limit <= position.
      Parameters:
      charset - the charset in which the bytes are encoded
      Returns:
      a String from the null-terminated string
    • getString

      public String getString()
      Decodes the native bytes assuming they are encoded in the platform's default charset. Assumes a null-terminated string if limit <= position.
      Returns:
      a String from the null-terminated string
    • putString

      public BytePointer putString(String s, String charsetName) throws 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 copy
      charsetName - the charset in which to encode the bytes
      Returns:
      this
      Throws:
      UnsupportedEncodingException
      See Also:
    • putString

      public BytePointer putString(String s, 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 copy
      charset - the charset in which to encode the bytes
      Returns:
      this
      See Also:
    • putString

      public BytePointer putString(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:
    • 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 the byte value to the i-th element of a native array.
      Parameters:
      i - the index into the array
      b - the byte 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 to
      offset - the offset into the array where to start writing
      length - 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 from
      offset - the offset into the array where to start reading
      length - the length of data to read and write
      Returns:
      this
    • asBuffer

      public final ByteBuffer asBuffer()
      Description copied from class: Pointer
      Same as Pointer.asByteBuffer(), but can be overridden to return subclasses of Buffer.
      Overrides:
      asBuffer in class Pointer
      Returns:
      asByteBuffer()
      See Also:
    • getUnsigned

      public int getUnsigned()
      Returns getUnsigned(0).
    • getUnsigned

      public int getUnsigned(long i)
      Returns the byte value at the i-th byte in the native array, treated as unsigned.
    • putUnsigned

      public BytePointer putUnsigned(int b)
      Returns putUnsigned(0, b).
    • putUnsigned

      public BytePointer putUnsigned(long i, int b)
      Sets the byte value at the i-th byte in the native array, treated as unsigned.
    • getShort

      public short getShort()
      Returns getShort(0).
    • getShort

      @ValueGetter @Cast("short") public short getShort(long i)
      Returns the short value at the i-th byte in the native array.
    • putShort

      public BytePointer putShort(short s)
      Returns putShort(0, s).
    • putShort

      @ValueSetter @Cast("short") public BytePointer putShort(long i, short s)
      Sets the short value at the i-th byte in the native array.
    • getInt

      public int getInt()
      Returns getInt(0).
    • getInt

      @ValueGetter @Cast("int") public int getInt(long i)
      Returns the int value at the i-th byte in the native array.
    • putInt

      public BytePointer putInt(int j)
      Returns putInt(0, s).
    • putInt

      @ValueSetter @Cast("int") public BytePointer putInt(long i, int j)
      Sets the int value at the i-th byte in the native array.
    • getLong

      public long getLong()
      Returns getLong(0).
    • getLong

      @ValueGetter @Cast("long long") public long getLong(long i)
      Returns the long value at the i-th byte in the native array.
    • putLong

      public BytePointer putLong(long j)
      Returns putLong(0, s).
    • putLong

      @ValueSetter @Cast("long long") public BytePointer putLong(long i, long j)
      Sets the long value at the i-th byte in the native array.
    • getFloat

      public float getFloat()
      Returns getFloat(0).
    • getFloat

      @ValueGetter @Cast("float") public float getFloat(long i)
      Returns the float value at the i-th byte in the native array.
    • putFloat

      public BytePointer putFloat(float f)
      Returns putFloat(0, s).
    • putFloat

      @ValueSetter @Cast("float") public BytePointer putFloat(long i, float f)
      Sets the float value at the i-th byte in the native array.
    • getDouble

      public double getDouble()
      Returns getDouble(0).
    • getDouble

      @ValueGetter @Cast("double") public double getDouble(long i)
      Returns the double value at the i-th byte in the native array.
    • putDouble

      public BytePointer putDouble(double d)
      Returns putDouble(0, s).
    • putDouble

      @ValueSetter @Cast("double") public BytePointer putDouble(long i, double d)
      Sets the double value at the i-th byte in the native array.
    • getBool

      public boolean getBool()
      Returns getBool(0).
    • getBool

      @ValueGetter @Cast("bool") public boolean getBool(long i)
      Returns the bool value at the i-th byte in the native array.
    • putBool

      public BytePointer putBool(boolean b)
      Returns putBool(0, s).
    • putBool

      @ValueSetter @Cast("bool") public BytePointer putBool(long i, boolean b)
      Sets the bool value at the i-th byte in the native array.
    • getChar

      public char getChar()
      Returns getChar(0).
    • getChar

      @ValueGetter @Cast("short") public char getChar(long i)
      Returns the char value at the i-th byte in the native array.
    • putChar

      public BytePointer putChar(char c)
      Returns putChar(0, s).
    • putChar

      @ValueSetter @Cast("short") public BytePointer putChar(long i, char c)
      Sets the char value at the i-th byte in the native array.
    • getPointerValue

      public Pointer getPointerValue()
      Returns getPointerValue(0).
    • getPointerValue

      @ValueGetter @Cast("void*") public Pointer getPointerValue(long i)
      Returns the Pointer value at the i-th byte in the native array.
    • putPointerValue

      public BytePointer putPointerValue(Pointer p)
      Returns putPointerValue(0, s).
    • putPointerValue

      @ValueSetter @Cast("void*") public BytePointer putPointerValue(long i, Pointer p)
      Sets the Pointer value at the i-th byte 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)