Top Description Inners Fields Constructors Methods
com.sun.jna

public Class Pointer

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.jna.Pointer.Opaque, com.sun.jna.Function, com.sun.jna.Memory
Imports
java.io.PrintWriter, .StringWriter, java.lang.reflect.Array, java.nio.Buffer, .ByteBuffer, .ByteOrder, java.util.ArrayList, .List

An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a native pointer. The native pointer could be any type of native pointer. Methods such as 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.

Authors
Sheng Liang, originator, Todd Fast, suitability modifications, Timothy Wall, robust library loading
See Also
Function

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
Pointer.Opaque

Pointer which disallows all read/write access.

Field Summary

Modifier and TypeField and Description
public static final Pointer
NULL

Convenience constant, same as null.

protected long
peer

Pointer value of the real native pointer.

Constructor Summary

AccessConstructor and Description
pack-priv
Pointer()

Derived class must assign peer pointer value.

public
Pointer(long peer)

Create from native pointer.

Method Summary

Modifier and TypeMethod and Description
public void
clear(long size)

Zero memory for the given number of bytes.

public static final Pointer
createConstant(long peer)

Convenience constant, equivalent to (void*)CONSTANT.

public static final Pointer
createConstant(int peer)

Convenience constant, equivalent to (void*)CONSTANT.

public String
dump(long offset, int size)

Dump memory for debugging purposes.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public byte

Returns:

the byte value being pointed to
getByte
(long
offset from pointer to perform the indirection
offset
)

Indirect the native pointer as a pointer to byte.

public byte[]
getByteArray(long offset, int arraySize)

Read a native array of bytes of size arraySize from the given offset from this Pointer.

public ByteBuffer

Returns:

a direct ByteBuffer that accesses the memory being pointed to,
getByteBuffer
(long
byte offset from pointer to start the buffer
offset
,
long
Length of ByteBuffer
length
)

Get a ByteBuffer mapped to the memory pointed to by the pointer, ensuring the buffer uses native byte order.

public char

Returns:

the wchar_t value being pointed to
getChar
(long
offset from pointer to perform the indirection
offset
)

Indirect the native pointer as a pointer to wchar_t.

public char[]
getCharArray(long offset, int arraySize)

Read a native array of wchar_t of size arraySize from the given offset from this Pointer.

public double

Returns:

the double value being pointed to
getDouble
(long
byte offset from pointer to perform the indirection
offset
)

Indirect the native pointer as a pointer to double.

public double[]
getDoubleArray(long offset, int arraySize)

Read a native array of double of size arraySize from the given offset from this Pointer.

public float

Returns:

the float value being pointed to
getFloat
(long
byte offset from pointer to perform the indirection
offset
)

Indirect the native pointer as a pointer to float.

public float[]
getFloatArray(long offset, int arraySize)

Read a native array of float of size arraySize from the given offset from this Pointer.

public int

Returns:

the int value being pointed to
getInt
(long
byte offset from pointer to perform the indirection
offset
)

Indirect the native pointer as a pointer to int.

public int[]
getIntArray(long offset, int arraySize)

Read a native array of int32 of size arraySize from the given offset from this Pointer.

public long

Returns:

the long value being pointed to
getLong
(long
byte offset from pointer to perform the indirection
offset
)

Indirect the native pointer as a pointer to long.

public long[]
getLongArray(long offset, int arraySize)

Read a native array of int64 of size arraySize from the given offset from this Pointer.

public NativeLong

Returns:

the long value being pointed to
getNativeLong
(long
byte offset from pointer to perform the indirection
offset
)

Indirect the native pointer as a pointer to long.

public Pointer

Returns:

a Pointer equivalent of the pointer value being pointed to, or null if the pointer value is NULL;
getPointer
(long
byte offset from pointer to perform the indirection
offset
)

Indirect the native pointer as a pointer to pointer.

public Pointer[]
getPointerArray(long offset)

Returns an array of Pointer.

public Pointer[]
getPointerArray(long offset, int arraySize)

Returns an array of Pointer of the requested size.

public short

Returns:

the short value being pointed to
getShort
(long
byte offset from pointer to perform the indirection
offset
)

Indirect the native pointer as a pointer to short.

public short[]
getShortArray(long offset, int arraySize)

Read a native array of int16 of size arraySize from the given offset from this Pointer.

public String

Returns:

the String value being pointed to
getString
(long
byte offset from pointer to start reading bytes
offset
)

Copy native memory to a Java String.

public String

Returns:

the String value being pointed to
getString
(long
byte offset from pointer to obtain the native string
offset
,
String
the desired encoding
encoding
)

Copy native memory to a Java String using the requested encoding.

public String[]
getStringArray(long offset)

Returns an array of String based on a native array of char *.

public String[]
getStringArray(long offset, String encoding)

Returns an array of String based on a native array of char *, using the requested encoding.

public String[]
getStringArray(long offset, int length)

Returns an array of String based on a native array of char *, using the given array length.

public 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.

pack-priv Object
getValue(long offset, Class<?> type, Object currentValue)

public String
getWideString(long offset)

Read a wide (const wchar_t *) string from memory.

public String[]
getWideStringArray(long offset)

public String[]
getWideStringArray(long offset, int length)

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public 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.

public static long
nativeValue(Pointer p)

Read the native peer value.

public static void
nativeValue(Pointer p, long value)

Set the native peer value.

public void
read(long
byte offset from pointer from which data is copied
offset
,
byte[]
byte array into which data is copied
buf
,
int
array index to which data is copied
index
,
int
number of elements from native pointer that must be copied
length
)

Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.

public void
read(long
byte offset from pointer from which data is copied
offset
,
short[]
short array into which data is copied
buf
,
int
array index to which data is copied
index
,
int
number of elements from native pointer that must be copied
length
)

Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.

public void
read(long
byte offset from pointer from which data is copied
offset
,
char[]
char array into which data is copied
buf
,
int
array index to which data is copied
index
,
int
number of elements from native pointer that must be copied
length
)

Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.

public void
read(long
byte offset from pointer from which data is copied
offset
,
int[]
int array into which data is copied
buf
,
int
array index to which data is copied
index
,
int
number of elements from native pointer that must be copied
length
)

Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.

public void
read(long
byte offset from pointer from which data is copied
offset
,
long[]
long array into which data is copied
buf
,
int
array index to which data is copied
index
,
int
number of elements from native pointer that must be copied
length
)

Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.

public void
read(long
byte offset from pointer from which data is copied
offset
,
float[]
float array into which data is copied
buf
,
int
array index to which data is copied
index
,
int
number of elements from native pointer that must be copied
length
)

Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.

public void
read(long
byte offset from pointer from which data is copied
offset
,
double[]
double array into which data is copied
buf
,
int
array index to which data is copied
index
,
int
number of elements from native pointer that must be copied
length
)

Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.

public void
read(long
byte offset from pointer from which data is copied
offset
,
Pointer[]
Pointer array into which data is copied
buf
,
int
array index to which data is copied
index
,
int
number of elements from native pointer that must be copied
length
)

Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.

private void
readArray(long offset, Object o, Class<?> cls)

Read memory starting at offset into the array with element type cls.

public void
setByte(long
byte offset from pointer at which value must be set
offset
,
byte
byte value to set
value
)

Set value at location being pointed to.

public void
setChar(long
byte offset from pointer at which value must be set
offset
,
char
char value to set
value
)

Set value at location being pointed to.

public void
setDouble(long
byte offset from pointer at which value must be set
offset
,
double
double value to set
value
)

Set value at location being pointed to.

public void
setFloat(long
byte offset from pointer at which value must be set
offset
,
float
float value to set
value
)

Set value at location being pointed to.

public void
setInt(long
byte offset from pointer at which value must be set
offset
,
int
int value to set
value
)

Set value at location being pointed to.

public void
setLong(long
byte offset from pointer at which value must be set
offset
,
long
long value to set
value
)

Set value at location being pointed to.

public void
setMemory(long
byte offset from pointer to start
offset
,
long
number of bytes to write
length
,
byte
value to be written
value
)

Write value to the requested bank of memory.

public void
setNativeLong(long
byte offset from pointer at which value must be set
offset
,
NativeLong
long value to set
value
)

Set value at location being pointed to.

public void
setPointer(long
byte offset from pointer at which value must be set
offset
,
Pointer
Pointer holding the actual pointer value to set, which may be null to indicate a NULL pointer.
value
)

Set value at location being pointed to.

public void
setShort(long
byte offset from pointer at which value must be set
offset
,
short
short value to set
value
)

Set value at location being pointed to.

public void
setString(long
byte offset from pointer at which characters in value must be set
offset
,
WString
WString value to set
value
)

Copy string value to the location being pointed to as a wide string (wchar_t*).

public void
setString(long
byte offset from pointer at which characters in value must be set
offset
,
String
java.lang.String value to set
value
)

Copy bytes out of string value to the location being pointed to, using the encoding indicated by Native#getDefaultStringEncoding().

public void
setString(long
byte offset from pointer at which characters in value must be set
offset
,
String
java.lang.String value to set
value
,
String
desired encoding
encoding
)

Copy string value to the location being pointed to, using the requested encoding.

pack-priv void
setValue(long offset, Object value, Class<?> type)

public void
setWideString(long
byte offset from pointer at which characters in value must be set
offset
,
String
java.lang.String value to set
value
)

Copy string value to the location being pointed to as a wide string (wchar_t*).

public Pointer
share(long offset)

Provide a view of this memory using the given offset to calculate a new base address.

public 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.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public void
write(long
byte offset from pointer into which data is copied
offset
,
byte[]
byte array from which to copy
buf
,
int
array index from which to start copying
index
,
int
number of elements from buf that must be copied
length
)

Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.

public void
write(long
byte offset from pointer into which data is copied
offset
,
short[]
short array from which to copy
buf
,
int
array index from which to start copying
index
,
int
number of elements from buf that must be copied
length
)

Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.

public void
write(long
byte offset from pointer into which data is copied
offset
,
char[]
char array from which to copy
buf
,
int
array index from which to start copying
index
,
int
number of elements from buf that must be copied
length
)

Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.

public void
write(long
byte offset from pointer into which data is copied
offset
,
int[]
int array from which to copy
buf
,
int
array index from which to start copying
index
,
int
number of elements from buf that must be copied
length
)

Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.

public void
write(long
byte offset from pointer into which data is copied
offset
,
long[]
long array from which to copy
buf
,
int
array index from which to start copying
index
,
int
number of elements from buf that must be copied
length
)

Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.

public void
write(long
byte offset from pointer into which data is copied
offset
,
float[]
float array from which to copy
buf
,
int
array index from which to start copying
index
,
int
number of elements from buf that must be copied
length
)

Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.

public void
write(long
byte offset from pointer into which data is copied
offset
,
double[]
double array from which to copy
buf
,
int
array index from which to start copying
index
,
int
number of elements from buf that must be copied
length
)

Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.

public void
write(long
byte offset from pointer into which data is copied
bOff
,
Pointer[]
Pointer array from which to copy
buf
,
int
array index from which to start copying
index
,
int
number of elements from buf that must be copied
length
)

Write the given array of Pointer to native memory.

private void
writeArray(long offset, Object value, Class<?> cls)

Write memory starting at offset from the array with element type cls.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait