org.simantics.databoard.util.binary
Class BinaryMemory

java.lang.Object
  extended by org.simantics.databoard.util.binary.BinaryMemory
All Implemented Interfaces:
BinaryReadable, BinaryWriteable, RandomAccessBinary

public class BinaryMemory
extends java.lang.Object
implements RandomAccessBinary

Rancom access memory blob

Author:
Toni Kalajainen

Constructor Summary
BinaryMemory()
          New memory blob
BinaryMemory(byte[] data)
          New memory blob
BinaryMemory(java.nio.ByteBuffer buf)
          Assume an existing byte buffer
BinaryMemory(int initialSize)
          New memory blob
BinaryMemory(int initialSize, int increment)
          New memory blob
 
Method Summary
 void close()
          Flush and close the blob.
 void flush()
          Flush write buffer
 byte get()
           
 void get(byte[] dst)
           
 void get(byte[] dst, int offset, int length)
           
 void get(java.nio.ByteBuffer buf)
          Get buf fully
 void get(java.nio.ByteBuffer buf, int length)
          Get fully length bytes
 double getDouble()
           
 float getFloat()
           
 int getInt()
           
 long getLong()
           
 short getShort()
           
 void insertBytes(long bytes)
          Insert bytes at current pointer.
 long length()
          Get the length of the binary object.
 java.nio.ByteOrder order()
          Get byte order
 void order(java.nio.ByteOrder order)
          Set a new byte order
 long position()
          Get the position of the cursor
 void position(long newPosition)
          Set new cursor position.
 void put(byte b)
          Write a byte
 void put(byte[] src)
           
 void put(byte[] src, int offset, int length)
           
 void put(java.nio.ByteBuffer src)
          Put n bytes from the remaining of the byte array.
 void put(java.nio.ByteBuffer src, int length)
          Put n bytes from the remaining of the byte buffer.
 void put(java.io.InputStream is)
           
 void putDouble(double value)
           
 void putFloat(float value)
           
 void putInt(int value)
           
 void putLong(long value)
           
 void putShort(short value)
           
 void removeBytes(long bytes)
          Remove bytes from the position of the current pointer.
 void setLength(long newLength)
          Set length of the binary object.
 void skip(long bytes)
          Move pointer forward
 java.nio.ByteBuffer toByteBuffer()
          Get the backend byte buffer.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BinaryMemory

public BinaryMemory()
New memory blob


BinaryMemory

public BinaryMemory(byte[] data)
New memory blob


BinaryMemory

public BinaryMemory(int initialSize)
New memory blob


BinaryMemory

public BinaryMemory(int initialSize,
                    int increment)
New memory blob


BinaryMemory

public BinaryMemory(java.nio.ByteBuffer buf)
Assume an existing byte buffer

Parameters:
buf - buffer
Method Detail

toByteBuffer

public java.nio.ByteBuffer toByteBuffer()
Get the backend byte buffer. The result may change if BinaryMemory is written.

Returns:
byte buffer

close

public void close()
           throws java.io.IOException
Description copied from interface: RandomAccessBinary
Flush and close the blob.

Specified by:
close in interface RandomAccessBinary
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Description copied from interface: RandomAccessBinary
Flush write buffer

Specified by:
flush in interface BinaryWriteable
Specified by:
flush in interface RandomAccessBinary
Throws:
java.io.IOException

get

public byte get()
Specified by:
get in interface BinaryReadable
Specified by:
get in interface RandomAccessBinary

get

public void get(byte[] dst,
                int offset,
                int length)
Specified by:
get in interface BinaryReadable
Specified by:
get in interface RandomAccessBinary

get

public void get(byte[] dst)
Specified by:
get in interface BinaryReadable
Specified by:
get in interface RandomAccessBinary

get

public void get(java.nio.ByteBuffer buf)
Description copied from interface: RandomAccessBinary
Get buf fully

Specified by:
get in interface BinaryReadable
Specified by:
get in interface RandomAccessBinary

get

public void get(java.nio.ByteBuffer buf,
                int length)
Description copied from interface: RandomAccessBinary
Get fully length bytes

Specified by:
get in interface BinaryReadable
Specified by:
get in interface RandomAccessBinary

getDouble

public double getDouble()
Specified by:
getDouble in interface BinaryReadable
Specified by:
getDouble in interface RandomAccessBinary

getFloat

public float getFloat()
Specified by:
getFloat in interface BinaryReadable
Specified by:
getFloat in interface RandomAccessBinary

getInt

public int getInt()
Specified by:
getInt in interface BinaryReadable
Specified by:
getInt in interface RandomAccessBinary

getLong

public long getLong()
Specified by:
getLong in interface BinaryReadable
Specified by:
getLong in interface RandomAccessBinary

getShort

public short getShort()
Specified by:
getShort in interface BinaryReadable
Specified by:
getShort in interface RandomAccessBinary

length

public long length()
Description copied from interface: RandomAccessBinary
Get the length of the binary object.

Specified by:
length in interface BinaryReadable
Specified by:
length in interface RandomAccessBinary
Returns:
the length

position

public long position()
Description copied from interface: RandomAccessBinary
Get the position of the cursor

Specified by:
position in interface BinaryReadable
Specified by:
position in interface RandomAccessBinary
Returns:
cursor

position

public void position(long newPosition)
              throws java.io.IOException
Description copied from interface: RandomAccessBinary
Set new cursor position. The position can be set outside the binary object.

Specified by:
position in interface RandomAccessBinary
Throws:
java.io.IOException

order

public java.nio.ByteOrder order()
Description copied from interface: RandomAccessBinary
Get byte order

Specified by:
order in interface BinaryReadable
Specified by:
order in interface BinaryWriteable
Specified by:
order in interface RandomAccessBinary
Returns:
byte order

order

public void order(java.nio.ByteOrder order)
Description copied from interface: RandomAccessBinary
Set a new byte order

Specified by:
order in interface BinaryReadable
Specified by:
order in interface BinaryWriteable
Specified by:
order in interface RandomAccessBinary
Parameters:
order - new byte order

put

public void put(byte b)
         throws java.io.IOException
Description copied from interface: RandomAccessBinary
Write a byte

Specified by:
put in interface BinaryWriteable
Specified by:
put in interface RandomAccessBinary
Throws:
java.io.IOException

put

public void put(java.nio.ByteBuffer src)
         throws java.io.IOException
Description copied from interface: RandomAccessBinary
Put n bytes from the remaining of the byte array. This operation moves the pointer in byte buffer.

Specified by:
put in interface BinaryWriteable
Specified by:
put in interface RandomAccessBinary
Throws:
java.io.IOException

put

public void put(java.nio.ByteBuffer src,
                int length)
         throws java.io.IOException
Description copied from interface: RandomAccessBinary
Put n bytes from the remaining of the byte buffer. This operation moves the pointer in byte buffer.

Specified by:
put in interface BinaryWriteable
Specified by:
put in interface RandomAccessBinary
Throws:
java.io.IOException

put

public void put(java.io.InputStream is)
         throws java.io.IOException
Throws:
java.io.IOException

put

public void put(byte[] src,
                int offset,
                int length)
         throws java.io.IOException
Specified by:
put in interface BinaryWriteable
Specified by:
put in interface RandomAccessBinary
Throws:
java.io.IOException

put

public void put(byte[] src)
         throws java.io.IOException
Specified by:
put in interface BinaryWriteable
Specified by:
put in interface RandomAccessBinary
Throws:
java.io.IOException

putDouble

public void putDouble(double value)
               throws java.io.IOException
Specified by:
putDouble in interface BinaryWriteable
Specified by:
putDouble in interface RandomAccessBinary
Throws:
java.io.IOException

putFloat

public void putFloat(float value)
              throws java.io.IOException
Specified by:
putFloat in interface BinaryWriteable
Specified by:
putFloat in interface RandomAccessBinary
Throws:
java.io.IOException

putInt

public void putInt(int value)
            throws java.io.IOException
Specified by:
putInt in interface BinaryWriteable
Specified by:
putInt in interface RandomAccessBinary
Throws:
java.io.IOException

putLong

public void putLong(long value)
             throws java.io.IOException
Specified by:
putLong in interface BinaryWriteable
Specified by:
putLong in interface RandomAccessBinary
Throws:
java.io.IOException

putShort

public void putShort(short value)
              throws java.io.IOException
Specified by:
putShort in interface BinaryWriteable
Specified by:
putShort in interface RandomAccessBinary
Throws:
java.io.IOException

insertBytes

public void insertBytes(long bytes)
                 throws java.io.IOException
Description copied from interface: RandomAccessBinary
Insert bytes at current pointer. If the pointer is outside the size of the blob, the blob is enlarged to fit the insertion. The operation does not move pointer.

Specified by:
insertBytes in interface RandomAccessBinary
Throws:
java.io.IOException

removeBytes

public void removeBytes(long bytes)
                 throws java.io.IOException
Description copied from interface: RandomAccessBinary
Remove bytes from the position of the current pointer. If the pointer is outside the blob, an error is thrown.

Specified by:
removeBytes in interface RandomAccessBinary
Throws:
java.io.IOException

setLength

public void setLength(long newLength)
               throws java.io.IOException
Description copied from interface: RandomAccessBinary
Set length of the binary object.

Specified by:
setLength in interface RandomAccessBinary
Throws:
java.io.IOException

skip

public void skip(long bytes)
          throws java.io.IOException
Description copied from interface: RandomAccessBinary
Move pointer forward

Specified by:
skip in interface BinaryReadable
Specified by:
skip in interface RandomAccessBinary
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object