org.cdlib.xtf.util
Class SubFileWriter

Object
  extended by SubStoreWriter
      extended by SubFileWriter

 class SubFileWriter
extends SubStoreWriter

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

Author:
Martin Haye

Field Summary
private  byte[] buf
          Buffered data (cuts down access to the physical file)
private static int BUF_SIZE
          Size of the buffer to maintain
private  int bufTop
          Amount of data buffered
private  RandomAccessFile file
          Actual disk file to write to
private  StructuredFile parent
          The structured file that owns this Subfile
private  long segOffset
          Absolute file position for the subfile's start
private  long writtenPos
          Current write position within the subfile
 
Constructor Summary
SubFileWriter(RandomAccessFile file, StructuredFile parent, long segOffset)
          Construct a subfile writer.
 
Method Summary
private  void checkLength(int nBytes)
          Ensure that the buffer has room for the specified number of bytes.
 void close()
           
 long length()
           
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void writeByte(int v)
           
 void writeInt(int v)
           
 
Methods inherited from class SubStoreWriter
writeChars
 
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


writtenPos

private long writtenPos
Current write position within the subfile


BUF_SIZE

private static final int BUF_SIZE
Size of the buffer to maintain

See Also:
Constant Field Values

buf

private byte[] buf
Buffered data (cuts down access to the physical file)


bufTop

private int bufTop
Amount of data buffered

Constructor Detail

SubFileWriter

SubFileWriter(RandomAccessFile file,
              StructuredFile parent,
              long segOffset)
        throws IOException
Construct a subfile writer.

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

close

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

length

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

checkLength

private void checkLength(int nBytes)
                  throws IOException
Ensure that the buffer has room for the specified number of bytes. If not, it is flushed.

Parameters:
nBytes - Amount of space desired
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Overrides:
write in class SubStoreWriter
Throws:
IOException

write

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

writeByte

public void writeByte(int v)
               throws IOException
Specified by:
writeByte in class SubStoreWriter
Throws:
IOException

writeInt

public void writeInt(int v)
              throws IOException
Specified by:
writeInt in class SubStoreWriter
Throws:
IOException