org.cdlib.xtf.util
Class SubFileReader

Object
  extended by SubStoreReader
      extended by SubFileReader

 class SubFileReader
extends SubStoreReader

Reads a single sub-file within a StructuredFile. A sub-file provides standard DataInput/DataOutput facilities, and takes care of reading from the correct subset of the main StructuredFile.

Author:
Martin Haye

Field Summary
private  long curPos
          Current read position within the subfile
private  RandomAccessFile file
          Actual disk file to write to
private  StructuredFile parent
          The structured file that owns this Subfile
private  long segLength
          Length of this subfile
private  long segOffset
          Absolute file position for the subfile's start
 
Constructor Summary
SubFileReader(RandomAccessFile file, StructuredFile parent, long segOffset, long segLength)
          Construct a subfile reader.
 
Method Summary
private  void checkLength(int nBytes)
          Ensure that the sub-file has room to read the specified number of bytes.
 void close()
           
 long getFilePointer()
           
 long length()
           
 void read(byte[] b, int off, int len)
           
 byte readByte()
           
 int readInt()
           
 void seek(long pos)
           
 
Methods inherited from class SubStoreReader
read
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

private RandomAccessFile file
Actual disk file to write to


parent

private StructuredFile parent
The structured file that owns this Subfile


segOffset

private long segOffset
Absolute file position for the subfile's start


segLength

private long segLength
Length of this subfile


curPos

private long curPos
Current read position within the subfile

Constructor Detail

SubFileReader

SubFileReader(RandomAccessFile file,
              StructuredFile parent,
              long segOffset,
              long segLength)
        throws IOException
Construct a subfile reader. Reads will be constrained to the specified limit.

Parameters:
file - Disk file to attach to
parent - Structured file to attach to
segOffset - Beginning offset of the segment
segLength - Length of the segment
Throws:
IOException
Method Detail

close

public void close()
           throws IOException
Specified by:
close in class SubStoreReader
Throws:
IOException

getFilePointer

public long getFilePointer()
                    throws IOException
Specified by:
getFilePointer in class SubStoreReader
Throws:
IOException

length

public long length()
            throws IOException
Specified by:
length in class SubStoreReader
Throws:
IOException

checkLength

private void checkLength(int nBytes)
                  throws IOException
Ensure that the sub-file has room to read the specified number of bytes. As a side-effect, we also check that the main file position is current for this sub-file, and if not, we save the position for the other sub-file and restore ours.

Parameters:
nBytes - Amount of space desired
Throws:
IOException

read

public void read(byte[] b,
                 int off,
                 int len)
          throws IOException
Specified by:
read in class SubStoreReader
Throws:
IOException

seek

public void seek(long pos)
          throws IOException
Specified by:
seek in class SubStoreReader
Throws:
IOException

readByte

public byte readByte()
              throws IOException
Specified by:
readByte in class SubStoreReader
Throws:
IOException

readInt

public int readInt()
            throws IOException
Specified by:
readInt in class SubStoreReader
Throws:
IOException