com.etymon.pjx
Class PdfInputFile

java.lang.Object
  extended by com.etymon.pjx.PdfInputFile
All Implemented Interfaces:
PdfInput

public class PdfInputFile
extends java.lang.Object
implements PdfInput

Provides low-level methods for reading portions of a PDF document. PdfReader accesses PDF documents through the PdfInput interface, which is implemented by this class. The portions of the document are read from the file system as they are requested, which reduces memory consumption as compared to PdfInputBuffer but is a bit slower.

This class is synchronized; however, note that since it acts as a wrapper around a file that is kept open, it is the calling method's responsibility to ensure that the file is not modified externally to this class. If that is a problem, use PdfInputBuffer.PdfInputBuffer(File), which reads the entire file into memory and closes it immediately.


Field Summary
protected  java.nio.channels.FileChannel _fileChannel
          The file channel associated with the PDF document.
protected  long _length
          The length of the input file.
protected  java.lang.String _name
          The input file name.
protected  java.io.RandomAccessFile _randomAccessFile
          The random access file containing the PDF document.
 
Constructor Summary
PdfInputFile(java.io.File pdfFile)
          Constructs a PDF input source based on a specified file.
 
Method Summary
 void close()
          Closes the PDF document and releases any system resources associated with it.
 long getLength()
          Returns the length of the PDF document.
 java.lang.String getName()
          Returns a name string associated of the PDF document.
 java.nio.ByteBuffer readBytes(long start, long end)
          Returns a specified portion of a PDF document as a ByteBuffer.
 java.nio.CharBuffer readChars(long start, long end)
          Returns a specified portion of a PDF document as a CharBuffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_fileChannel

protected java.nio.channels.FileChannel _fileChannel
The file channel associated with the PDF document.


_length

protected long _length
The length of the input file.


_name

protected java.lang.String _name
The input file name.


_randomAccessFile

protected java.io.RandomAccessFile _randomAccessFile
The random access file containing the PDF document.

Constructor Detail

PdfInputFile

public PdfInputFile(java.io.File pdfFile)
             throws java.io.IOException
Constructs a PDF input source based on a specified file. The file is kept open, and portions of it are read as they are requested. It is the calling method's responsibility to ensure that the file is not modified externally to this class.

Parameters:
pdfFile - the source file.
Throws:
java.io.IOException
Method Detail

close

public void close()
           throws java.io.IOException
Closes the PDF document and releases any system resources associated with it.

Throws:
java.io.IOException

getLength

public long getLength()
Description copied from interface: PdfInput
Returns the length of the PDF document.

Specified by:
getLength in interface PdfInput
Returns:
the length (in bytes) of the PDF document.

readBytes

public java.nio.ByteBuffer readBytes(long start,
                                     long end)
                              throws java.io.IOException
Description copied from interface: PdfInput
Returns a specified portion of a PDF document as a ByteBuffer.

Specified by:
readBytes in interface PdfInput
Parameters:
start - the offset position of the first byte to read.
end - the offset position at which to stop reading. (The byte at this offset is not included.)
Returns:
the requested portion of the PDF document.
Throws:
java.io.IOException

readChars

public java.nio.CharBuffer readChars(long start,
                                     long end)
                              throws java.io.IOException
Description copied from interface: PdfInput
Returns a specified portion of a PDF document as a CharBuffer.

Specified by:
readChars in interface PdfInput
Parameters:
start - the offset position of the first byte to read.
end - the offset position at which to stop reading. (The byte at this offset is not included.)
Returns:
the requested portion of the PDF document.
Throws:
java.io.IOException

getName

public java.lang.String getName()
Description copied from interface: PdfInput
Returns a name string associated of the PDF document.

Specified by:
getName in interface PdfInput
Returns:
the name of the PDF document.