Package com.sun.jna
Class Pointer
- java.lang.Object
- 
- com.sun.jna.Pointer
 
- 
 public class Pointer extends java.lang.ObjectAn 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 aswrite,read,getXXX, andsetXXX, 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. - Author:
- Sheng Liang, originator, Todd Fast, suitability modifications, Timothy Wall, robust library loading
- See Also:
- Function
 
- 
- 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear(long size)Zero memory for the given number of bytes.static PointercreateConstant(int peer)Convenience constant, equivalent to(void*)CONSTANT.static PointercreateConstant(long peer)Convenience constant, equivalent to(void*)CONSTANT.java.lang.Stringdump(long offset, int size)Dump memory for debugging purposes.booleanequals(java.lang.Object o)bytegetByte(long offset)Indirect the native pointer as a pointer tobyte.byte[]getByteArray(long offset, int arraySize)java.nio.ByteBuffergetByteBuffer(long offset, long length)Get a ByteBuffer mapped to the memory pointed to by the pointer, ensuring the buffer uses native byte order.chargetChar(long offset)Indirect the native pointer as a pointer towchar_t.char[]getCharArray(long offset, int arraySize)doublegetDouble(long offset)Indirect the native pointer as a pointer todouble.double[]getDoubleArray(long offset, int arraySize)floatgetFloat(long offset)Indirect the native pointer as a pointer tofloat.float[]getFloatArray(long offset, int arraySize)intgetInt(long offset)Indirect the native pointer as a pointer toint.int[]getIntArray(long offset, int arraySize)longgetLong(long offset)Indirect the native pointer as a pointer tolong.long[]getLongArray(long offset, int arraySize)NativeLonggetNativeLong(long offset)Indirect the native pointer as a pointer tolong.PointergetPointer(long offset)Indirect the native pointer as a pointer to pointer.Pointer[]getPointerArray(long offset)Returns an array ofPointer.Pointer[]getPointerArray(long offset, int arraySize)Returns an array ofPointerof the requested size.shortgetShort(long offset)Indirect the native pointer as a pointer toshort.short[]getShortArray(long offset, int arraySize)java.lang.StringgetString(long offset)Copy native memory to a Java String.java.lang.StringgetString(long offset, java.lang.String encoding)Copy native memory to a Java String using the requested encoding.java.lang.String[]getStringArray(long offset)Returns an array ofStringbased on a native array ofchar *.java.lang.String[]getStringArray(long offset, int length)Returns an array ofStringbased on a native array ofchar *, using the given array length.java.lang.String[]getStringArray(long offset, int length, java.lang.String encoding)Returns an array ofStringbased on a native array ofchar*orwchar_t*based on thewideparameter, using the given array length.java.lang.String[]getStringArray(long offset, java.lang.String encoding)Returns an array ofStringbased on a native array ofchar *, using the requested encoding.(package private) java.lang.ObjectgetValue(long offset, java.lang.Class<?> type, java.lang.Object currentValue)java.lang.StringgetWideString(long offset)Read a wide (const wchar_t *) string from memory.java.lang.String[]getWideStringArray(long offset)java.lang.String[]getWideStringArray(long offset, int length)inthashCode()longindexOf(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 longnativeValue(Pointer p)Read the native peer value.static voidnativeValue(Pointer p, long value)Set the native peer value.voidread(long offset, byte[] buf, int index, int length)Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.voidread(long offset, char[] buf, int index, int length)Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.voidread(long offset, double[] buf, int index, int length)Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.voidread(long offset, float[] buf, int index, int length)Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.voidread(long offset, int[] buf, int index, int length)Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.voidread(long offset, long[] buf, int index, int length)Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.voidread(long offset, short[] buf, int index, int length)Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.voidread(long offset, Pointer[] buf, int index, int length)Indirect the native pointer, copying from memory pointed to by native pointer, into the specified array.voidsetByte(long offset, byte value)Setvalueat location being pointed to.voidsetChar(long offset, char value)Setvalueat location being pointed to.voidsetDouble(long offset, double value)Setvalueat location being pointed to.voidsetFloat(long offset, float value)Setvalueat location being pointed to.voidsetInt(long offset, int value)Setvalueat location being pointed to.voidsetLong(long offset, long value)Setvalueat location being pointed to.voidsetMemory(long offset, long length, byte value)Writevalueto the requested bank of memory.voidsetNativeLong(long offset, NativeLong value)Setvalueat location being pointed to.voidsetPointer(long offset, Pointer value)Setvalueat location being pointed to.voidsetShort(long offset, short value)Setvalueat location being pointed to.voidsetString(long offset, WString value)Copy stringvalueto the location being pointed to as a wide string (wchar_t*).voidsetString(long offset, java.lang.String value)Copy bytes out of stringvalueto the location being pointed to, using the encoding indicated byNative.getDefaultStringEncoding().voidsetString(long offset, java.lang.String value, java.lang.String encoding)Copy stringvalueto the location being pointed to, using the requested encoding.(package private) voidsetValue(long offset, java.lang.Object value, java.lang.Class<?> type)voidsetWideString(long offset, java.lang.String value)Copy stringvalueto the location being pointed to as a wide string (wchar_t*).Pointershare(long offset)Provide a view of this memory using the given offset to calculate a new base address.Pointershare(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.java.lang.StringtoString()voidwrite(long offset, byte[] buf, int index, int length)Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.voidwrite(long offset, char[] buf, int index, int length)Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.voidwrite(long offset, double[] buf, int index, int length)Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.voidwrite(long offset, float[] buf, int index, int length)Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.voidwrite(long offset, int[] buf, int index, int length)Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.voidwrite(long offset, long[] buf, int index, int length)Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.voidwrite(long offset, short[] buf, int index, int length)Indirect the native pointer, copying into memory pointed to by native pointer, from the specified array.voidwrite(long bOff, Pointer[] buf, int index, int length)Write the given array of Pointer to native memory.
 
- 
- 
- 
Field Detail- 
NULLpublic static final Pointer NULL Convenience constant, same asnull.
 - 
peerprotected long peer Pointer value of the real native pointer. Use long to be 64-bit safe.
 
- 
 - 
Method Detail- 
createConstantpublic static final Pointer createConstant(long peer) Convenience constant, equivalent to(void*)CONSTANT.
 - 
createConstantpublic static final Pointer createConstant(int peer) Convenience constant, equivalent to(void*)CONSTANT. This version will avoid setting any of the high bits on 64-bit systems.
 - 
sharepublic Pointer share(long offset) Provide a view of this memory using the given offset to calculate a new base address.
 - 
sharepublic 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.
 - 
clearpublic void clear(long size) Zero memory for the given number of bytes.
 - 
equalspublic boolean equals(java.lang.Object o) - Overrides:
- equalsin class- java.lang.Object
 
 - 
hashCodepublic int hashCode() - Overrides:
- hashCodein class- java.lang.Object
 
 - 
indexOfpublic 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.
 - 
readpublic 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.- Parameters:
- offset- byte offset from pointer from which data is copied
- buf-- bytearray into which data is copied
- index- array index to which data is copied
- length- number of elements from native pointer that must be copied
 
 - 
readpublic 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.- Parameters:
- offset- byte offset from pointer from which data is copied
- buf-- shortarray into which data is copied
- index- array index to which data is copied
- length- number of elements from native pointer that must be copied
 
 - 
readpublic 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.- Parameters:
- offset- byte offset from pointer from which data is copied
- buf-- chararray into which data is copied
- index- array index to which data is copied
- length- number of elements from native pointer that must be copied
 
 - 
readpublic 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.- Parameters:
- offset- byte offset from pointer from which data is copied
- buf-- intarray into which data is copied
- index- array index to which data is copied
- length- number of elements from native pointer that must be copied
 
 - 
readpublic 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.- Parameters:
- offset- byte offset from pointer from which data is copied
- buf-- longarray into which data is copied
- index- array index to which data is copied
- length- number of elements from native pointer that must be copied
 
 - 
readpublic 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.- Parameters:
- offset- byte offset from pointer from which data is copied
- buf-- floatarray into which data is copied
- index- array index to which data is copied
- length- number of elements from native pointer that must be copied
 
 - 
readpublic 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.- Parameters:
- offset- byte offset from pointer from which data is copied
- buf-- doublearray into which data is copied
- index- array index to which data is copied
- length- number of elements from native pointer that must be copied
 
 - 
readpublic 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.- Parameters:
- offset- byte offset from pointer from which data is copied
- buf-- Pointerarray into which data is copied
- index- array index to which data is copied
- length- number of elements from native pointer that must be copied
 
 - 
writepublic 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.- Parameters:
- offset- byte offset from pointer into which data is copied
- buf-- bytearray from which to copy
- index- array index from which to start copying
- length- number of elements from- bufthat must be copied
 
 - 
writepublic 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.- Parameters:
- offset- byte offset from pointer into which data is copied
- buf-- shortarray from which to copy
- index- array index from which to start copying
- length- number of elements from- bufthat must be copied
 
 - 
writepublic 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.- Parameters:
- offset- byte offset from pointer into which data is copied
- buf-- chararray from which to copy
- index- array index from which to start copying
- length- number of elements from- bufthat must be copied
 
 - 
writepublic 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.- Parameters:
- offset- byte offset from pointer into which data is copied
- buf-- intarray from which to copy
- index- array index from which to start copying
- length- number of elements from- bufthat must be copied
 
 - 
writepublic 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.- Parameters:
- offset- byte offset from pointer into which data is copied
- buf-- longarray from which to copy
- index- array index from which to start copying
- length- number of elements from- bufthat must be copied
 
 - 
writepublic 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.- Parameters:
- offset- byte offset from pointer into which data is copied
- buf-- floatarray from which to copy
- index- array index from which to start copying
- length- number of elements from- bufthat must be copied
 
 - 
writepublic 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.- Parameters:
- offset- byte offset from pointer into which data is copied
- buf-- doublearray from which to copy
- index- array index from which to start copying
- length- number of elements from- bufthat must be copied
 
 - 
writepublic void write(long bOff, Pointer[] buf, int index, int length)Write the given array of Pointer to native memory.- Parameters:
- bOff- byte offset from pointer into which data is copied
- buf-- Pointerarray from which to copy
- index- array index from which to start copying
- length- number of elements from- bufthat must be copied
 
 - 
getValuejava.lang.Object getValue(long offset, java.lang.Class<?> type, java.lang.Object currentValue)
 - 
getBytepublic byte getByte(long offset) Indirect the native pointer as a pointer tobyte. This is equivalent to the expression*((jbyte *)((char *)Pointer + offset)).- Parameters:
- offset- offset from pointer to perform the indirection
- Returns:
- the bytevalue being pointed to
 
 - 
getCharpublic char getChar(long offset) Indirect the native pointer as a pointer towchar_t. This is equivalent to the expression*((wchar_t*)((char *)Pointer + offset)).- Parameters:
- offset- offset from pointer to perform the indirection
- Returns:
- the wchar_tvalue being pointed to
 
 - 
getShortpublic short getShort(long offset) Indirect the native pointer as a pointer toshort. This is equivalent to the expression*((jshort *)((char *)Pointer + offset)).- Parameters:
- offset- byte offset from pointer to perform the indirection
- Returns:
- the shortvalue being pointed to
 
 - 
getIntpublic int getInt(long offset) Indirect the native pointer as a pointer toint. This is equivalent to the expression*((jint *)((char *)Pointer + offset)).- Parameters:
- offset- byte offset from pointer to perform the indirection
- Returns:
- the intvalue being pointed to
 
 - 
getLongpublic long getLong(long offset) Indirect the native pointer as a pointer tolong. This is equivalent to the expression*((jlong *)((char *)Pointer + offset)).- Parameters:
- offset- byte offset from pointer to perform the indirection
- Returns:
- the longvalue being pointed to
 
 - 
getNativeLongpublic NativeLong getNativeLong(long offset) Indirect the native pointer as a pointer tolong. This is equivalent to the expression*((long *)((char *)Pointer + offset)).- Parameters:
- offset- byte offset from pointer to perform the indirection
- Returns:
- the longvalue being pointed to
 
 - 
getFloatpublic float getFloat(long offset) Indirect the native pointer as a pointer tofloat. This is equivalent to the expression*((jfloat *)((char *)Pointer + offset)).- Parameters:
- offset- byte offset from pointer to perform the indirection
- Returns:
- the floatvalue being pointed to
 
 - 
getDoublepublic double getDouble(long offset) Indirect the native pointer as a pointer todouble. This is equivalent to the expression*((jdouble *)((char *)Pointer + offset)).- Parameters:
- offset- byte offset from pointer to perform the indirection
- Returns:
- the doublevalue being pointed to
 
 - 
getPointerpublic Pointer getPointer(long offset) Indirect the native pointer as a pointer to pointer. This is equivalent to the expression*((void **)((char *)Pointer + offset)).- Parameters:
- offset- byte offset from pointer to perform the indirection
- Returns:
- a Pointerequivalent of the pointer value being pointed to, ornullif the pointer value isNULL;
 
 - 
getByteBufferpublic java.nio.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.- Parameters:
- offset- byte offset from pointer to start the buffer
- length- Length of ByteBuffer
- Returns:
- a direct ByteBuffer that accesses the memory being pointed to,
 
 - 
getWideStringpublic java.lang.String getWideString(long offset) Read a wide (const wchar_t *) string from memory.
 - 
getStringpublic java.lang.String getString(long offset) Copy native memory to a Java String. The encoding used is obtained formNative.getDefaultStringEncoding().- Parameters:
- offset- byte offset from pointer to start reading bytes
- Returns:
- the Stringvalue being pointed to
 
 - 
getStringpublic java.lang.String getString(long offset, java.lang.String encoding)Copy native memory to a Java String using the requested encoding.- Parameters:
- offset- byte offset from pointer to obtain the native string
- encoding- the desired encoding
- Returns:
- the Stringvalue being pointed to
 
 - 
getByteArraypublic byte[] getByteArray(long offset, int arraySize)
 - 
getCharArraypublic char[] getCharArray(long offset, int arraySize)
 - 
getShortArraypublic short[] getShortArray(long offset, int arraySize)
 - 
getIntArraypublic int[] getIntArray(long offset, int arraySize)
 - 
getLongArraypublic long[] getLongArray(long offset, int arraySize)
 - 
getFloatArraypublic float[] getFloatArray(long offset, int arraySize)
 - 
getDoubleArraypublic double[] getDoubleArray(long offset, int arraySize)
 - 
getPointerArraypublic Pointer[] getPointerArray(long offset) Returns an array ofPointer. The array length is determined by a NULL-valued terminating element.
 - 
getPointerArraypublic Pointer[] getPointerArray(long offset, int arraySize) Returns an array ofPointerof the requested size.
 - 
getStringArraypublic java.lang.String[] getStringArray(long offset) Returns an array of The strings are decoded using the encoding returned byStringbased on a native array ofchar *. The array length is determined by a NULL-valued terminating element.Native.getDefaultStringEncoding().
 - 
getStringArraypublic java.lang.String[] getStringArray(long offset, java.lang.String encoding)Returns an array ofStringbased on a native array ofchar *, using the requested encoding. The array length is determined by a NULL-valued terminating element.
 - 
getStringArraypublic java.lang.String[] getStringArray(long offset, int length)Returns an array of The strings are decoded using the encoding returned byStringbased on a native array ofchar *, using the given array length.Native.getDefaultStringEncoding().
 - 
getWideStringArraypublic java.lang.String[] getWideStringArray(long offset) 
 - 
getWideStringArraypublic java.lang.String[] getWideStringArray(long offset, int length)
 - 
getStringArraypublic java.lang.String[] getStringArray(long offset, int length, java.lang.String encoding)Returns an array ofStringbased on a native array ofchar*orwchar_t*based on thewideparameter, using the given array length.- Parameters:
- offset-
- length-
- encoding-
 
 - 
setValuevoid setValue(long offset, java.lang.Object value, java.lang.Class<?> type)
 - 
setMemorypublic void setMemory(long offset, long length, byte value)Writevalueto the requested bank of memory.- Parameters:
- offset- byte offset from pointer to start
- length- number of bytes to write
- value- value to be written
 
 - 
setBytepublic void setByte(long offset, byte value)Setvalueat location being pointed to. This is equivalent to the expression*((jbyte *)((char *)Pointer + offset)) = value.- Parameters:
- offset- byte offset from pointer at which- valuemust be set
- value-- bytevalue to set
 
 - 
setShortpublic void setShort(long offset, short value)Setvalueat location being pointed to. This is equivalent to the expression*((jshort *)((char *)Pointer + offset)) = value.- Parameters:
- offset- byte offset from pointer at which- valuemust be set
- value-- shortvalue to set
 
 - 
setCharpublic void setChar(long offset, char value)Setvalueat location being pointed to. This is equivalent to the expression*((wchar_t *)((char *)Pointer + offset)) = value.- Parameters:
- offset- byte offset from pointer at which- valuemust be set
- value-- charvalue to set
 
 - 
setIntpublic void setInt(long offset, int value)Setvalueat location being pointed to. This is equivalent to the expression*((jint *)((char *)Pointer + offset)) = value.- Parameters:
- offset- byte offset from pointer at which- valuemust be set
- value-- intvalue to set
 
 - 
setLongpublic void setLong(long offset, long value)Setvalueat location being pointed to. This is equivalent to the expression*((jlong *)((char *)Pointer + offset)) = value.- Parameters:
- offset- byte offset from pointer at which- valuemust be set
- value-- longvalue to set
 
 - 
setNativeLongpublic void setNativeLong(long offset, NativeLong value)Setvalueat location being pointed to. This is equivalent to the expression*((long *)((char *)Pointer + offset)) = value.- Parameters:
- offset- byte offset from pointer at which- valuemust be set
- value-- longvalue to set
 
 - 
setFloatpublic void setFloat(long offset, float value)Setvalueat location being pointed to. This is equivalent to the expression*((jfloat *)((char *)Pointer + offset)) = value.- Parameters:
- offset- byte offset from pointer at which- valuemust be set
- value-- floatvalue to set
 
 - 
setDoublepublic void setDouble(long offset, double value)Setvalueat location being pointed to. This is equivalent to the expression*((jdouble *)((char *)Pointer + offset)) = value.- Parameters:
- offset- byte offset from pointer at which- valuemust be set
- value-- doublevalue to set
 
 - 
setPointerpublic void setPointer(long offset, Pointer value)Setvalueat location being pointed to. This is equivalent to the expression*((void **)((char *)Pointer + offset)) = value.- Parameters:
- offset- byte offset from pointer at which- valuemust be set
- value-- Pointerholding the actual pointer value to set, which may be- nullto indicate a- NULLpointer.
 
 - 
setWideStringpublic void setWideString(long offset, java.lang.String value)Copy stringvalueto the location being pointed to as a wide string (wchar_t*).- Parameters:
- offset- byte offset from pointer at which characters in- valuemust be set
- value-- java.lang.Stringvalue to set
 
 - 
setStringpublic void setString(long offset, WString value)Copy stringvalueto the location being pointed to as a wide string (wchar_t*).- Parameters:
- offset- byte offset from pointer at which characters in- valuemust be set
- value-- WStringvalue to set
 
 - 
setStringpublic void setString(long offset, java.lang.String value)Copy bytes out of stringvalueto the location being pointed to, using the encoding indicated byNative.getDefaultStringEncoding().- Parameters:
- offset- byte offset from pointer at which characters in- valuemust be set
- value-- java.lang.Stringvalue to set
 
 - 
setStringpublic void setString(long offset, java.lang.String value, java.lang.String encoding)Copy stringvalueto the location being pointed to, using the requested encoding.- Parameters:
- offset- byte offset from pointer at which characters in- valuemust be set
- value-- java.lang.Stringvalue to set
- encoding- desired encoding
 
 - 
dumppublic java.lang.String dump(long offset, int size)Dump memory for debugging purposes.
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
nativeValuepublic static long nativeValue(Pointer p) Read the native peer value. Use with caution.
 - 
nativeValuepublic static void nativeValue(Pointer p, long value) Set the native peer value. Use with caution.
 
- 
 
-