Package org.deckfour.xes.nikefs2
Class NikeFS2RandomAccessStorageImpl
- java.lang.Object
-
- org.deckfour.xes.nikefs2.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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classNikeFS2RandomAccessStorageImpl.FS2BlockInputStreamInternal support class implementing an input stream over a list of blocks, as implemented by the enclosing classprotected classNikeFS2RandomAccessStorageImpl.FS2BlockOutputStreamInternal support class implementing an output stream over a list of blocks, as implemented by the enclosing classprotected classNikeFS2RandomAccessStorageImpl.FS2DataInputStreamInternal support class implementing a data input stream with NikeFS2-block-safe UTF-8 string serialization.protected classNikeFS2RandomAccessStorageImpl.FS2DataOutputStreamInternal support class implementing a data output stream with NikeFS2-block-safe UTF-8 string serialization.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<NikeFS2Block>blocksList of blocks used to store data.protected NikeFS2RandomAccessStorageImpl.FS2DataInputStreamdataInputStreamData input stream, used to simplify reading of higher-level data types.protected NikeFS2RandomAccessStorageImpl.FS2DataOutputStreamdataOutputStreamData output stream, used to simplify writing of higher-level data types.protected longpointerCurrent file pointer (in bytes from the start) within this virtual file.protected longsizeCurrent size, in bytes, of this virtual file.protected NikeFS2VirtualFileSystemvfsReferences the virtual file system for block provision.
-
Constructor Summary
Constructors Constructor Description NikeFS2RandomAccessStorageImpl(NikeFS2VirtualFileSystem virtualFileSystem)Creates a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidadjustSize()Calling this method will adjust the size of this file, if it is no longer accurate.voidclose()Closes the data storage container.NikeFS2RandomAccessStoragecopy()Creates a clone, or copy, of this storage, having the exact same contents and the file pointer reset to zero.longgetFilePointer()Returns the current file pointer of the storage container.longlength()Returns the length, or size, in number of bytes currently used by this instance.booleanreadBoolean()bytereadByte()charreadChar()doublereadDouble()floatreadFloat()voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)intreadInt()java.lang.StringreadLine()Deprecated.longreadLong()shortreadShort()intreadUnsignedByte()intreadUnsignedShort()java.lang.StringreadUTF()voidseek(long pos)Repositions the offset, or file pointer, at which the next read or write operation will occur.intskipBytes(int n)Moves the offset, or file pointer, a specified number of bytes towards the end of the storage container.protected inttranslateToBlockNumber(long offset)Translates a virtual file pointer address in this instance to the block number, where the data is actually stored.protected inttranslateToBlockOffset(long offset)Translates a virtual file pointer address in this instance to the offset within the block, where the data is actually stored.voidwrite(byte[] b)voidwrite(byte[] b, int off, int len)voidwrite(int b)voidwriteBoolean(boolean v)voidwriteByte(int b)voidwriteBytes(java.lang.String str)voidwriteChar(int c)voidwriteChars(java.lang.String str)voidwriteDouble(double d)voidwriteFloat(float f)voidwriteInt(int i)voidwriteLong(long l)voidwriteShort(int s)voidwriteUTF(java.lang.String str)
-
-
-
Field Detail
-
vfs
protected NikeFS2VirtualFileSystem vfs
References the virtual file system for block provision.
-
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.
-
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 java.io.IOExceptionDescription copied from interface:NikeFS2RandomAccessStorageCloses the data storage container. After this method has been invoked, no further access to the represented instance is allowed.- Specified by:
closein interfaceNikeFS2RandomAccessStorage- Throws:
java.io.IOException
-
copy
public NikeFS2RandomAccessStorage copy() throws java.io.IOException
Description copied from interface:NikeFS2RandomAccessStorageCreates a clone, or copy, of this storage, having the exact same contents and the file pointer reset to zero.- Specified by:
copyin interfaceNikeFS2RandomAccessStorage- Throws:
java.io.IOException
-
getFilePointer
public long getFilePointer() throws java.io.IOExceptionDescription copied from interface:NikeFS2RandomAccessStorageReturns 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:
getFilePointerin interfaceNikeFS2RandomAccessStorage- Returns:
- Offset in bytes from beginning of storage.
- Throws:
java.io.IOException
-
length
public long length() throws java.io.IOExceptionDescription copied from interface:NikeFS2RandomAccessStorageReturns the length, or size, in number of bytes currently used by this instance.- Specified by:
lengthin interfaceNikeFS2RandomAccessStorage- Returns:
- Number of bytes currently allocated.
- Throws:
java.io.IOException
-
seek
public void seek(long pos) throws java.io.IOExceptionDescription copied from interface:NikeFS2RandomAccessStorageRepositions the offset, or file pointer, at which the next read or write operation will occur.- Specified by:
seekin interfaceNikeFS2RandomAccessStorage- 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.IOExceptionDescription copied from interface:NikeFS2RandomAccessStorageMoves the offset, or file pointer, a specified number of bytes towards the end of the storage container.- Specified by:
skipBytesin interfacejava.io.DataInput- Specified by:
skipBytesin interfaceNikeFS2RandomAccessStorage- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException- Specified by:
writein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
write
public void write(byte[] b) throws java.io.IOException- Specified by:
writein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Specified by:
writein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeBoolean
public void writeBoolean(boolean v) throws java.io.IOException- Specified by:
writeBooleanin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeByte
public void writeByte(int b) throws java.io.IOException- Specified by:
writeBytein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(java.lang.String str) throws java.io.IOException- Specified by:
writeBytesin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeChar
public void writeChar(int c) throws java.io.IOException- Specified by:
writeCharin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeChars
public void writeChars(java.lang.String str) throws java.io.IOException- Specified by:
writeCharsin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeDouble
public void writeDouble(double d) throws java.io.IOException- Specified by:
writeDoublein interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeFloat
public void writeFloat(float f) throws java.io.IOException- Specified by:
writeFloatin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeInt
public void writeInt(int i) throws java.io.IOException- Specified by:
writeIntin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeLong
public void writeLong(long l) throws java.io.IOException- Specified by:
writeLongin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeShort
public void writeShort(int s) throws java.io.IOException- Specified by:
writeShortin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
writeUTF
public void writeUTF(java.lang.String str) throws java.io.IOException- Specified by:
writeUTFin interfacejava.io.DataOutput- Throws:
java.io.IOException
-
readBoolean
public boolean readBoolean() throws java.io.IOException- Specified by:
readBooleanin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readByte
public byte readByte() throws java.io.IOException- Specified by:
readBytein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readChar
public char readChar() throws java.io.IOException- Specified by:
readCharin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException- Specified by:
readDoublein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException- Specified by:
readFloatin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b) throws java.io.IOException- Specified by:
readFullyin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws java.io.IOException- Specified by:
readFullyin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readInt
public int readInt() throws java.io.IOException- Specified by:
readIntin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readLine
@Deprecated public java.lang.String readLine() throws java.io.IOExceptionDeprecated.- Specified by:
readLinein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException- Specified by:
readLongin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readShort
public short readShort() throws java.io.IOException- Specified by:
readShortin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUTF
public java.lang.String readUTF() throws java.io.IOException- Specified by:
readUTFin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOException- Specified by:
readUnsignedBytein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUnsignedShort
public int readUnsignedShort() throws java.io.IOException- Specified by:
readUnsignedShortin interfacejava.io.DataInput- Throws:
java.io.IOException
-
-