public class Pointer extends Object
write
,
read
, getXXX
, and setXXX
, provide
means to access memory underlying the native pointer.While a constructor exists to create a Pointer from an integer value, it's not generally a good idea to be creating pointers that way.
Function
Modifier and Type | Field and Description |
---|---|
static Pointer |
NULL
Convenience constant, same as
null . |
protected long |
peer
Pointer value of the real native pointer.
|
static int |
SIZE
Size of a native pointer, in bytes.
|
Constructor and Description |
---|
Pointer()
Derived class must assign peer pointer value.
|
Pointer(long peer)
Create from native pointer.
|
Modifier and Type | Method and Description |
---|---|
void |
clear(long size)
Zero memory for the given number of bytes.
|
static Pointer |
createConstant(int peer)
Convenience constant, equivalent to
(void*)CONSTANT . |
static Pointer |
createConstant(long peer)
Convenience constant, equivalent to
(void*)CONSTANT . |
String |
dump(long offset,
int size)
Dump memory for debugging purposes.
|
boolean |
equals(Object o)
Compares this
Pointer to the specified object. |
byte |
getByte(long offset)
Indirect the native pointer as a pointer to
byte . |
byte[] |
getByteArray(long offset,
int arraySize)
|
ByteBuffer |
getByteBuffer(long offset,
long length)
Get a ByteBuffer mapped to the memory pointed to by the pointer,
ensuring the buffer uses native byte order.
|
char |
getChar(long offset)
Indirect the native pointer as a pointer to
wchar_t . |
char[] |
getCharArray(long offset,
int arraySize)
|
double |
getDouble(long offset)
Indirect the native pointer as a pointer to
double . |
double[] |
getDoubleArray(long offset,
int arraySize)
|
float |
getFloat(long offset)
Indirect the native pointer as a pointer to
float . |
float[] |
getFloatArray(long offset,
int arraySize)
|
int |
getInt(long offset)
Indirect the native pointer as a pointer to
int . |
int[] |
getIntArray(long offset,
int arraySize)
|
long |
getLong(long offset)
Indirect the native pointer as a pointer to
long . |
long[] |
getLongArray(long offset,
int arraySize)
|
NativeLong |
getNativeLong(long offset)
Indirect the native pointer as a pointer to
long . |
Pointer |
getPointer(long offset)
Indirect the native pointer as a pointer to pointer.
|
Pointer[] |
getPointerArray(long offset)
Returns an array of
Pointer . |
Pointer[] |
getPointerArray(long offset,
int arraySize)
Returns an array of
Pointer of the requested size. |
short |
getShort(long offset)
Indirect the native pointer as a pointer to
short . |
short[] |
getShortArray(long offset,
int arraySize)
|
String |
getString(long offset)
Copy native memory to a Java String.
|
String |
getString(long offset,
boolean wide)
Deprecated.
use
getString(long,String) or getWideString(long) instead. |
String |
getString(long offset,
String encoding)
Copy native memory to a Java String using the requested encoding.
|
String[] |
getStringArray(long offset)
Returns an array of
String based on a native array
of char * . |
String[] |
getStringArray(long offset,
boolean wide)
Deprecated.
use
getStringArray(long,String) or getWideStringArray(long) instead. |
String[] |
getStringArray(long offset,
int length)
Returns an array of
String based on a native array
of char * , using the given array length. |
String[] |
getStringArray(long offset,
int length,
boolean wide)
Deprecated.
use
getStringArray(long,int,String) or getWideStringArray(long,int) instead. |
String[] |
getStringArray(long offset,
int length,
String encoding)
Returns an array of
String based on a native array
of char* or wchar_t* based on the
wide parameter, using the given array length. |
String[] |
getStringArray(long offset,
String encoding)
Returns an array of
String based on a native array
of char * , using the requested encoding. |
(package private) Object |
getValue(long offset,
Class type,
Object currentValue) |
String |
getWideString(long offset)
Read a wide (
const wchar_t * ) string from memory. |
String[] |
getWideStringArray(long offset) |
String[] |
getWideStringArray(long offset,
int length) |
int |
hashCode()
Returns a hashcode for the native pointer represented by this
Pointer object |
long |
indexOf(long offset,
byte value)
Returns the offset of the given value in memory from the given offset,
or -1 if the value is not found.
|
static long |
nativeValue(Pointer p)
Read the native peer value.
|
static void |
nativeValue(Pointer p,
long value)
Set the native peer value.
|
void |
read(long offset,
byte[] buf,
int index,
int length)
Indirect the native pointer, copying from memory pointed to by
native pointer, into the specified array.
|
void |
read(long offset,
char[] buf,
int index,
int length)
Indirect the native pointer, copying from memory pointed to by
native pointer, into the specified array.
|
void |
read(long offset,
double[] buf,
int index,
int length)
Indirect the native pointer, copying from memory pointed to by
native pointer, into the specified array.
|
void |
read(long offset,
float[] buf,
int index,
int length)
Indirect the native pointer, copying from memory pointed to by
native pointer, into the specified array.
|
void |
read(long offset,
int[] buf,
int index,
int length)
Indirect the native pointer, copying from memory pointed to by
native pointer, into the specified array.
|
void |
read(long offset,
long[] buf,
int index,
int length)
Indirect the native pointer, copying from memory pointed to by
native pointer, into the specified array.
|
void |
read(long offset,
Pointer[] buf,
int index,
int length)
Indirect the native pointer, copying from memory pointed to by
native pointer, into the specified array.
|
void |
read(long offset,
short[] buf,
int index,
int length)
Indirect the native pointer, copying from memory pointed to by
native pointer, into the specified array.
|
void |
setByte(long offset,
byte value)
Set
value at location being pointed to. |
void |
setChar(long offset,
char value)
Set
value at location being pointed to. |
void |
setDouble(long offset,
double value)
Set
value at location being pointed to. |
void |
setFloat(long offset,
float value)
Set
value at location being pointed to. |
void |
setInt(long offset,
int value)
Set
value at location being pointed to. |
void |
setLong(long offset,
long value)
Set
value at location being pointed to. |
void |
setMemory(long offset,
long length,
byte value)
Write
value to the requested bank of memory. |
void |
setNativeLong(long offset,
NativeLong value)
Set
value at location being pointed to. |
void |
setPointer(long offset,
Pointer value)
Set
value at location being pointed to. |
void |
setShort(long offset,
short value)
Set
value at location being pointed to. |
void |
setString(long offset,
String value)
Copy bytes out of string
value to the location being
pointed to, using the encoding indicated by Native.getDefaultStringEncoding() . |
void |
setString(long offset,
String value,
boolean wide)
Deprecated.
use
setWideString(long,String) instead. |
void |
setString(long offset,
String value,
String encoding)
Copy string
value to the location being pointed to, using
the requested encoding. |
void |
setString(long offset,
WString value)
Copy string
value to the location being pointed to as a
wide string (wchar_t* ). |
(package private) void |
setValue(long offset,
Object value,
Class type) |
void |
setWideString(long offset,
String value)
Copy string
value to the location being pointed to as a
wide string (wchar_t* ). |
Pointer |
share(long offset)
Provide a view of this memory using the given offset to calculate a new base address.
|
Pointer |
share(long offset,
long sz)
Provide a view of this memory using the given offset to calculate a
new base address, bounds-limiting the memory with the given size.
|
String |
toString() |
void |
write(long offset,
byte[] buf,
int index,
int length)
Indirect the native pointer, copying into memory pointed to by
native pointer, from the specified array.
|
void |
write(long offset,
char[] buf,
int index,
int length)
Indirect the native pointer, copying into memory pointed to by
native pointer, from the specified array.
|
void |
write(long offset,
double[] buf,
int index,
int length)
Indirect the native pointer, copying into memory pointed to by
native pointer, from the specified array.
|
void |
write(long offset,
float[] buf,
int index,
int length)
Indirect the native pointer, copying into memory pointed to by
native pointer, from the specified array.
|
void |
write(long offset,
int[] buf,
int index,
int length)
Indirect the native pointer, copying into memory pointed to by
native pointer, from the specified array.
|
void |
write(long offset,
long[] buf,
int index,
int length)
Indirect the native pointer, copying into memory pointed to by
native pointer, from the specified array.
|
void |
write(long bOff,
Pointer[] buf,
int index,
int length)
Write the given array of Pointer to native memory.
|
void |
write(long offset,
short[] buf,
int index,
int length)
Indirect the native pointer, copying into memory pointed to by
native pointer, from the specified array.
|
public static final int SIZE
public static final Pointer NULL
null
.protected long peer
Pointer()
public Pointer(long peer)
public static final Pointer createConstant(long peer)
(void*)CONSTANT
.public static final Pointer createConstant(int peer)
(void*)CONSTANT
.
This version will avoid setting any of the high bits on 64-bit
systems.public Pointer share(long offset)
public Pointer share(long offset, long sz)
public void clear(long size)
public boolean equals(Object o)
Pointer
to the specified object.public int hashCode()
Pointer
objectpublic long indexOf(long offset, byte value)
public void read(long offset, byte[] buf, int index, int length)
offset
- byte offset from pointer into which data is copiedbuf
- byte
array into which data is copiedindex
- array index from which to start copyinglength
- number of elements from native pointer that must be copiedpublic void read(long offset, short[] buf, int index, int length)
offset
- byte offset from pointer from which data is copiedbuf
- short
array into which data is copiedindex
- array index to which data is copiedlength
- number of elements from native pointer that must be copiedpublic void read(long offset, char[] buf, int index, int length)
offset
- byte offset from pointer from which data is copiedbuf
- char
array into which data is copiedindex
- array index to which data is copiedlength
- number of elements from native pointer that must be copiedpublic void read(long offset, int[] buf, int index, int length)
offset
- byte offset from pointer from which data is copiedbuf
- int
array into which data is copiedindex
- array index to which data is copiedlength
- number of elements from native pointer that must be copiedpublic void read(long offset, long[] buf, int index, int length)
offset
- byte offset from pointer from which data is copiedbuf
- long
array into which data is copiedindex
- array index to which data is copiedlength
- number of elements from native pointer that must be copiedpublic void read(long offset, float[] buf, int index, int length)
offset
- byte offset from pointer from which data is copiedbuf
- float
array into which data is copiedindex
- array index to which data is copiedlength
- number of elements from native pointer that must be copiedpublic void read(long offset, double[] buf, int index, int length)
offset
- byte offset from pointer from which data is copiedbuf
- double
array into which data is copiedindex
- array index to which data is copiedlength
- number of elements from native pointer that must be copiedpublic void read(long offset, Pointer[] buf, int index, int length)
offset
- byte offset from pointer from which data is copiedbuf
- Pointer
array into which data is copiedindex
- array index to which data is copiedlength
- number of elements from native pointer that must be copiedpublic void write(long offset, byte[] buf, int index, int length)
offset
- byte offset from pointer into which data is copiedbuf
- byte
array from which to copyindex
- array index from which to start copyinglength
- number of elements from buf
that must be
copiedpublic void write(long offset, short[] buf, int index, int length)
offset
- byte offset from pointer into which data is copiedbuf
- short
array from which to copyindex
- array index from which to start copyinglength
- number of elements from buf
that must be
copiedpublic void write(long offset, char[] buf, int index, int length)
offset
- byte offset from pointer into which data is copiedbuf
- char
array from which to copyindex
- array index from which to start copyinglength
- number of elements from buf
that must be
copiedpublic void write(long offset, int[] buf, int index, int length)
offset
- byte offset from pointer into which data is copiedbuf
- int
array from which to copyindex
- array index from which to start copyinglength
- number of elements from buf
that must be
copiedpublic void write(long offset, long[] buf, int index, int length)
offset
- byte offset from pointer into which data is copiedbuf
- long
array from which to copyindex
- array index from which to start copyinglength
- number of elements from buf
that must be
copiedpublic void write(long offset, float[] buf, int index, int length)
offset
- byte offset from pointer into which data is copiedbuf
- float
array from which to copyindex
- array index from which to start copyinglength
- number of elements from buf
that must be
copiedpublic void write(long offset, double[] buf, int index, int length)
offset
- byte offset from pointer into which data is copiedbuf
- double
array from which to copyindex
- array index from which to start copyinglength
- number of elements from buf
that must be
copiedpublic void write(long bOff, Pointer[] buf, int index, int length)
bOff
- byte offset from pointer into which data is copiedbuf
- Pointer
array from which to copyindex
- array index from which to start copyinglength
- number of elements from buf
that must be
copiedpublic byte getByte(long offset)
byte
. This is
equivalent to the expression
*((jbyte *)((char *)Pointer + offset))
.offset
- offset from pointer to perform the indirectionbyte
value being pointed topublic char getChar(long offset)
wchar_t
. This
is equivalent to the expression
*((wchar_t*)((char *)Pointer + offset))
.offset
- offset from pointer to perform the indirectionwchar_t
value being pointed topublic short getShort(long offset)
short
. This is
equivalent to the expression
*((jshort *)((char *)Pointer + offset))
.offset
- byte offset from pointer to perform the indirectionshort
value being pointed topublic int getInt(long offset)
int
. This is
equivalent to the expression
*((jint *)((char *)Pointer + offset))
.offset
- byte offset from pointer to perform the indirectionint
value being pointed topublic long getLong(long offset)
long
. This is
equivalent to the expression
*((jlong *)((char *)Pointer + offset))
.offset
- byte offset from pointer to perform the indirectionlong
value being pointed topublic NativeLong getNativeLong(long offset)
long
. This is
equivalent to the expression
*((long *)((char *)Pointer + offset))
.offset
- byte offset from pointer to perform the indirectionlong
value being pointed topublic float getFloat(long offset)
float
. This is
equivalent to the expression
*((jfloat *)((char *)Pointer + offset))
.offset
- byte offset from pointer to perform the indirectionfloat
value being pointed topublic double getDouble(long offset)
double
. This
is equivalent to the expression
*((jdouble *)((char *)Pointer + offset))
.offset
- byte offset from pointer to perform the indirectiondouble
value being pointed topublic Pointer getPointer(long offset)
*((void **)((char *)Pointer + offset))
.offset
- byte offset from pointer to perform the indirectionPointer
equivalent of the pointer value
being pointed to, or null
if the pointer value is
NULL
;public ByteBuffer getByteBuffer(long offset, long length)
offset
- byte offset from pointer to start the bufferlength
- Length of ByteBufferpublic String getString(long offset, boolean wide)
getString(long,String)
or getWideString(long)
instead.wide
is true,
access the memory as an array of wchar_t
, otherwise
as an array of char
, using the default platform encoding.offset
- byte offset from pointer to obtain the native string
v * @param wide whether to convert from a wide or standard C stringString
value being pointed topublic String getWideString(long offset)
const wchar_t *
) string from memory.public String getString(long offset)
Native.getDefaultStringEncoding()
.offset
- byte offset from pointer to start reading bytesString
value being pointed topublic String getString(long offset, String encoding)
offset
- byte offset from pointer to obtain the native stringencoding
- the desired encodingString
value being pointed topublic byte[] getByteArray(long offset, int arraySize)
public char[] getCharArray(long offset, int arraySize)
public short[] getShortArray(long offset, int arraySize)
public int[] getIntArray(long offset, int arraySize)
public long[] getLongArray(long offset, int arraySize)
public float[] getFloatArray(long offset, int arraySize)
public double[] getDoubleArray(long offset, int arraySize)
public Pointer[] getPointerArray(long offset)
Pointer
. The array length is
determined by a NULL-valued terminating element.public Pointer[] getPointerArray(long offset, int arraySize)
Pointer
of the requested size.public String[] getStringArray(long offset)
Returns an array of String
based on a native array
of char *
. The array length is determined by a
NULL-valued terminating element.
Native.getDefaultStringEncoding()
.public String[] getStringArray(long offset, String encoding)
String
based on a native array
of char *
, using the requested encoding. The array length
is determined by a NULL-valued terminating element.public String[] getStringArray(long offset, int length)
Returns an array of String
based on a native array
of char *
, using the given array length.
Native.getDefaultStringEncoding()
.public String[] getStringArray(long offset, boolean wide)
getStringArray(long,String)
or getWideStringArray(long)
instead.String
based on a native array
of char*
or wchar_t*
based on the
wide
parameter. The array length is determined by a
NULL-valued terminating element.public String[] getWideStringArray(long offset)
public String[] getWideStringArray(long offset, int length)
public String[] getStringArray(long offset, int length, boolean wide)
getStringArray(long,int,String)
or getWideStringArray(long,int)
instead.String
based on a native array
of char*
or wchar_t*
based on the
wide
parameter, using the given array length.public String[] getStringArray(long offset, int length, String encoding)
String
based on a native array
of char*
or wchar_t*
based on the
wide
parameter, using the given array length.offset
- length
- encoding
- public void setMemory(long offset, long length, byte value)
value
to the requested bank of memory.offset
- byte offset from pointer to startlength
- number of bytes to writevalue
- value to be writtenpublic void setByte(long offset, byte value)
value
at location being pointed to. This is equivalent
to the expression
*((jbyte *)((char *)Pointer + offset)) = value
.offset
- byte offset from pointer at which value
must be setvalue
- byte
value to setpublic void setShort(long offset, short value)
value
at location being pointed to. This is equivalent
to the expression
*((jshort *)((char *)Pointer + offset)) = value
.offset
- byte offset from pointer at which value
must be setvalue
- short
value to setpublic void setChar(long offset, char value)
value
at location being pointed to. This is equivalent
to the expression
*((wchar_t *)((char *)Pointer + offset)) = value
.offset
- byte offset from pointer at which value
must be setvalue
- char
value to setpublic void setInt(long offset, int value)
value
at location being pointed to. This is equivalent
to the expression
*((jint *)((char *)Pointer + offset)) = value
.offset
- byte offset from pointer at which value
must be setvalue
- int
value to setpublic void setLong(long offset, long value)
value
at location being pointed to. This is equivalent
to the expression
*((jlong *)((char *)Pointer + offset)) = value
.offset
- byte offset from pointer at which value
must be setvalue
- long
value to setpublic void setNativeLong(long offset, NativeLong value)
value
at location being pointed to. This is equivalent
to the expression
*((long *)((char *)Pointer + offset)) = value
.offset
- byte offset from pointer at which value
must be setvalue
- long
value to setpublic void setFloat(long offset, float value)
value
at location being pointed to. This is equivalent
to the expression
*((jfloat *)((char *)Pointer + offset)) = value
.offset
- byte offset from pointer at which value
must be setvalue
- float
value to setpublic void setDouble(long offset, double value)
value
at location being pointed to. This is equivalent
to the expression
*((jdouble *)((char *)Pointer + offset)) = value
.offset
- byte offset from pointer at which value
must be setvalue
- double
value to setpublic void setPointer(long offset, Pointer value)
value
at location being pointed to. This is equivalent
to the expression
*((void **)((char *)Pointer + offset)) = value
.offset
- byte offset from pointer at which value
must be setvalue
- Pointer
holding the actual pointer value to
set, which may be null
to indicate a NULL
pointer.public void setString(long offset, String value, boolean wide)
setWideString(long,String)
instead.value
to the location being pointed to.offset
- byte offset from pointer at which characters in
value
must be setvalue
- java.lang.String
value to setwide
- whether to write the native string as an array of
wchar_t
. If false, writes as a NUL-terminated array of
char
using the encoding indicated by Native.getDefaultStringEncoding()
.public void setWideString(long offset, String value)
value
to the location being pointed to as a
wide string (wchar_t*
).offset
- byte offset from pointer at which characters in
value
must be setvalue
- java.lang.String
value to setpublic void setString(long offset, WString value)
value
to the location being pointed to as a
wide string (wchar_t*
).offset
- byte offset from pointer at which characters in
value
must be setvalue
- WString
value to setpublic void setString(long offset, String value)
value
to the location being
pointed to, using the encoding indicated by Native.getDefaultStringEncoding()
.offset
- byte offset from pointer at which characters in
value
must be setvalue
- java.lang.String
value to setpublic void setString(long offset, String value, String encoding)
value
to the location being pointed to, using
the requested encoding.offset
- byte offset from pointer at which characters in
value
must be setvalue
- java.lang.String
value to setencoding
- desired encodingpublic String dump(long offset, int size)
public static long nativeValue(Pointer p)
public static void nativeValue(Pointer p, long value)