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.UnsupportedEncodingException, java.nio.ByteBuffer, .ByteOrder

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.

The constructors are intentionally package-private, since it's not generally a good idea to be creating C pointers de novo.

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.

pack-priv long
peer

Pointer value of the real native pointer.

public static final int
SIZE

Size of a native pointer, in bytes.

Constructor Summary

AccessConstructor and Description
pack-priv
Pointer()

Derived class must assign peer pointer value.

pack-priv
Pointer(long peer)

Create from native pointer.

Method Summary

Modifier and TypeMethod and Description
private static native byte
_getByte(long addr)

private static native char
_getChar(long addr)

private native ByteBuffer

Returns:

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

Get a direct ByteBuffer mapped to the memory pointed to by the pointer.

private static native double
_getDouble(long addr)

private native float
_getFloat(long addr)

private static native int
_getInt(long addr)

private static native long
_getLong(long addr)

private static native Pointer
_getPointer(long addr)

private static native short
_getShort(long addr)

private static native String
_getString(long addr, boolean wide)

private static native long
_indexOf(long addr, byte value)

private static native void
_read(long addr, byte[] buf, int index, int length)

private static native void
_read(long addr, short[] buf, int index, int length)

private static native void
_read(long addr, char[] buf, int index, int length)

private static native void
_read(long addr, int[] buf, int index, int length)

private static native void
_read(long addr, long[] buf, int index, int length)

private static native void
_read(long addr, float[] buf, int index, int length)

private static native void
_read(long addr, double[] buf, int index, int length)

private static native void
_setByte(long addr, byte value)

private static native void
_setChar(long addr, char value)

private static native void
_setDouble(long addr, double value)

private static native void
_setFloat(long addr, float value)

private static native void
_setInt(long addr, int value)

private static native void
_setLong(long addr, long value)

private static native void
_setMemory(long addr, long length, byte value)

private static native void
_setPointer(long addr, long value)

private static native void
_setShort(long addr, short value)

private static native void
_setString(long addr, String value, boolean wide)

private static native void
_write(long addr, byte[] buf, int index, int length)

private static native void
_write(long addr, short[] buf, int index, int length)

private static native void
_write(long addr, char[] buf, int index, int length)

private static native void
_write(long addr, int[] buf, int index, int length)

private static native void
_write(long addr, long[] buf, int index, int length)

private static native void
_write(long addr, float[] buf, int index, int length)

private static native void
_write(long addr, double[] buf, int index, int length)

pack-priv void
clear(long size)

Zero memory for the given number of bytes.

public static final Pointer
createConstant(long peer)

Convenience constant, equivalent to (void*)-1.

public boolean

Returns:

True if the other object is a Pointer, and the C pointers being pointed to by these objects are also equal. Returns false otherwise.
equals
(Object
A Pointer instance
o
)

Overrides java.lang.Object.equals.

Compares this Pointer to the specified object.
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)

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)

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)

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)

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)

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)

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, int arraySize)

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)

public String

Returns:

the String value being pointed to
getString
(long
byte offset from pointer to obtain the native string v * @param wide whether to convert from a wide or standard C string
offset
,
boolean wide)

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
)

Copy native memory to a Java String.

public int

Returns:

A hash code value for the represented native pointer
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hashcode for the native pointer represented by this Pointer 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 void
read(long
byte offset from pointer into which data is copied
offset
,
byte[]
byte array into which data is copied
buf
,
int
array index from which to start copying
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.

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
,
String
java.lang.String value to set
value
,
boolean
whether to write the native string as an array of wchar_t. If false, writes as a NUL-terminated array of char using the default platform encoding.
wide
)

Copy string value to the location being pointed to.

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 string value to the location being pointed to.

public Pointer
share(long offset)

public Pointer
share(long offset, long sz)

Provide a view of this pointer with a different peer base.

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.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait