org.simantics.databoard.util.binary
Interface RandomAccessBinary

All Superinterfaces:
BinaryReadable, BinaryWriteable
All Known Implementing Classes:
BinaryFile, BinaryMemory, Blob

public interface RandomAccessBinary
extends BinaryWriteable, BinaryReadable

Random access binary is a interface to access a binary object (BLOB). Binary object is random accessible and has a length. It can be read and written, enlarged and shrunk at any position.

There is a pointer which moves on every read and write operation. It can moved with position(). If bytes are written and the pointer is moved outside the blob or moves while writing, the blob is enlarged.

Author:
Toni Kalajainen
See Also:
Cascading implementation, RandomAccessFile implementation, java.util.List implementation

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 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
 

Method Detail

put

void put(byte b)
         throws java.io.IOException
Write a byte

Specified by:
put in interface BinaryWriteable
Parameters:
b -
Throws:
java.io.IOException

put

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

Specified by:
put in interface BinaryWriteable
Parameters:
src -
Throws:
java.io.IOException

put

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

Specified by:
put in interface BinaryWriteable
Parameters:
src -
length -
Throws:
java.io.IOException

put

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

put

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

putShort

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

putInt

void putInt(int value)
            throws java.io.IOException,
                   java.lang.IndexOutOfBoundsException
Specified by:
putInt in interface BinaryWriteable
Throws:
java.io.IOException
java.lang.IndexOutOfBoundsException

putLong

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

putFloat

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

putDouble

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

order

java.nio.ByteOrder order()
Get byte order

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

order

void order(java.nio.ByteOrder order)
Set a new byte order

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

flush

void flush()
           throws java.io.IOException
Flush write buffer

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

get

byte get()
         throws java.io.IOException
Specified by:
get in interface BinaryReadable
Throws:
java.io.IOException

get

void get(byte[] dst,
         int offset,
         int length)
         throws java.io.IOException
Specified by:
get in interface BinaryReadable
Throws:
java.io.IOException

get

void get(byte[] dst)
         throws java.io.IOException
Specified by:
get in interface BinaryReadable
Throws:
java.io.IOException

get

void get(java.nio.ByteBuffer buf)
         throws java.io.IOException
Get buf fully

Specified by:
get in interface BinaryReadable
Parameters:
buf -
Throws:
java.io.IOException

get

void get(java.nio.ByteBuffer buf,
         int length)
         throws java.io.IOException
Get fully length bytes

Specified by:
get in interface BinaryReadable
Parameters:
buf -
length -
Throws:
java.io.IOException

getShort

short getShort()
               throws java.io.IOException
Specified by:
getShort in interface BinaryReadable
Throws:
java.io.IOException

getInt

int getInt()
           throws java.io.IOException
Specified by:
getInt in interface BinaryReadable
Throws:
java.io.IOException

getLong

long getLong()
             throws java.io.IOException
Specified by:
getLong in interface BinaryReadable
Throws:
java.io.IOException

getFloat

float getFloat()
               throws java.io.IOException
Specified by:
getFloat in interface BinaryReadable
Throws:
java.io.IOException

getDouble

double getDouble()
                 throws java.io.IOException
Specified by:
getDouble in interface BinaryReadable
Throws:
java.io.IOException

removeBytes

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

Parameters:
bytes -
Throws:
java.io.IOException

insertBytes

void insertBytes(long bytes)
                 throws java.io.IOException
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.

Parameters:
bytes -
Throws:
java.io.IOException

setLength

void setLength(long newLength)
               throws java.io.IOException
Set length of the binary object.

Parameters:
newLength -
Throws:
java.io.IOException

length

long length()
            throws java.io.IOException
Get the length of the binary object.

Specified by:
length in interface BinaryReadable
Returns:
the length
Throws:
java.io.IOException

close

void close()
           throws java.io.IOException
Flush and close the blob.

Throws:
java.io.IOException

position

void position(long newPosition)
              throws java.io.IOException
Set new cursor position. The position can be set outside the binary object.

Parameters:
newPosition -
Throws:
java.io.IOException

position

long position()
              throws java.io.IOException
Get the position of the cursor

Specified by:
position in interface BinaryReadable
Returns:
cursor
Throws:
java.io.IOException

skip

void skip(long bytes)
          throws java.io.IOException
Move pointer forward

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