org.jnetpcap.nio
Class JNumber

java.lang.Object
  extended by org.jnetpcap.nio.JMemory
      extended by org.jnetpcap.nio.JNumber

public class JNumber
extends JMemory

A peered number pointer class that stores and retrieves number values from native/direct memory locations. This class facilitates exchange of number values (from bytes to doubles) to various native functions. The key being that these numbers at JNI level can be passed in as pointers and thus allows natives methods to both send and receive values between native and java space. The methods are named similarly like java.lang.Number class, with the exception of existance of setter methods.

Typical usage for JNumber is to use it wherever a function requests a primitive type pointer.

Author:
Mark Bednarczyk, Sly Technologies, Inc.

Nested Class Summary
static class JNumber.Type
          Used to request a specific type of primitive that this number will be dealing with possibly allocating memory more efficiently to fit the primitive type.
 
Field Summary
 
Fields inherited from class org.jnetpcap.nio.JMemory
JNETPCAP_LIBRARY_NAME, MAX_DIRECT_MEMORY_DEFAULT, POINTER
 
Constructor Summary
JNumber()
          Allocates a JNumber object capable of storing the biggest primitive on this platform.
JNumber(JMemory.Type type)
          Creates a number pointer, which does not allocate any memory on its own, but needs to be peered with primitive pointer.
JNumber(JNumber.Type type)
          Allocates a number of the specified size and type.
 
Method Summary
 byte byteValue()
          Gets value from native memory.
 void byteValue(byte value)
          Sets new value in native memory.
 double doubleValue()
          Gets value from native memory.
 void doubleValue(double value)
          Sets new value in native memory.
 float floatValue()
          Gets value from native memory.
 void floatValue(float value)
          Sets new value in native memory.
 int intValue()
          Returns the data from this JNUmber as a signed integer.
 void intValue(int value)
          Sets new value in native memory.
 long longValue()
          Gets value from native memory.
 void longValue(long value)
          Sets new value in native memory.
 int peer(JBuffer buffer)
          Peers with supplied buffer object.
 int peer(JBuffer buffer, int offset)
          Peers with supplied buffer object.
 int peer(JNumber number)
          Peers with supplied number object.
 short shortValue()
          Gets value from native memory.
 void shortValue(short value)
          Sets new value in native memory.
 int transferFrom(java.nio.ByteBuffer buffer)
          Copies data out of the supplied buffer into this number object.
 
Methods inherited from class org.jnetpcap.nio.JMemory
availableDirectMemory, check, cleanup, createReference, isInitialized, isJMemoryBasedOwner, isOwner, maxDirectMemory, peer, peer, peer, reservedDirectMemory, setSize, size, softDirectMemory, toDebugString, toHexdump, toHexdump, totalActiveAllocated, totalAllocateCalls, totalAllocated, totalAllocatedSegments0To255Bytes, totalAllocatedSegments256OrAbove, totalDeAllocateCalls, totalDeAllocated, transferFrom, transferFrom, transferFrom, transferFromDirect, transferOwnership, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo, transferTo0
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JNumber

public JNumber()
Allocates a JNumber object capable of storing the biggest primitive on this platform.


JNumber

public JNumber(JNumber.Type type)
Allocates a number of the specified size and type.

Parameters:
type - primitive type for which to allocate memory

JNumber

public JNumber(JMemory.Type type)
Creates a number pointer, which does not allocate any memory on its own, but needs to be peered with primitive pointer.

Parameters:
type - memory model
Method Detail

intValue

public int intValue()
Returns the data from this JNUmber as a signed integer.

Returns:
java signed integer

intValue

public void intValue(int value)
Sets new value in native memory.

Parameters:
value - new value

byteValue

public byte byteValue()
Gets value from native memory.

Returns:
java signed byte

byteValue

public void byteValue(byte value)
Sets new value in native memory.

Parameters:
value - new value

shortValue

public short shortValue()
Gets value from native memory.

Returns:
java signed short

shortValue

public void shortValue(short value)
Sets new value in native memory.

Parameters:
value - new value

longValue

public long longValue()
Gets value from native memory.

Returns:
java signed long

longValue

public void longValue(long value)
Sets new value in native memory.

Parameters:
value - new value

floatValue

public float floatValue()
Gets value from native memory.

Returns:
java float

floatValue

public void floatValue(float value)
Sets new value in native memory.

Parameters:
value - new value

doubleValue

public double doubleValue()
Gets value from native memory.

Returns:
java double float

doubleValue

public void doubleValue(double value)
Sets new value in native memory.

Parameters:
value - new value

peer

public int peer(JNumber number)
Peers with supplied number object.

Parameters:
number - number object to peer with
Returns:
number of bytes peered

peer

public int peer(JBuffer buffer)
Peers with supplied buffer object.

Parameters:
buffer - buffer to peer with
Returns:
number of bytes peered

peer

public int peer(JBuffer buffer,
                int offset)
Peers with supplied buffer object.

Parameters:
buffer - buffer to peer with
offset - offset into supplied buffer
Returns:
number of bytes peered

transferFrom

public int transferFrom(java.nio.ByteBuffer buffer)
Copies data out of the supplied buffer into this number object.

Overrides:
transferFrom in class JMemory
Parameters:
buffer - buffer to copy data out of. Buffer's position and limit properties set the bounds for the copy
Returns:
number of bytes copied