org.deckfour.xes.nikefs2
Class NikeFS2RandomAccessStorageImpl

java.lang.Object
  extended by org.deckfour.xes.nikefs2.NikeFS2RandomAccessStorageImpl
All Implemented Interfaces:
DataInput, DataOutput, NikeFS2RandomAccessStorage
Direct Known Subclasses:
NikeFS2LazyRandomAccessStorageImpl

public class NikeFS2RandomAccessStorageImpl
extends 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)

Nested Class Summary
protected  class NikeFS2RandomAccessStorageImpl.FS2BlockInputStream
          Internal support class implementing an input stream over a list of blocks, as implemented by the enclosing class
protected  class NikeFS2RandomAccessStorageImpl.FS2BlockOutputStream
          Internal support class implementing an output stream over a list of blocks, as implemented by the enclosing class
protected  class NikeFS2RandomAccessStorageImpl.FS2DataInputStream
          Internal support class implementing a data input stream with NikeFS2-block-safe UTF-8 string serialization.
protected  class NikeFS2RandomAccessStorageImpl.FS2DataOutputStream
          Internal support class implementing a data output stream with NikeFS2-block-safe UTF-8 string serialization.
 
Field Summary
protected  List<NikeFS2Block> blocks
          List of blocks used to store data.
protected  NikeFS2RandomAccessStorageImpl.FS2DataInputStream dataInputStream
          Data input stream, used to simplify reading of higher-level data types.
protected  NikeFS2RandomAccessStorageImpl.FS2DataOutputStream dataOutputStream
          Data output stream, used to simplify writing of higher-level data types.
protected  long pointer
          Current file pointer (in bytes from the start) within this virtual file.
protected  long size
          Current size, in bytes, of this virtual file.
protected  NikeFS2VirtualFileSystem vfs
          References the virtual file system for block provision.
 
Constructor Summary
NikeFS2RandomAccessStorageImpl(NikeFS2VirtualFileSystem virtualFileSystem)
          Creates a new instance of this class.
 
Method Summary
protected  void adjustSize()
          Calling this method will adjust the size of this file, if it is no longer accurate.
 void close()
          Closes the data storage container.
 NikeFS2RandomAccessStorage copy()
          Creates a clone, or copy, of this storage, having the exact same contents and the file pointer reset to zero.
 long getFilePointer()
          Returns the current file pointer of the storage container.
 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[] b)
           
 void readFully(byte[] b, int off, int len)
           
 int readInt()
           
 String readLine()
          Deprecated. 
 long readLong()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 String readUTF()
           
 void seek(long pos)
          Repositions the offset, or file pointer, at which the next read or write operation will occur.
 int skipBytes(int n)
          Moves the offset, or file pointer, a specified number of bytes towards the end of the storage container.
protected  int translateToBlockNumber(long offset)
          Translates a virtual file pointer address in this instance to the block number, where the data is actually stored.
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.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 void writeBoolean(boolean v)
           
 void writeByte(int b)
           
 void writeBytes(String str)
           
 void writeChar(int c)
           
 void writeChars(String str)
           
 void writeDouble(double d)
           
 void writeFloat(float f)
           
 void writeInt(int i)
           
 void writeLong(long l)
           
 void writeShort(int s)
           
 void writeUTF(String str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vfs

protected NikeFS2VirtualFileSystem vfs
References the virtual file system for block provision.


blocks

protected 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.


dataOutputStream

protected NikeFS2RandomAccessStorageImpl.FS2DataOutputStream dataOutputStream
Data output stream, used to simplify writing of higher-level data types.


dataInputStream

protected NikeFS2RandomAccessStorageImpl.FS2DataInputStream dataInputStream
Data input stream, used to simplify reading of higher-level data types.

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 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:
IOException

copy

public NikeFS2RandomAccessStorage copy()
                                throws IOException
Description copied from interface: NikeFS2RandomAccessStorage
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 NikeFS2RandomAccessStorage
Throws:
IOException

getFilePointer

public long getFilePointer()
                    throws 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:
IOException

length

public long length()
            throws 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:
IOException

seek

public void seek(long pos)
          throws 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:
IOException

skipBytes

public int skipBytes(int n)
              throws 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 DataInput
Specified by:
skipBytes in interface NikeFS2RandomAccessStorage
Throws:
IOException

write

public void write(int b)
           throws IOException
Specified by:
write in interface DataOutput
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Specified by:
write in interface DataOutput
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Specified by:
write in interface DataOutput
Throws:
IOException

writeBoolean

public void writeBoolean(boolean v)
                  throws IOException
Specified by:
writeBoolean in interface DataOutput
Throws:
IOException

writeByte

public void writeByte(int b)
               throws IOException
Specified by:
writeByte in interface DataOutput
Throws:
IOException

writeBytes

public void writeBytes(String str)
                throws IOException
Specified by:
writeBytes in interface DataOutput
Throws:
IOException

writeChar

public void writeChar(int c)
               throws IOException
Specified by:
writeChar in interface DataOutput
Throws:
IOException

writeChars

public void writeChars(String str)
                throws IOException
Specified by:
writeChars in interface DataOutput
Throws:
IOException

writeDouble

public void writeDouble(double d)
                 throws IOException
Specified by:
writeDouble in interface DataOutput
Throws:
IOException

writeFloat

public void writeFloat(float f)
                throws IOException
Specified by:
writeFloat in interface DataOutput
Throws:
IOException

writeInt

public void writeInt(int i)
              throws IOException
Specified by:
writeInt in interface DataOutput
Throws:
IOException

writeLong

public void writeLong(long l)
               throws IOException
Specified by:
writeLong in interface DataOutput
Throws:
IOException

writeShort

public void writeShort(int s)
                throws IOException
Specified by:
writeShort in interface DataOutput
Throws:
IOException

writeUTF

public void writeUTF(String str)
              throws IOException
Specified by:
writeUTF in interface DataOutput
Throws:
IOException

readBoolean

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

readByte

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

readChar

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

readDouble

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

readFloat

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

readFully

public void readFully(byte[] b)
               throws IOException
Specified by:
readFully in interface DataInput
Throws:
IOException

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws IOException
Specified by:
readFully in interface DataInput
Throws:
IOException

readInt

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

readLine

@Deprecated
public String readLine()
                throws IOException
Deprecated. 

Specified by:
readLine in interface DataInput
Throws:
IOException

readLong

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

readShort

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

readUTF

public String readUTF()
               throws IOException
Specified by:
readUTF in interface DataInput
Throws:
IOException

readUnsignedByte

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

readUnsignedShort

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