JNative project : see http://jnative.sf.net


org.xvolks.jnative.pointers
Class Pointer

java.lang.Object
  extended by org.xvolks.jnative.pointers.Pointer
Direct Known Subclasses:
NullPointer

public class Pointer
extends java.lang.Object

$Id: Pointer.java,v 1.4 2006/01/14 19:27:01 mdenty Exp $;

This class encapsulate a native pointer.

To create a pointer you should first create a memory block that can be addressed by this Pointer. See org.xvolks.jnative.pointers.memory.MemoryBlockFactory

A Pointer can also be obtained by using a Structure (BasicData) or one of its concreate implementation (LONG, MemoryStatusEx...) with the method BasicData.createPointer().

See Also:
MemoryBlockFactory,
This software is released under the GPL.

Constructor Summary
Pointer(MemoryBlock mem)
          Constructor : allocates size memory block in the native side
 
Method Summary
 void dispose()
          Method dispose frees the memory addressed by this pointer
protected  void finalize()
          Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
 byte getAsByte(int offset)
          Method getAsByte
 int getAsInt(int offset)
          Method getAsInt
 long getAsLong(int offset)
          Method getAsLong
 short getAsShort(int offset)
          Method getAsShort
 java.lang.String getAsString()
          Method getAsString
 byte[] getMemory()
          Method getMemory
 int getPointer()
          Method getPointer
 int getSize()
          Method getSize
 int setByteAt(int offset, byte value)
          Method setByteAt
 int setIntAt(int offset, int value)
          Method setIntAt
 int setLongAt(int offset, long value)
          Method setLongAt
 void setMemory(byte[] buffer)
          Method setMemory fills the native memory with the content of buffer
 void setMemory(java.lang.String buffer)
          Method setMemory fills the native memory with the content of buffer
 int setShortAt(int offset, short value)
          Method setShortAt
 int setStringAt(int offset, java.lang.String value)
          Method setStringAt
 void zeroMemory()
          Method zeroMemory performs a memset(pointer, 0)
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Pointer

public Pointer(MemoryBlock mem)
Constructor : allocates size memory block in the native side

Parameters:
size - : memory size to allocate
Method Detail

dispose

public void dispose()
             throws NativeException
Method dispose frees the memory addressed by this pointer

Throws:
NativeException

getPointer

public int getPointer()
Method getPointer

Returns:
the address of this pointer

getSize

public int getSize()
Method getSize

Returns:
the size of the memory block addressed by this pointer

setMemory

public void setMemory(java.lang.String buffer)
               throws NativeException,
                      java.lang.ArrayIndexOutOfBoundsException
Method setMemory fills the native memory with the content of buffer

Parameters:
buffer - the source to strcpy
Throws:
NativeException
java.lang.ArrayIndexOutOfBoundsException - if the size of the buffer is greater than the size of the native memory

setMemory

public void setMemory(byte[] buffer)
               throws NativeException
Method setMemory fills the native memory with the content of buffer

Parameters:
buffer - the source to memcpy
Throws:
NativeException
java.lang.ArrayIndexOutOfBoundsException - if the size of the buffer is greater than the size of the native memory

setByteAt

public int setByteAt(int offset,
                     byte value)
              throws NativeException
Method setByteAt

Parameters:
offset - int the native memory block
value - the byte to write
Returns:
the size of written data : here 1
Throws:
NativeException
java.lang.ArrayIndexOutOfBoundsException - if offset > size of the native buufer

setShortAt

public int setShortAt(int offset,
                      short value)
               throws NativeException
Method setShortAt

Parameters:
offset - int the native memory block
value - the short to write
Returns:
the size of written data : here 2
Throws:
NativeException
java.lang.ArrayIndexOutOfBoundsException - if offset + 2 > size of the native buufer

setIntAt

public int setIntAt(int offset,
                    int value)
             throws NativeException
Method setIntAt

Parameters:
offset - int the native memory block
value - the integer to write
Returns:
the size of written data : here 4
Throws:
NativeException
java.lang.ArrayIndexOutOfBoundsException - if offset + 4 > size of the native buufer

setLongAt

public int setLongAt(int offset,
                     long value)
              throws NativeException
Method setLongAt

Parameters:
offset - int the native memory block
value - the long to write
Returns:
the size of written data : here 8
Throws:
NativeException
java.lang.ArrayIndexOutOfBoundsException - if offset + 8 > size of the native buufer

setStringAt

public int setStringAt(int offset,
                       java.lang.String value)
                throws NativeException
Method setStringAt

Parameters:
offset - int the native memory block
value - the String to write
Returns:
the size of written data : here the length of value
Throws:
NativeException
java.lang.ArrayIndexOutOfBoundsException - if offset + len(value) > size of the native buufer

zeroMemory

public void zeroMemory()
                throws NativeException
Method zeroMemory performs a memset(pointer, 0)

Throws:
NativeException

getMemory

public byte[] getMemory()
                 throws NativeException
Method getMemory

Returns:
a copy of the native memory
Throws:
NativeException

getAsString

public java.lang.String getAsString()
                             throws NativeException
Method getAsString

Returns:
a copy of the native memory as String
Throws:
NativeException

getAsByte

public byte getAsByte(int offset)
               throws NativeException
Method getAsByte

Parameters:
offset -
Returns:
the byte at offset offset
Throws:
NativeException

getAsShort

public short getAsShort(int offset)
                 throws NativeException
Method getAsShort

Parameters:
offset - an int
Returns:
the short/WORD at offset offset
Throws:
NativeException

getAsInt

public int getAsInt(int offset)
             throws NativeException
Method getAsInt

Parameters:
offset - an int
Returns:
the int/DWORD at offset offset
Throws:
NativeException

getAsLong

public long getAsLong(int offset)
               throws NativeException
Method getAsLong

Parameters:
offset - an int
Returns:
the long/int64 at offset offset
Throws:
NativeException

finalize

protected void finalize()
                 throws java.lang.Throwable
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

The general contract of finalize is that it is invoked if and when the JavaTM virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Calls dispose()

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - the Exception raised by this method

JNative project : see http://jnative.sf.net