Class NikeFS2RandomAccessStorageImpl

  • All Implemented Interfaces:
    java.io.DataInput, java.io.DataOutput, NikeFS2RandomAccessStorage
    Direct Known Subclasses:
    NikeFS2LazyRandomAccessStorageImpl

    public class NikeFS2RandomAccessStorageImpl
    extends java.lang.Object
    implements NikeFS2RandomAccessStorage
    Implements the Random Access Storage interface for using the NikeFS2 virtual file system transparently to the application and user. Effectively, this class implements a file abstraction, backed not by a real OS-level file, but a set of virtual blocks in the VFS.
    Author:
    Christian W. Guenther (christian@deckfour.org)
    • Field Detail

      • blocks

        protected java.util.List<NikeFS2Block> blocks
        List of blocks used to store data.
      • size

        protected long size
        Current size, in bytes, of this virtual file.
      • pointer

        protected long pointer
        Current file pointer (in bytes from the start) within this virtual file.
    • Constructor Detail

      • NikeFS2RandomAccessStorageImpl

        public NikeFS2RandomAccessStorageImpl​(NikeFS2VirtualFileSystem virtualFileSystem)
        Creates a new instance of this class.
        Parameters:
        virtualFileSystem - The virtual file system instance this virtual file can allocate storage blocks from.
    • Method Detail

      • adjustSize

        protected void adjustSize()
        Calling this method will adjust the size of this file, if it is no longer accurate.
      • translateToBlockNumber

        protected int translateToBlockNumber​(long offset)
        Translates a virtual file pointer address in this instance to the block number, where the data is actually stored.
        Parameters:
        offset - The virtual file pointer address, in bytes from the beginning.
        Returns:
        The number of the referenced block.
      • translateToBlockOffset

        protected int translateToBlockOffset​(long offset)
        Translates a virtual file pointer address in this instance to the offset within the block, where the data is actually stored.
        Parameters:
        offset - The virtual file pointer address, in bytes from the beginning.
        Returns:
        The offset within the block, where the data is actually stored
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: NikeFS2RandomAccessStorage
        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 NikeFS2RandomAccessStorage
        Throws:
        java.io.IOException
      • getFilePointer

        public long getFilePointer()
                            throws java.io.IOException
        Description copied from interface: NikeFS2RandomAccessStorage
        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 NikeFS2RandomAccessStorage
        Returns:
        Offset in bytes from beginning of storage.
        Throws:
        java.io.IOException
      • length

        public long length()
                    throws java.io.IOException
        Description copied from interface: NikeFS2RandomAccessStorage
        Returns the length, or size, in number of bytes currently used by this instance.
        Specified by:
        length in interface NikeFS2RandomAccessStorage
        Returns:
        Number of bytes currently allocated.
        Throws:
        java.io.IOException
      • seek

        public void seek​(long pos)
                  throws java.io.IOException
        Description copied from interface: NikeFS2RandomAccessStorage
        Repositions the offset, or file pointer, at which the next read or write operation will occur.
        Specified by:
        seek in interface NikeFS2RandomAccessStorage
        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: NikeFS2RandomAccessStorage
        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 NikeFS2RandomAccessStorage
        Throws:
        java.io.IOException
      • write

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

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

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Specified by:
        write in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeBoolean

        public void writeBoolean​(boolean v)
                          throws java.io.IOException
        Specified by:
        writeBoolean in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeByte

        public void writeByte​(int b)
                       throws java.io.IOException
        Specified by:
        writeByte in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeBytes

        public void writeBytes​(java.lang.String str)
                        throws java.io.IOException
        Specified by:
        writeBytes in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeChar

        public void writeChar​(int c)
                       throws java.io.IOException
        Specified by:
        writeChar in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeChars

        public void writeChars​(java.lang.String str)
                        throws java.io.IOException
        Specified by:
        writeChars in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeDouble

        public void writeDouble​(double d)
                         throws java.io.IOException
        Specified by:
        writeDouble in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeFloat

        public void writeFloat​(float f)
                        throws java.io.IOException
        Specified by:
        writeFloat in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeInt

        public void writeInt​(int i)
                      throws java.io.IOException
        Specified by:
        writeInt in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeLong

        public void writeLong​(long l)
                       throws java.io.IOException
        Specified by:
        writeLong in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeShort

        public void writeShort​(int s)
                        throws java.io.IOException
        Specified by:
        writeShort in interface java.io.DataOutput
        Throws:
        java.io.IOException
      • writeUTF

        public void writeUTF​(java.lang.String str)
                      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[] b)
                       throws java.io.IOException
        Specified by:
        readFully in interface java.io.DataInput
        Throws:
        java.io.IOException
      • readFully

        public void readFully​(byte[] b,
                              int off,
                              int len)
                       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

        @Deprecated
        public java.lang.String readLine()
                                  throws java.io.IOException
        Deprecated.
        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