org.simantics.databoard.util.binary
Class FileWriteable

java.lang.Object
  extended by org.simantics.databoard.util.binary.FileWriteable
All Implemented Interfaces:
BinaryWriteable, Seekable

public class FileWriteable
extends java.lang.Object
implements BinaryWriteable, Seekable

This class is a Random Access File implementation to BinaryWritable implementation. The implementation is buffered, therefore the values may not be written until flush(). The implementation is not multi-thread safe. Although file pointer of the backend RandomAccessFile is allowed to move between read operations of this class.

Author:
Toni Kalajainen

Constructor Summary
FileWriteable(java.io.RandomAccessFile file)
          Create a BinaryWritable implemantation wrapped over a RandomAccessFile.
 
Method Summary
 void close()
           
 void flush()
          Flush write buffer
 java.io.RandomAccessFile getFile()
           
 java.nio.ByteOrder order()
           
 void order(java.nio.ByteOrder order)
           
 long position()
          Get position
 void position(long newPosition)
          Seek new 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)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileWriteable

public FileWriteable(java.io.RandomAccessFile file)
              throws java.io.IOException
Create a BinaryWritable implemantation wrapped over a RandomAccessFile.

Parameters:
file -
Throws:
java.io.IOException
Method Detail

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

getFile

public java.io.RandomAccessFile getFile()

order

public java.nio.ByteOrder order()
Specified by:
order in interface BinaryWriteable

order

public void order(java.nio.ByteOrder order)
Specified by:
order in interface BinaryWriteable

put

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

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

put

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

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

put

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

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

put

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

put

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

putDouble

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

putFloat

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

putInt

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

putLong

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

putShort

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

flush

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

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

position

public long position()
Description copied from interface: Seekable
Get position

Specified by:
position in interface Seekable
Returns:
position

position

public void position(long newPosition)
              throws java.io.IOException
Description copied from interface: Seekable
Seek new position. The next value will be written after the index of the given pointer.

Specified by:
position in interface Seekable
Parameters:
newPosition - new position
Throws:
java.io.IOException