Class NikeFS2Block


  • public class NikeFS2Block
    extends java.lang.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)
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 java.io.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:
        java.io.IOException
      • read

        public int read​(int blockOffset,
                        byte[] buffer)
                 throws java.io.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:
        java.io.IOException
      • read

        public int read​(int blockOffset)
                 throws java.io.IOException
        Read a single byte from this block.
        Parameters:
        blockOffset - Offset, in bytes, within this block.
        Returns:
        The read byte.
        Throws:
        java.io.IOException
      • write

        public void write​(int blockOffset,
                          byte[] buffer,
                          int offset,
                          int length)
                   throws java.io.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:
        java.io.IOException
      • write

        public void write​(int blockOffset,
                          byte[] buffer)
                   throws java.io.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:
        java.io.IOException
      • write

        public void write​(int blockOffset,
                          int value)
                   throws java.io.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:
        java.io.IOException