org.simantics.databoard.util.binary
Interface RandomAccessBinary

All Superinterfaces:
BinaryReadable, BinaryWriteable, java.io.DataInput, java.io.DataOutput
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

Nested Class Summary
static class RandomAccessBinary.ByteSide
           
 
Method Summary
 void close()
          Flush and close the blob.
 void flush()
          Flush write buffer
 void insertBytes(long bytes, RandomAccessBinary.ByteSide side)
          Insert bytes at current pointer.
 long length()
          Get the length of the binary object.
 long position()
          Get the position of the cursor
 void position(long newPosition)
          Set new cursor position.
 void removeBytes(long bytes, RandomAccessBinary.ByteSide side)
          Remove bytes from the position of the current pointer.
 void setLength(long newLength)
          Set length of the binary object.
 
Methods inherited from interface org.simantics.databoard.util.binary.BinaryWriteable
writeFully, writeFully
 
Methods inherited from interface java.io.DataOutput
write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from interface org.simantics.databoard.util.binary.BinaryReadable
readFully, readFully, skipBytes
 
Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytes
 

Method Detail

flush

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

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

removeBytes

void removeBytes(long bytes,
                 RandomAccessBinary.ByteSide side)
                 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 -
side -
Throws:
java.io.IOException

insertBytes

void insertBytes(long bytes,
                 RandomAccessBinary.ByteSide side)
                 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 -
side -
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