org.deckfour.xes.nikefs2
Class NikeFS2Block

java.lang.Object
  extended by org.deckfour.xes.nikefs2.NikeFS2Block

public class NikeFS2Block
extends Object

This class implements the abstraction of a storage block for the NikeFS2 virtual file systems. Blocks have a defined size, in number of bytes, and are the basic building blocks for virtual files.

Author:
Christian W. Guenther (christian@deckfour.org)

Constructor Summary
NikeFS2Block(NikeFS2BlockProvider provider, int blockNumber)
          Creates a new block.
 
Method Summary
 int blockNumber()
          Returns the index number of this block within its block provider.
 void close()
          Closes this block, which frees all associated resources.
 int read(int blockOffset)
          Read a single byte from this block.
 int read(int blockOffset, byte[] buffer)
          Read a number of bytes from this block.
 int read(int blockOffset, byte[] buffer, int offset, int length)
          Read a number of bytes from this block.
 int size()
          Returns the size of this block in bytes.
 void write(int blockOffset, byte[] buffer)
          Writes a number of bytes to this block.
 void write(int blockOffset, byte[] buffer, int offset, int length)
          Writes a number of bytes to this block.
 void write(int blockOffset, int value)
          Writes a single byte to this block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NikeFS2Block

public NikeFS2Block(NikeFS2BlockProvider provider,
                    int blockNumber)
Creates a new block.

Parameters:
provider - The provider of this block.
blockNumber - The block number.
Method Detail

size

public int size()
Returns the size of this block in bytes.


blockNumber

public int blockNumber()
Returns the index number of this block within its block provider.


close

public void close()
Closes this block, which frees all associated resources.


read

public int read(int blockOffset,
                byte[] buffer,
                int offset,
                int length)
         throws IOException
Read a number of bytes from this block.

Parameters:
blockOffset - Offset, in bytes, within this block.
buffer - Buffer to store read data in.
offset - Offset within the buffer to write to.
length - Number of bytes to be read.
Returns:
The number of read bytes.
Throws:
IOException

read

public int read(int blockOffset,
                byte[] buffer)
         throws IOException
Read a number of bytes from this block.

Parameters:
blockOffset - Offset, in bytes, within this block.
buffer - Buffer to store read data in.
Throws:
IOException

read

public int read(int blockOffset)
         throws IOException
Read a single byte from this block.

Parameters:
blockOffset - Offset, in bytes, within this block.
Returns:
The read byte.
Throws:
IOException

write

public void write(int blockOffset,
                  byte[] buffer,
                  int offset,
                  int length)
           throws IOException
Writes a number of bytes to this block.

Parameters:
blockOffset - Offset within the block to commence writing at.
buffer - Buffer storing the data to be written.
offset - Offset within the buffer from where to read.
length - Number of bytes to be written.
Throws:
IOException

write

public void write(int blockOffset,
                  byte[] buffer)
           throws IOException
Writes a number of bytes to this block.

Parameters:
blockOffset - Offset within the block to commence writing at.
buffer - Buffer storing the data to be written.
Throws:
IOException

write

public void write(int blockOffset,
                  int value)
           throws IOException
Writes a single byte to this block.

Parameters:
blockOffset - Offset within the block to commence writing at.
value - The byte to be written.
Throws:
IOException