|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.etymon.pjx.PdfInputBuffer
public class PdfInputBuffer
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 entire buffer is stored in memory (except in the case
of PdfInputBuffer(File,
true)
); having the buffer in memory generally improves processing
speed as compared to PdfInputFile
, but of
course it requires the memory to be available and therefore puts
greater stress on system resources. For large PDF documents, it is
normally better to use PdfInputFile
instead.
This class is synchronized; however, note that since
it acts as a wrapper around a buffer (in the case of PdfInputBuffer(ByteBuffer,
String)
), it is the calling method's responsibility to ensure that
the buffer is not modified externally to this class. In the case
of PdfInputBuffer(File)
or PdfInputBuffer(File, false)
, the
constructor reads the entire file into a buffer and that buffer is
not externally accessible; so there is no such danger. However,
PdfInputBuffer(File, true)
leaves the file open, and therefore the calling method must ensure
that the file is not modified externally to this class.
Field Summary | |
---|---|
protected java.nio.ByteBuffer |
_bbuf
The byte buffer containing the PDF raw data. |
protected java.nio.CharBuffer |
_cbuf
The char buffer associated with _bbuf . |
protected java.nio.channels.FileChannel |
_fileChannel
The file channel associated with the PDF document. |
protected java.io.FileInputStream |
_fileInputStream
The file input stream associated with the PDF document. |
protected java.lang.String |
_name
The file name or assigned name of this buffer. |
Constructor Summary | |
---|---|
PdfInputBuffer(java.nio.ByteBuffer pdfBuffer,
java.lang.String name)
Constructs a PDF input source based on a specified ByteBuffer . |
|
PdfInputBuffer(java.io.File pdfFile)
Constructs a PDF input source based on a specified file. |
|
PdfInputBuffer(java.io.File pdfFile,
boolean memoryMapped)
Constructs a PDF input source based on a specified file, with optional memory-mapping. |
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. |
protected void |
init()
Performs initialization common to multiple constructors of this class. |
protected void |
initBuffer()
Performs initialization common to multiple constructors of this class. |
protected void |
initFile(java.io.File pdfFile,
boolean memoryMapped)
Performs initialization common to multiple constructors of this class. |
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 |
---|
protected java.nio.ByteBuffer _bbuf
protected java.nio.CharBuffer _cbuf
_bbuf
.
protected java.nio.channels.FileChannel _fileChannel
protected java.io.FileInputStream _fileInputStream
protected java.lang.String _name
Constructor Detail |
---|
public PdfInputBuffer(java.nio.ByteBuffer pdfBuffer, java.lang.String name) throws java.io.IOException
ByteBuffer
. The buffer is read starting at its
current position until no more bytes are remaining. It is
the calling method's responsibility to ensure that the
buffer is not modified externally to this class. A name can
optionally be assigned to this document for identification.
pdfBuffer
- the source buffer.name
- the name to assign to the document (or
null
if no name is to be assigned).
java.io.IOException
public PdfInputBuffer(java.io.File pdfFile) throws java.io.IOException
PdfInputBuffer(File, false)
; i.e. this constructor reads
the entire file into memory and closes the file, and the
file is not memory-mapped. The size of the file must not be
greater than 231-1; use PdfInputFile
for huge files.
pdfFile
- the source file.
java.io.IOException
public PdfInputBuffer(java.io.File pdfFile, boolean memoryMapped) throws java.io.IOException
PdfInputFile
makes more sense in order to minimize stress
on system resources; therefore using the memory-mapping
feature is not generally recommended. The size of the file
must not be greater than 231-1; use PdfInputFile
for huge files.
pdfFile
- the source file.memoryMapped
- specifies whether the file is to be
memory-mapped. A value of true
enables
memory-mapping.
java.io.IOException
Method Detail |
---|
public void close() throws java.io.IOException
java.io.IOException
protected void init()
protected void initBuffer()
protected void initFile(java.io.File pdfFile, boolean memoryMapped) throws java.io.IOException
java.io.IOException
public java.nio.ByteBuffer readBytes(long start, long end) throws java.io.IOException
PdfInput
ByteBuffer
.
readBytes
in interface PdfInput
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.)
java.io.IOException
public java.nio.CharBuffer readChars(long start, long end) throws java.io.IOException
PdfInput
CharBuffer
.
readChars
in interface PdfInput
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.)
java.io.IOException
public long getLength()
PdfInput
getLength
in interface PdfInput
public java.lang.String getName()
PdfInput
getName
in interface PdfInput
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |