com.kenai.jaffl
Class MemoryIO

java.lang.Object
  extended by com.kenai.jaffl.MemoryIO
All Implemented Interfaces:
Pointer
Direct Known Subclasses:
AbstractMemoryIO

public abstract class MemoryIO
extends java.lang.Object
implements Pointer

Interface to reading/writing various types of memory


Field Summary
 
Fields inherited from interface com.kenai.jaffl.Pointer
SIZE
 
Constructor Summary
MemoryIO()
           
 
Method Summary
abstract  long address()
          Gets the native address of this memory object (optional operation).
static MemoryIO allocate(int size)
          Allocates a new block of java heap memory and wraps it in a MemoryIO accessor.
static MemoryIO allocateDirect(int size)
          Allocates a new block of native memory and wraps it in a MemoryIO accessor.
static MemoryIO allocateDirect(int size, boolean clear)
          Allocates a new block of native memory and wraps it in a MemoryIO accessor.
abstract  void get(long offset, byte[] dst, int idx, int len)
          Bulk byte get method.
abstract  void get(long offset, double[] dst, int idx, int len)
          Bulk double get method.
abstract  void get(long offset, float[] dst, int idx, int len)
          Bulk float get method.
abstract  void get(long offset, int[] dst, int idx, int len)
          Bulk int get method.
abstract  void get(long offset, long[] dst, int idx, int len)
          Bulk long get method.
abstract  void get(long offset, short[] dst, int idx, int len)
          Bulk short get method.
abstract  long getAddress(long offset)
           
abstract  byte getByte(long offset)
          Reads a 8 bit integer at the given offset.
abstract  double getDouble(long offset)
          Reads a 64 bit floating point value at the given offset.
abstract  float getFloat(long offset)
          Reads a 32 bit floating point value at the given offset.
abstract  int getInt(long offset)
          Reads a 32 bit integer at the given offset.
abstract  long getLong(long offset)
          Reads a 64 bit integer at the given offset.
abstract  MemoryIO getMemoryIO(long offset)
           
abstract  MemoryIO getMemoryIO(long offset, long size)
           
abstract  long getNativeLong(long offset)
           
abstract  Pointer getPointer(long offset)
           
abstract  short getShort(long offset)
          Reads a 16 bit integer at the given offset.
abstract  java.lang.String getString(long offset)
           
abstract  java.lang.String getString(long offset, int maxLength, java.nio.charset.Charset cs)
           
abstract  int indexOf(long offset, byte value)
           
abstract  int indexOf(long offset, byte value, int maxlen)
           
abstract  boolean isDirect()
          Tells whether or not this memory object is direct.
abstract  void put(long offset, byte[] src, int idx, int len)
          Bulk byte put method.
abstract  void put(long offset, double[] src, int idx, int len)
          Bulk double put method.
abstract  void put(long offset, float[] src, int idx, int len)
          Bulk float put method.
abstract  void put(long offset, int[] src, int idx, int len)
          Bulk int put method.
abstract  void put(long offset, long[] src, int idx, int len)
          Bulk long put method.
abstract  void put(long offset, short[] src, int idx, int len)
          Bulk short put method.
abstract  void putAddress(long offset, Address value)
           
abstract  void putAddress(long offset, long value)
           
abstract  void putByte(long offset, byte value)
          Writes an 8 bit integer value at the given offset.
abstract  void putDouble(long offset, double value)
          Writes a 64 bit floating point value at the given offset.
abstract  void putFloat(long offset, float value)
          Writes a 32 bit floating point value at the given offset.
abstract  void putInt(long offset, int value)
          Writes a 32 bit integer value at the given offset.
abstract  void putLong(long offset, long value)
          Writes a 64 bit integer value at the given offset.
abstract  void putNativeLong(long offset, long value)
           
abstract  void putPointer(long offset, Pointer value)
           
abstract  void putShort(long offset, short value)
          Writes a 16 bit integer value at the given offset.
abstract  void putString(long offset, java.lang.String string, int maxLength, java.nio.charset.Charset cs)
           
abstract  void setMemory(long offset, long size, byte value)
           
abstract  MemoryIO slice(long offset)
           
abstract  MemoryIO slice(long offset, long size)
           
abstract  void transferTo(long offset, MemoryIO other, long otherOffset, long count)
           
static MemoryIO wrap(java.nio.ByteBuffer buffer)
           
static MemoryIO wrap(Pointer ptr)
           
static MemoryIO wrap(Pointer ptr, int size)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryIO

public MemoryIO()
Method Detail

allocate

public static final MemoryIO allocate(int size)
Allocates a new block of java heap memory and wraps it in a MemoryIO accessor.

Parameters:
size - The size in bytes of memory to allocate.
Returns:
A new MemoryIO instance that can access the memory.

allocateDirect

public static final MemoryIO allocateDirect(int size)
Allocates a new block of native memory and wraps it in a MemoryIO accessor.

Parameters:
size - The size in bytes of memory to allocate.
Returns:
A new MemoryIO instance that can access the memory.

allocateDirect

public static final MemoryIO allocateDirect(int size,
                                            boolean clear)
Allocates a new block of native memory and wraps it in a MemoryIO accessor.

Parameters:
size - The size in bytes of memory to allocate.
clear - Whether the memory contents should be cleared, or left as random data.
Returns:
A new MemoryIO instance that can access the memory.

wrap

public static final MemoryIO wrap(Pointer ptr)

wrap

public static final MemoryIO wrap(Pointer ptr,
                                  int size)

wrap

public static final MemoryIO wrap(java.nio.ByteBuffer buffer)

getByte

public abstract byte getByte(long offset)
Reads a 8 bit integer at the given offset.

Specified by:
getByte in interface Pointer
Parameters:
offset - The offset from which the integer will be read.
Returns:
The byte value at the offset.

getShort

public abstract short getShort(long offset)
Reads a 16 bit integer at the given offset.

Specified by:
getShort in interface Pointer
Parameters:
offset - The offset from which the integer will be read.
Returns:
The short value at the offset.

getInt

public abstract int getInt(long offset)
Reads a 32 bit integer at the given offset.

Specified by:
getInt in interface Pointer
Parameters:
offset - The offset from which the integer will be read.
Returns:
The int value at the offset.

getLong

public abstract long getLong(long offset)
Reads a 64 bit integer at the given offset.

Specified by:
getLong in interface Pointer
Parameters:
offset - The offset from which the integer will be read.
Returns:
The long value at the offset.

getFloat

public abstract float getFloat(long offset)
Reads a 32 bit floating point value at the given offset.

Specified by:
getFloat in interface Pointer
Parameters:
offset - The offset from which the integer will be read.
Returns:
The float value at the offset.

getDouble

public abstract double getDouble(long offset)
Reads a 64 bit floating point value at the given offset.

Specified by:
getDouble in interface Pointer
Parameters:
offset - The offset from which the integer will be read.
Returns:
The double value at the offset.

putByte

public abstract void putByte(long offset,
                             byte value)
Writes an 8 bit integer value at the given offset.

Specified by:
putByte in interface Pointer
Parameters:
offset - The offset at which the value will be written.
value - The value to be written.

putShort

public abstract void putShort(long offset,
                              short value)
Writes a 16 bit integer value at the given offset.

Specified by:
putShort in interface Pointer
Parameters:
offset - The offset at which the value will be written.
value - The value to be written.

putInt

public abstract void putInt(long offset,
                            int value)
Writes a 32 bit integer value at the given offset.

Specified by:
putInt in interface Pointer
Parameters:
offset - The offset at which the value will be written.
value - The value to be written.

putLong

public abstract void putLong(long offset,
                             long value)
Writes a 64 bit integer value at the given offset.

Specified by:
putLong in interface Pointer
Parameters:
offset - The offset at which the value will be written.
value - The value to be written.

putFloat

public abstract void putFloat(long offset,
                              float value)
Writes a 32 bit floating point value at the given offset.

Specified by:
putFloat in interface Pointer
Parameters:
offset - The offset at which the value will be written.
value - The value to be written.

putDouble

public abstract void putDouble(long offset,
                               double value)
Writes a 64 bit floating point value at the given offset.

Specified by:
putDouble in interface Pointer
Parameters:
offset - The offset at which the value will be written.
value - The value to be written.

get

public abstract void get(long offset,
                         byte[] dst,
                         int idx,
                         int len)
Bulk byte get method. This method reads an array of bytes at the given offset into the given destination array.

Specified by:
get in interface Pointer
Parameters:
offset - The offset at which the values will be read.
dst - The array into which values are to be written.
idx - The index within the destination array of the first value to be written.
len - The number of values to be written to the destination array.

put

public abstract void put(long offset,
                         byte[] src,
                         int idx,
                         int len)
Bulk byte put method. This method writes an array of bytes at the given offset from the given source array.

Specified by:
put in interface Pointer
Parameters:
offset - The offset at which the values will be written.
src - The source array from which values are to be read.
idx - The index within the destination array of the first value to be read.
len - The number of values to be read from the source array.

get

public abstract void get(long offset,
                         short[] dst,
                         int idx,
                         int len)
Bulk short get method. This method reads an array of 16 bit integers at the given offset into the given destination array.

Specified by:
get in interface Pointer
Parameters:
offset - The offset at which the values will be read.
dst - The array into which values are to be written.
idx - The index within the destination array of the first value to be written.
len - The number of values to be written to the destination array.

put

public abstract void put(long offset,
                         short[] src,
                         int idx,
                         int len)
Bulk short put method. This method writes an array of 16 bit integers at the given offset from the given array.

Specified by:
put in interface Pointer
Parameters:
offset - The offset at which the values will be written.
src - The source array from which values are to be read.
idx - The index within the destination array of the first value to be read.
len - The number of values to be read from the source array.

get

public abstract void get(long offset,
                         int[] dst,
                         int idx,
                         int len)
Bulk int get method. This method reads an array of 32 bit integers at the given offset into the given destination array.

Specified by:
get in interface Pointer
Parameters:
offset - The offset at which the values will be read.
dst - The array into which values are to be written.
idx - The index within the destination array of the first value to be written.
len - The number of values to be written to the destination array.

put

public abstract void put(long offset,
                         int[] src,
                         int idx,
                         int len)
Bulk int put method. This method writes an array of 32 bit integers at the given offset from the given array.

Specified by:
put in interface Pointer
Parameters:
offset - The offset at which the values will be written.
src - The source array from which values are to be read.
idx - The index within the destination array of the first value to be read.
len - The number of values to be read from the source array.

get

public abstract void get(long offset,
                         long[] dst,
                         int idx,
                         int len)
Bulk long get method. This method reads an array of 64 bit integers at the given offset into the given destination array.

Specified by:
get in interface Pointer
Parameters:
offset - The offset at which the values will be read.
dst - The array into which values are to be written.
idx - The index within the destination array of the first value to be written.
len - The number of values to be written to the destination array.

put

public abstract void put(long offset,
                         long[] src,
                         int idx,
                         int len)
Bulk long put method. This method writes an array of 64 bit integers at the given offset from the given array.

Specified by:
put in interface Pointer
Parameters:
offset - The offset at which the values will be written.
src - The source array from which values are to be read.
idx - The index within the destination array of the first value to be read.
len - The number of values to be read from the source array.

get

public abstract void get(long offset,
                         float[] dst,
                         int idx,
                         int len)
Bulk float get method. This method reads an array of 32 bit floats at the given offset into the given destination array.

Specified by:
get in interface Pointer
Parameters:
offset - The offset at which the values will be read.
dst - The array into which values are to be written.
idx - The index within the destination array of the first value to be written.
len - The number of values to be written to the destination array.

put

public abstract void put(long offset,
                         float[] src,
                         int idx,
                         int len)
Bulk float put method. This method writes an array of 32 bit floats at the given offset from the given array.

Specified by:
put in interface Pointer
Parameters:
offset - The offset at which the values will be written.
src - The source array from which values are to be read.
idx - The index within the destination array of the first value to be read.
len - The number of values to be read from the source array.

get

public abstract void get(long offset,
                         double[] dst,
                         int idx,
                         int len)
Bulk double get method. This method reads an array of 64 bit floats at the given offset into the given destination array.

Specified by:
get in interface Pointer
Parameters:
offset - The offset at which the values will be read.
dst - The array into which values are to be written.
idx - The index within the destination array of the first value to be written.
len - The number of values to be written to the destination array.

put

public abstract void put(long offset,
                         double[] src,
                         int idx,
                         int len)
Bulk double put method. This method writes an array of 64 bit floats at the given offset from the given array.

Specified by:
put in interface Pointer
Parameters:
offset - The offset at which the values will be written.
src - The source array from which values are to be read.
idx - The index within the destination array of the first value to be read.
len - The number of values to be read from the source array.

getMemoryIO

public abstract MemoryIO getMemoryIO(long offset)

getMemoryIO

public abstract MemoryIO getMemoryIO(long offset,
                                     long size)

getPointer

public abstract Pointer getPointer(long offset)
Specified by:
getPointer in interface Pointer

putPointer

public abstract void putPointer(long offset,
                                Pointer value)
Specified by:
putPointer in interface Pointer

indexOf

public abstract int indexOf(long offset,
                            byte value)

indexOf

public abstract int indexOf(long offset,
                            byte value,
                            int maxlen)

getAddress

public abstract long getAddress(long offset)

putAddress

public abstract void putAddress(long offset,
                                long value)

putAddress

public abstract void putAddress(long offset,
                                Address value)

getNativeLong

public abstract long getNativeLong(long offset)

putNativeLong

public abstract void putNativeLong(long offset,
                                   long value)

getString

public abstract java.lang.String getString(long offset,
                                           int maxLength,
                                           java.nio.charset.Charset cs)

getString

public abstract java.lang.String getString(long offset)
Specified by:
getString in interface Pointer

putString

public abstract void putString(long offset,
                               java.lang.String string,
                               int maxLength,
                               java.nio.charset.Charset cs)

slice

public abstract MemoryIO slice(long offset)

slice

public abstract MemoryIO slice(long offset,
                               long size)

transferTo

public abstract void transferTo(long offset,
                                MemoryIO other,
                                long otherOffset,
                                long count)

setMemory

public abstract void setMemory(long offset,
                               long size,
                               byte value)

isDirect

public abstract boolean isDirect()
Tells whether or not this memory object is direct. Memory objects can be either direct (representing native memory), or non-direct (representing java heap memory).

Specified by:
isDirect in interface Pointer
Returns:
true if, and only if, this memory object is direct

address

public abstract long address()
Gets the native address of this memory object (optional operation).

Specified by:
address in interface Pointer
Returns:
The native address of this memory object.
Throws:
java.lang.UnsupportedOperationException - If this memory object is not backed by native memory.