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
clear
(long size)
static
Pointer
createConstant
(int peer)
(void*)CONSTANT
.
static
Pointer
createConstant
(long peer)
(void*)CONSTANT
.
String
dump
(long offset,
int size)
boolean
equals
(
Object
o)
Pointer
to the specified object.
getByte
(long offset)
byte
.
byte[]
getByteArray
(long offset,
int arraySize)
ByteBuffer
getByteBuffer
(long offset,
long length)
getChar
(long offset)
wchar_t
.
char[]
getCharArray
(long offset,
int arraySize)
double
getDouble
(long offset)
double
.
double[]
getDoubleArray
(long offset,
int arraySize)
float
getFloat
(long offset)
float
.
float[]
getFloatArray
(long offset,
int arraySize)
getInt
(long offset)
int
.
int[]
getIntArray
(long offset,
int arraySize)
getLong
(long offset)
long
.
long[]
getLongArray
(long offset,
int arraySize)
NativeLong
getNativeLong
(long offset)
long
.
Pointer
getPointer
(long offset)
Pointer
[]
getPointerArray
(long offset)
Pointer
.
Pointer
[]
getPointerArray
(long offset,
int arraySize)
Pointer
of the requested size.
short
getShort
(long offset)
short
.
short[]
getShortArray
(long offset,
int arraySize)
String
getString
(long offset)
String
getString
(long offset,
boolean wide)
getString(long,String)
or
getWideString(long)
instead.
getStringArray
(long offset,
int length)
String
based on a native array
of
char *
, using the given array length.
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.
String
[]
getStringArray
(long offset,
String
encoding)
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)
const wchar_t *
) string from memory.
String
[]
getWideStringArray
(long offset)
String
[]
getWideStringArray
(long offset,
int length)
hashCode
()
Pointer
object
indexOf
(long offset,
byte value)
static long
nativeValue
(
Pointer
p)
static void
nativeValue
(
Pointer
p,
long value)
read
(long offset,
byte[] buf,
int index,
int length)
read
(long offset,
char[] buf,
int index,
int length)
read
(long offset,
double[] buf,
int index,
int length)
read
(long offset,
float[] buf,
int index,
int length)
read
(long offset,
int[] buf,
int index,
int length)
read
(long offset,
long[] buf,
int index,
int length)
read
(long offset,
Pointer
[] buf,
int index,
int length)
read
(long offset,
short[] buf,
int index,
int length)
setByte
(long offset,
byte value)
value
at location being pointed to.
setChar
(long offset,
char value)
value
at location being pointed to.
setDouble
(long offset,
double value)
value
at location being pointed to.
setFloat
(long offset,
float value)
value
at location being pointed to.
setInt
(long offset,
int value)
value
at location being pointed to.
setLong
(long offset,
long value)
value
at location being pointed to.
setMemory
(long offset,
long length,
byte value)
value
to the requested bank of memory.
setNativeLong
(long offset,
NativeLong
value)
value
at location being pointed to.
setPointer
(long offset,
Pointer
value)
value
at location being pointed to.
setShort
(long offset,
short value)
value
at location being pointed to.
setString
(long offset,
String
value)
value
to the location being
pointed to, using the encoding indicated by
Native.getDefaultStringEncoding()
.
setString
(long offset,
String
value,
boolean wide)
setWideString(long,String)
instead.
setString
(long offset,
WString
value)
value
to the location being pointed to as a
wide string (
wchar_t*
).
(package private) void
setValue
(long offset,
Object
value,
Class
type)
setWideString
(long offset,
String
value)
value
to the location being pointed to as a
wide string (
wchar_t*
).
Pointer
share
(long offset)
Pointer
share
(long offset,
long sz)
String
toString
()
write
(long offset,
byte[] buf,
int index,
int length)
write
(long offset,
char[] buf,
int index,
int length)
write
(long offset,
double[] buf,
int index,
int length)
write
(long offset,
float[] buf,
int index,
int length)
write
(long offset,
int[] buf,
int index,
int length)
write
(long offset,
long[] buf,
int index,
int length)
write
(long bOff,
Pointer
[] buf,
int index,
int length)
write
(long offset,
short[] buf,
int index,
int length)
public Pointer(long peer)
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, long sz)
Pointer
,
and the C pointers being pointed to by these objects are also
equal. Returns false otherwise.
public int hashCode()
Pointer
object
hashCode
in class
Object
public long indexOf(long offset,
byte value)
offset
- byte offset from pointer into which data is copied
buf
-
byte
array into which data is copied
index
- array index from which to start copying
length
- number of elements from native pointer that must be copied
offset
- byte offset from pointer from which data is copied
buf
-
short
array into which data is copied
index
- array index to which data is copied
length
- number of elements from native pointer that must be copied
offset
- byte offset from pointer from which data is copied
buf
-
char
array into which data is copied
index
- array index to which data is copied
length
- number of elements from native pointer that must be copied
offset
- byte offset from pointer from which data is copied
buf
-
int
array into which data is copied
index
- array index to which data is copied
length
- number of elements from native pointer that must be copied
offset
- byte offset from pointer from which data is copied
buf
-
long
array into which data is copied
index
- array index to which data is copied
length
- number of elements from native pointer that must be copied
offset
- byte offset from pointer from which data is copied
buf
-
float
array into which data is copied
index
- array index to which data is copied
length
- number of elements from native pointer that must be copied
offset
- byte offset from pointer from which data is copied
buf
-
double
array into which data is copied
index
- array index to which data is copied
length
- number of elements from native pointer that must be copied
offset
- byte offset from pointer from which data is copied
buf
-
Pointer
array into which data is copied
index
- array index to which data is copied
length
- number of elements from native pointer that must be copied
offset
- byte offset from pointer into which data is copied
buf
-
byte
array from which to copy
index
- array index from which to start copying
length
- number of elements from
buf
that must be
copied
offset
- byte offset from pointer into which data is copied
buf
-
short
array from which to copy
index
- array index from which to start copying
length
- number of elements from
buf
that must be
copied
offset
- byte offset from pointer into which data is copied
buf
-
char
array from which to copy
index
- array index from which to start copying
length
- number of elements from
buf
that must be
copied
offset
- byte offset from pointer into which data is copied
buf
-
int
array from which to copy
index
- array index from which to start copying
length
- number of elements from
buf
that must be
copied
offset
- byte offset from pointer into which data is copied
buf
-
long
array from which to copy
index
- array index from which to start copying
length
- number of elements from
buf
that must be
copied
offset
- byte offset from pointer into which data is copied
buf
-
float
array from which to copy
index
- array index from which to start copying
length
- number of elements from
buf
that must be
copied
offset
- byte offset from pointer into which data is copied
buf
-
double
array from which to copy
index
- array index from which to start copying
length
- number of elements from
buf
that must be
copied
bOff
- byte offset from pointer into which data is copied
buf
-
Pointer
array from which to copy
index
- array index from which to start copying
length
- number of elements from
buf
that must be
copied
public byte getByte(long offset)
byte
. This is
equivalent to the expression
*((jbyte *)((char *)Pointer + offset))
.
offset
- offset from pointer to perform the indirection
byte
value being pointed to
public char getChar(long offset)
wchar_t
. This
is equivalent to the expression
*((wchar_t*)((char *)Pointer + offset))
.
offset
- offset from pointer to perform the indirection
wchar_t
value being pointed to
public short getShort(long offset)
short
. This is
equivalent to the expression
*((jshort *)((char *)Pointer + offset))
.
offset
- byte offset from pointer to perform the indirection
short
value being pointed to
public int getInt(long offset)
int
. This is
equivalent to the expression
*((jint *)((char *)Pointer + offset))
.
offset
- byte offset from pointer to perform the indirection
int
value being pointed to
public long getLong(long offset)
long
. This is
equivalent to the expression
*((jlong *)((char *)Pointer + offset))
.
offset
- byte offset from pointer to perform the indirection
long
value being pointed to
public NativeLong getNativeLong(long offset)
long
. This is
equivalent to the expression
*((long *)((char *)Pointer + offset))
.
offset
- byte offset from pointer to perform the indirection
long
value being pointed to
public float getFloat(long offset)
float
. This is
equivalent to the expression
*((jfloat *)((char *)Pointer + offset))
.
offset
- byte offset from pointer to perform the indirection
float
value being pointed to
public double getDouble(long offset)
double
. This
is equivalent to the expression
*((jdouble *)((char *)Pointer + offset))
.
offset
- byte offset from pointer to perform the indirection
double
value being pointed to
public Pointer getPointer(long offset)
*((void **)((char *)Pointer + offset))
.
offset
- byte offset from pointer to perform the indirection
Pointer
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 buffer
length
- Length of ByteBuffer
public 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 string
String
value being pointed to
public String getString(long offset)
Native.getDefaultStringEncoding()
.
offset
- byte offset from pointer to start reading bytes
String
value being pointed to
public String getString(long offset, String encoding)
offset
- byte offset from pointer to obtain the native string
encoding
- the desired encoding
String
value being pointed to
public 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 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.
The strings are decoded using the encoding returned by
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.
The strings are decoded using the encoding returned by
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.
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.
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 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 set
value
-
byte
value to set
public 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 set
value
-
short
value to set
public 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 set
value
-
char
value to set
public 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 set
value
-
int
value to set
public 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 set
value
-
long
value to set
public 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 set
value
-
long
value to set
public 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 set
value
-
float
value to set
public 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 set
value
-
double
value to set
public 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 set
value
-
Pointer
holding the actual pointer value to
set, which may be
null
to indicate a
NULL
pointer.
setWideString(long,String)
instead.
value
to the location being pointed to.
offset
- byte offset from pointer at which characters in
value
must be set
value
-
java.lang.String
value to set
wide
- 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 set
value
-
java.lang.String
value to set
public 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 set
value
-
WString
value to set
public 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 set
value
-
java.lang.String
value to set
value
to the location being pointed to, using
the requested encoding.
offset
- byte offset from pointer at which characters in
value
must be set
value
-
java.lang.String
value to set
encoding
- desired encoding