org.cdlib.xtf.saxonExt.pipe
Class BufferedRandomAccessFile

Object
  extended by RandomAccessFileOrArray
      extended by BufferedRandomAccessFile
All Implemented Interfaces:
DataInput

 class BufferedRandomAccessFile
extends RandomAccessFileOrArray

Class to provide buffered, random access to a PDF file. Useful for when we can't realistically fit a PDF file into memory.

Author:
Martin Haye

Field Summary
(package private)  RandomAccessFile baseFile
           
(package private)  byte[] buffer
           
(package private)  int BUFFER_SIZE
           
(package private)  int bufferFilePointer
           
(package private)  int bufferLength
           
(package private)  int bufferPos
           
(package private)  boolean havePrevByte
           
(package private)  byte prevByte
           
(package private)  int startOffset
           
 
Constructor Summary
BufferedRandomAccessFile(String filename)
           
 
Method Summary
 void close()
           
private  void fillBuffer()
          Fill our buffer with data at the current file pointer.
 int getFilePointer()
           
 ByteBuffer getNioByteBuffer()
           
 int getStartOffset()
           
 boolean isOpen()
           
 int length()
           
 void pushBack(byte b)
           
 int read()
           
 int read(byte[] b, int off, int len)
           
 void reOpen()
           
 void seek(int pos)
           
 void seek(long pos)
           
 void setStartOffset(int off)
           
 int skipBytes(int n)
           
 
Methods inherited from class RandomAccessFileOrArray
InputStreamToArray, insureOpen, read, readBoolean, readByte, readChar, readCharLE, readDouble, readDoubleLE, readFloat, readFloatLE, readFully, readFully, readInt, readIntLE, readLine, readLong, readLongLE, readShort, readShortLE, readUnsignedByte, readUnsignedInt, readUnsignedIntLE, readUnsignedShort, readUnsignedShortLE, readUTF, skip
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

baseFile

RandomAccessFile baseFile

prevByte

byte prevByte

havePrevByte

boolean havePrevByte

BUFFER_SIZE

final int BUFFER_SIZE
See Also:
Constant Field Values

buffer

byte[] buffer

startOffset

int startOffset

bufferLength

int bufferLength

bufferPos

int bufferPos

bufferFilePointer

int bufferFilePointer
Constructor Detail

BufferedRandomAccessFile

public BufferedRandomAccessFile(String filename)
                         throws IOException
Throws:
IOException
Method Detail

pushBack

public void pushBack(byte b)
Overrides:
pushBack in class RandomAccessFileOrArray

fillBuffer

private void fillBuffer()
                 throws IOException
Fill our buffer with data at the current file pointer.

Throws:
IOException

read

public int read()
         throws IOException
Overrides:
read in class RandomAccessFileOrArray
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class RandomAccessFileOrArray
Throws:
IOException

skipBytes

public int skipBytes(int n)
              throws IOException
Specified by:
skipBytes in interface DataInput
Overrides:
skipBytes in class RandomAccessFileOrArray
Throws:
IOException

reOpen

public void reOpen()
            throws IOException
Overrides:
reOpen in class RandomAccessFileOrArray
Throws:
IOException

isOpen

public boolean isOpen()
Overrides:
isOpen in class RandomAccessFileOrArray

close

public void close()
           throws IOException
Overrides:
close in class RandomAccessFileOrArray
Throws:
IOException

setStartOffset

public void setStartOffset(int off)
Overrides:
setStartOffset in class RandomAccessFileOrArray

getStartOffset

public int getStartOffset()
Overrides:
getStartOffset in class RandomAccessFileOrArray

length

public int length()
           throws IOException
Overrides:
length in class RandomAccessFileOrArray
Throws:
IOException

seek

public void seek(int pos)
          throws IOException
Overrides:
seek in class RandomAccessFileOrArray
Throws:
IOException

seek

public void seek(long pos)
          throws IOException
Overrides:
seek in class RandomAccessFileOrArray
Throws:
IOException

getFilePointer

public int getFilePointer()
                   throws IOException
Overrides:
getFilePointer in class RandomAccessFileOrArray
Throws:
IOException

getNioByteBuffer

public ByteBuffer getNioByteBuffer()
                            throws IOException
Overrides:
getNioByteBuffer in class RandomAccessFileOrArray
Throws:
IOException