be.cardon.nativecall
Class LowLevelCalls

java.lang.Object
  extended by be.cardon.nativecall.LowLevelCalls

public class LowLevelCalls
extends java.lang.Object

Functions to allocate, delete, read or write some native types int, boolean, byte, UTF-8 String, etc.

This class uses the Java Native Interface.

Note : In native object on Intel x386 processors, muliple byte values are encoded in little endian (first byte is the least significant byte) while Java use big endiang encoding (first byte is the most significant byte). The functions in this class don't convert the byte arrays. Use be.cardon.utils to reverse small byte arrays (this function use a copy of the array, so don't use it for big arrays).


Constructor Summary
LowLevelCalls()
          Creates a new instance of {code LowLevelCalls} The library nativecall is statically loaded when the first instance of {code LowLevelCalls} is created.
 
Method Summary
 int allocAndCopyBytes(byte[] data)
          Allocates memory and copies the given byte array.
 int allocBytes(int numberOfBytes)
          Allocates memory.
 void deleteAllocatedData(int firstByteAddress)
          Delete the allocated data.
 boolean readBoolean(int BooleanAddress)
          Read a boolean at the given address
 byte readByte(int ByteAddress)
          Read one byte.
 byte[] readBytes(int firstByteAddress, int numberOfBytes)
          Read a byte array.
 int readInt(int IntAddress)
          Read a signed integer (32 bits) at the given address
 short readShort(int IntAddress)
          Read a signed short (16 bits) at the given address
 java.lang.String readUnicodeString(int StringAddress)
          Read a MS UNICODE String at the given address
 java.lang.String readUTFString(int StringAddress)
          Read a UTF-8 String at the given address
 void writeBoolean(int BooleanAddress, boolean bool)
          Write a boolean at the given address
 void writeBytes(int firstByteAddress, byte[] bytes)
          Write bytes.
 void writeBytesSecure(int firstByteAddress, byte[] bytes, int max)
          Write maximal max bytes.
 void writeInt(int IntAddress, int value)
          Write a signed integer (32 bits) at the given address
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LowLevelCalls

public LowLevelCalls()
              throws NativeCallException
Creates a new instance of {code LowLevelCalls} The library nativecall is statically loaded when the first instance of {code LowLevelCalls} is created.

Throws:
NativeCallException
Method Detail

readInt

public int readInt(int IntAddress)
            throws NativeCallException
Read a signed integer (32 bits) at the given address

Throws:
NativeCallException

writeInt

public void writeInt(int IntAddress,
                     int value)
              throws NativeCallException
Write a signed integer (32 bits) at the given address

Throws:
NativeCallException

readShort

public short readShort(int IntAddress)
                throws NativeCallException
Read a signed short (16 bits) at the given address

Throws:
NativeCallException

readUTFString

public java.lang.String readUTFString(int StringAddress)
                               throws NativeCallException
Read a UTF-8 String at the given address

Throws:
NativeCallException

readUnicodeString

public java.lang.String readUnicodeString(int StringAddress)
                                   throws NativeCallException
Read a MS UNICODE String at the given address

Throws:
NativeCallException

readBoolean

public boolean readBoolean(int BooleanAddress)
                    throws NativeCallException
Read a boolean at the given address

Throws:
NativeCallException

writeBoolean

public void writeBoolean(int BooleanAddress,
                         boolean bool)
                  throws NativeCallException
Write a boolean at the given address

Throws:
NativeCallException

readBytes

public byte[] readBytes(int firstByteAddress,
                        int numberOfBytes)
                 throws NativeCallException
Read a byte array. See the note about byte order in this class description.

Throws:
NativeCallException

readByte

public byte readByte(int ByteAddress)
              throws NativeCallException
Read one byte.

Throws:
NativeCallException

allocAndCopyBytes

public int allocAndCopyBytes(byte[] data)
                      throws NativeCallException
Allocates memory and copies the given byte array. See the note about byte order in this class description.

Returns:
Address of the first byte.
Throws:
NativeCallException

allocBytes

public int allocBytes(int numberOfBytes)
               throws NativeCallException
Allocates memory. The JNI C function used the malloc function of the standard C library.

Parameters:
numberOfBytes - Size of the allocated memory in bytes.
Returns:
Address of the first byte.
Throws:
NativeCallException

deleteAllocatedData

public void deleteAllocatedData(int firstByteAddress)
                         throws NativeCallException
Delete the allocated data. The JNI C function used the delete function of the standard C library.

Throws:
NativeCallException

writeBytesSecure

public void writeBytesSecure(int firstByteAddress,
                             byte[] bytes,
                             int max)
                      throws NativeCallException
Write maximal max bytes. This is a secure version of writeBytes.

Throws:
NativeCallException - if bytes.length > max.

writeBytes

public void writeBytes(int firstByteAddress,
                       byte[] bytes)
                throws NativeCallException
Write bytes.

Throws:
NativeCallException