org.processmining.framework.log.rfb.io
Class StorageBlock

java.lang.Object
  extended by org.processmining.framework.log.rfb.io.StorageBlock
All Implemented Interfaces:
java.io.DataInput, java.io.DataOutput, RandomAccessStorage

public class StorageBlock
extends java.lang.Object
implements RandomAccessStorage

This class represents a block of bytes, as provided by a block data storage. These blocks can be used to constitute and back a virtual file.

Author:
Christian W. Guenther (christian at deckfour dot org)

Field Summary
protected  int blockNumber
          The logical index of this block in the encompassing block data storage.
protected  int maxSize
          The current maximal number of bytes which can be allocated in this block.
protected  BlockDataStorage parent
          The block data storage of which this block is a part.
protected  int pointer
          Current offset of bytes in this block, from which the next read or write operation will occur.
protected  int size
          The current number of bytes allocated in this block at the moment.
 
Constructor Summary
StorageBlock(BlockDataStorage aParent, int aBlockNumber, int aMaxSize)
          Creates and initializes a new storage block object.
 
Method Summary
protected  void adjustSize()
          Internal method for automatically growing the current size of this block with each write operation.
 void close()
          Closes the data storage container.
 RandomAccessStorage copy()
          Creates a clone, or copy, of this storage, having the exact same contents and the file pointer reset to zero.
 double fillRatio()
          Returns the fill ratio of this block.
 int getBlockNumber()
          Returns the logical index of this block in its providing block data storage.
 long getFilePointer()
          Returns the current file pointer of the storage container.
 int getFreeBytes()
          Returns the free number of bytes, i.e.
 int getMaxSize()
          Returns the maximal number of bytes that can be allocated by and from this block.
 long length()
          Returns the length, or size, in number of bytes currently used by this instance.
 boolean readBoolean()
           
 byte readByte()
           
 char readChar()
           
 double readDouble()
           
 float readFloat()
           
 void readFully(byte[] arg0)
           
 void readFully(byte[] arg0, int arg1, int arg2)
           
 int readInt()
           
 java.lang.String readLine()
           
 long readLong()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 java.lang.String readUTF()
           
 void seek(long pos)
          Repositions the offset, or file pointer, at which the next read or write operation will occur.
 void setBlockNumber(int aBlockNumber)
          Sets a new logical index of this bock in its providing block data storage.
Warning: Do not use this method unless you know what you are doing! The internal functionality of a storage block depends on its alignment with the encompassing block data storage.
 void setMaxSize(int aMaxSize)
          Adjusts the maximal allocated number of bytes in this block, used by the encompassing block data storage.
 int skipBytes(int n)
          Moves the offset, or file pointer, a specified number of bytes towards the end of the storage container.
 void write(byte[] arg0)
           
 void write(byte[] arg0, int arg1, int arg2)
           
 void write(int arg0)
           
 void writeBoolean(boolean arg0)
           
 void writeByte(int arg0)
           
 void writeBytes(java.lang.String arg0)
           
 void writeChar(int arg0)
           
 void writeChars(java.lang.String arg0)
           
 void writeDouble(double arg0)
           
 void writeFloat(float arg0)
           
 void writeInt(int arg0)
           
 void writeLong(long arg0)
           
 void writeShort(int arg0)
           
 void writeUTF(java.lang.String arg0)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected BlockDataStorage parent
The block data storage of which this block is a part.


blockNumber

protected int blockNumber
The logical index of this block in the encompassing block data storage.


maxSize

protected int maxSize
The current maximal number of bytes which can be allocated in this block.


size

protected int size
The current number of bytes allocated in this block at the moment.


pointer

protected int pointer
Current offset of bytes in this block, from which the next read or write operation will occur.

Constructor Detail

StorageBlock

public StorageBlock(BlockDataStorage aParent,
                    int aBlockNumber,
                    int aMaxSize)
Creates and initializes a new storage block object.

Parameters:
aParent - Block data storage of which this block is a part.
aBlockNumber - Index of this block in the encompassing storage.
aMaxSize - Maximal number of bytes contained in this block.
Method Detail

adjustSize

protected void adjustSize()
Internal method for automatically growing the current size of this block with each write operation.


setMaxSize

public void setMaxSize(int aMaxSize)
Adjusts the maximal allocated number of bytes in this block, used by the encompassing block data storage.

Parameters:
aMaxSize - Maximal size in bytes to be available.

getMaxSize

public int getMaxSize()
Returns the maximal number of bytes that can be allocated by and from this block.

Returns:
Maximal size in bytes available.

getFreeBytes

public int getFreeBytes()
Returns the free number of bytes, i.e. which can still be allocated, from this block.

Returns:

fillRatio

public double fillRatio()
Returns the fill ratio of this block.

Returns:
The percentage of this block which is currently filled with data, as value within [0.0, 1.0]

getBlockNumber

public int getBlockNumber()
Returns the logical index of this block in its providing block data storage.

Returns:

setBlockNumber

public void setBlockNumber(int aBlockNumber)
Sets a new logical index of this bock in its providing block data storage.
Warning: Do not use this method unless you know what you are doing! The internal functionality of a storage block depends on its alignment with the encompassing block data storage.

Parameters:
aBlockNumber - The new logical index of this bock in its providing block data storage.

close

public void close()
           throws java.io.IOException
Description copied from interface: RandomAccessStorage
Closes the data storage container. After this method has been invoked, no further access to the represented instance is allowed.

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

getFilePointer

public long getFilePointer()
                    throws java.io.IOException
Description copied from interface: RandomAccessStorage
Returns the current file pointer of the storage container. A file pointer is the offset in bytes, from the beginning of the sequential byte storage, at which the next read or write operation would occur.

Specified by:
getFilePointer in interface RandomAccessStorage
Returns:
Offset in bytes from beginning of storage.
Throws:
java.io.IOException

length

public long length()
            throws java.io.IOException
Description copied from interface: RandomAccessStorage
Returns the length, or size, in number of bytes currently used by this instance.

Specified by:
length in interface RandomAccessStorage
Returns:
Number of bytes currently allocated.
Throws:
java.io.IOException

seek

public void seek(long pos)
          throws java.io.IOException
Description copied from interface: RandomAccessStorage
Repositions the offset, or file pointer, at which the next read or write operation will occur.

Specified by:
seek in interface RandomAccessStorage
Parameters:
pos - The offset in bytes, at which the next operation will occur.
Throws:
java.io.IOException

skipBytes

public int skipBytes(int n)
              throws java.io.IOException
Description copied from interface: RandomAccessStorage
Moves the offset, or file pointer, a specified number of bytes towards the end of the storage container.

Specified by:
skipBytes in interface java.io.DataInput
Specified by:
skipBytes in interface RandomAccessStorage
Throws:
java.io.IOException

write

public void write(int arg0)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Throws:
java.io.IOException

write

public void write(byte[] arg0)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Throws:
java.io.IOException

write

public void write(byte[] arg0,
                  int arg1,
                  int arg2)
           throws java.io.IOException
Specified by:
write in interface java.io.DataOutput
Throws:
java.io.IOException

writeBoolean

public void writeBoolean(boolean arg0)
                  throws java.io.IOException
Specified by:
writeBoolean in interface java.io.DataOutput
Throws:
java.io.IOException

writeByte

public void writeByte(int arg0)
               throws java.io.IOException
Specified by:
writeByte in interface java.io.DataOutput
Throws:
java.io.IOException

writeBytes

public void writeBytes(java.lang.String arg0)
                throws java.io.IOException
Specified by:
writeBytes in interface java.io.DataOutput
Throws:
java.io.IOException

writeChar

public void writeChar(int arg0)
               throws java.io.IOException
Specified by:
writeChar in interface java.io.DataOutput
Throws:
java.io.IOException

writeChars

public void writeChars(java.lang.String arg0)
                throws java.io.IOException
Specified by:
writeChars in interface java.io.DataOutput
Throws:
java.io.IOException

writeDouble

public void writeDouble(double arg0)
                 throws java.io.IOException
Specified by:
writeDouble in interface java.io.DataOutput
Throws:
java.io.IOException

writeFloat

public void writeFloat(float arg0)
                throws java.io.IOException
Specified by:
writeFloat in interface java.io.DataOutput
Throws:
java.io.IOException

writeInt

public void writeInt(int arg0)
              throws java.io.IOException
Specified by:
writeInt in interface java.io.DataOutput
Throws:
java.io.IOException

writeLong

public void writeLong(long arg0)
               throws java.io.IOException
Specified by:
writeLong in interface java.io.DataOutput
Throws:
java.io.IOException

writeShort

public void writeShort(int arg0)
                throws java.io.IOException
Specified by:
writeShort in interface java.io.DataOutput
Throws:
java.io.IOException

writeUTF

public void writeUTF(java.lang.String arg0)
              throws java.io.IOException
Specified by:
writeUTF in interface java.io.DataOutput
Throws:
java.io.IOException

readBoolean

public boolean readBoolean()
                    throws java.io.IOException
Specified by:
readBoolean in interface java.io.DataInput
Throws:
java.io.IOException

readByte

public byte readByte()
              throws java.io.IOException
Specified by:
readByte in interface java.io.DataInput
Throws:
java.io.IOException

readChar

public char readChar()
              throws java.io.IOException
Specified by:
readChar in interface java.io.DataInput
Throws:
java.io.IOException

readDouble

public double readDouble()
                  throws java.io.IOException
Specified by:
readDouble in interface java.io.DataInput
Throws:
java.io.IOException

readFloat

public float readFloat()
                throws java.io.IOException
Specified by:
readFloat in interface java.io.DataInput
Throws:
java.io.IOException

readFully

public void readFully(byte[] arg0)
               throws java.io.IOException
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

readFully

public void readFully(byte[] arg0,
                      int arg1,
                      int arg2)
               throws java.io.IOException
Specified by:
readFully in interface java.io.DataInput
Throws:
java.io.IOException

readInt

public int readInt()
            throws java.io.IOException
Specified by:
readInt in interface java.io.DataInput
Throws:
java.io.IOException

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Specified by:
readLine in interface java.io.DataInput
Throws:
java.io.IOException

readLong

public long readLong()
              throws java.io.IOException
Specified by:
readLong in interface java.io.DataInput
Throws:
java.io.IOException

readShort

public short readShort()
                throws java.io.IOException
Specified by:
readShort in interface java.io.DataInput
Throws:
java.io.IOException

readUTF

public java.lang.String readUTF()
                         throws java.io.IOException
Specified by:
readUTF in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedByte

public int readUnsignedByte()
                     throws java.io.IOException
Specified by:
readUnsignedByte in interface java.io.DataInput
Throws:
java.io.IOException

readUnsignedShort

public int readUnsignedShort()
                      throws java.io.IOException
Specified by:
readUnsignedShort in interface java.io.DataInput
Throws:
java.io.IOException

copy

public RandomAccessStorage copy()
                         throws java.io.IOException
Description copied from interface: RandomAccessStorage
Creates a clone, or copy, of this storage, having the exact same contents and the file pointer reset to zero.

Specified by:
copy in interface RandomAccessStorage
Returns:
Throws:
java.io.IOException