Class RandomAccessFileOrArray
java.lang.Object
com.itextpdf.text.pdf.RandomAccessFileOrArray
- All Implemented Interfaces:
DataInput
Intended to be layered on top of a low level RandomAccessSource object. Provides
functionality useful during parsing:
- tracks current position in the file
- allows single byte pushback
- allows reading of multi-byte data structures (int, long, String) for both Big and Little Endian representations
- allows creation of independent 'views' of the underlying data source
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate bytethe pushed back byte, if anyprivate final RandomAccessSourceThe source that backs this objectprivate longThe physical location in the underlying byte source.private booleanWhether there is a pushed back byte -
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessFileOrArray(byte[] arrayIn) Deprecated.RandomAccessFileOrArray(RandomAccessSource byteSource) Creates a RandomAccessFileOrArray that wraps the specified byte source.Deprecated.usecreateView()insteadDeprecated.RandomAccessFileOrArray(String filename) Deprecated.useRandomAccessFileOrArray(RandomAccessSource)insteadRandomAccessFileOrArray(String filename, boolean forceRead, boolean plainRandomAccess) Deprecated.Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Creates an independent view of this object (with it's own file pointer and pushback queue).protected RandomAccessSourceDeprecated.longlonglength()voidpushBack(byte b) Pushes a byte back.intread()Reads a single byteintread(byte[] b) intread(byte[] b, int off, int len) booleanbytereadByte()charreadChar()final charReads a Unicode character from this stream in little-endian order.doublefinal doublefloatfinal floatvoidreadFully(byte[] b) voidreadFully(byte[] b, int off, int len) intreadInt()final intReads a signed 32-bit integer from this stream in little-endian order.readLine()longreadLong()final longshortfinal shortReads a signed 16-bit number from this stream in little-endian order.readString(int length, String encoding) Reads aStringfrom the font file as bytes using the given encoding.intfinal longReads an unsigned 32-bit integer from this stream.final longintfinal intReads an unsigned 16-bit number from this stream in little-endian order.readUTF()voidreOpen()Deprecated.voidseek(long pos) longskip(long n) intskipBytes(int n)
-
Field Details
-
byteSource
The source that backs this object -
byteSourcePosition
private long byteSourcePositionThe physical location in the underlying byte source. -
back
private byte backthe pushed back byte, if any -
isBack
private boolean isBackWhether there is a pushed back byte
-
-
Constructor Details
-
RandomAccessFileOrArray
Deprecated.useRandomAccessFileOrArray(RandomAccessSource)instead- Parameters:
filename-- Throws:
IOException
-
RandomAccessFileOrArray
Deprecated.usecreateView()insteadCreates an independent view of the specified source. Closing the new object will not close the source. Closing the source will have adverse effect on the behavior of the new view.- Parameters:
source- the source for the new independent view
-
RandomAccessFileOrArray
Creates a RandomAccessFileOrArray that wraps the specified byte source. The byte source will be closed when this RandomAccessFileOrArray is closed.- Parameters:
byteSource- the byte source to wrap
-
RandomAccessFileOrArray
@Deprecated public RandomAccessFileOrArray(String filename, boolean forceRead, boolean plainRandomAccess) throws IOException Deprecated.Constructs a new RandomAccessFileOrArrayObject- Parameters:
filename- the file to open (can be a file system file or one of the following url strings: file://, http://, https://, jar:, wsjar:, vfszip:forceRead- if true, the entire file will be read into memoryplainRandomAccess- if true, a regular RandomAccessFile is used to access the file contents. If false, a memory mapped file will be used, unless the file cannot be mapped into memory, in which case regular RandomAccessFile will be used- Throws:
IOException- if there is a failure opening or reading the file
-
RandomAccessFileOrArray
Deprecated.- Parameters:
url-- Throws:
IOException
-
RandomAccessFileOrArray
Deprecated.- Parameters:
is-- Throws:
IOException
-
RandomAccessFileOrArray
Deprecated.- Parameters:
arrayIn- byte[]- Throws:
IOException
-
-
Method Details
-
createView
Creates an independent view of this object (with it's own file pointer and pushback queue). Closing the new object will not close this object. Closing this object will have adverse effect on the view.- Returns:
- the new view
-
createSourceView
-
getByteSource
Deprecated. -
pushBack
public void pushBack(byte b) Pushes a byte back. The next get() will return this byte instead of the value from the underlying data source- Parameters:
b- the byte to push
-
read
Reads a single byte- Returns:
- the byte, or -1 if EOF is reached
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
skip
- Throws:
IOException
-
skipBytes
- Specified by:
skipBytesin interfaceDataInput- Throws:
IOException
-
reOpen
-
close
- Throws:
IOException
-
length
- Throws:
IOException
-
seek
- Throws:
IOException
-
getFilePointer
- Throws:
IOException
-
readBoolean
- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
readByte
- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IOException
-
readShort
- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readShortLE
Reads a signed 16-bit number from this stream in little-endian order. The method reads two bytes from this stream, starting at the current stream pointer. If the two bytes read, in order, areb1andb2, where each of the two values is between0and255, inclusive, then the result is equal to:(short)((b2 << 8) | b1)This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
- Returns:
- the next two bytes of this stream, interpreted as a signed 16-bit number.
- Throws:
EOFException- if this stream reaches the end before reading two bytes.IOException- if an I/O error occurs.
-
readUnsignedShort
- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
readUnsignedShortLE
Reads an unsigned 16-bit number from this stream in little-endian order. This method reads two bytes from the stream, starting at the current stream pointer. If the bytes read, in order, areb1andb2, where0 <= b1, b2 <= 255, then the result is equal to:(b2 << 8) | b1This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
- Returns:
- the next two bytes of this stream, interpreted as an unsigned 16-bit integer.
- Throws:
EOFException- if this stream reaches the end before reading two bytes.IOException- if an I/O error occurs.
-
readChar
- Specified by:
readCharin interfaceDataInput- Throws:
IOException
-
readCharLE
Reads a Unicode character from this stream in little-endian order. This method reads two bytes from the stream, starting at the current stream pointer. If the bytes read, in order, areb1andb2, where0 <= b1, b2 <= 255, then the result is equal to:(char)((b2 << 8) | b1)This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.
- Returns:
- the next two bytes of this stream as a Unicode character.
- Throws:
EOFException- if this stream reaches the end before reading two bytes.IOException- if an I/O error occurs.
-
readInt
- Specified by:
readIntin interfaceDataInput- Throws:
IOException
-
readIntLE
Reads a signed 32-bit integer from this stream in little-endian order. This method reads 4 bytes from the stream, starting at the current stream pointer. If the bytes read, in order, areb1,b2,b3, andb4, where0 <= b1, b2, b3, b4 <= 255, then the result is equal to:(b4 << 24) | (b3 << 16) + (b2 << 8) + b1This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
- Returns:
- the next four bytes of this stream, interpreted as an
int. - Throws:
EOFException- if this stream reaches the end before reading four bytes.IOException- if an I/O error occurs.
-
readUnsignedInt
Reads an unsigned 32-bit integer from this stream. This method reads 4 bytes from the stream, starting at the current stream pointer. If the bytes read, in order, areb1,b2,b3, andb4, where0 <= b1, b2, b3, b4 <= 255, then the result is equal to:(b1 << 24) | (b2 << 16) + (b3 << 8) + b4This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.
- Returns:
- the next four bytes of this stream, interpreted as a
long. - Throws:
EOFException- if this stream reaches the end before reading four bytes.IOException- if an I/O error occurs.
-
readUnsignedIntLE
- Throws:
IOException
-
readLong
- Specified by:
readLongin interfaceDataInput- Throws:
IOException
-
readLongLE
- Throws:
IOException
-
readFloat
- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readFloatLE
- Throws:
IOException
-
readDouble
- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readDoubleLE
- Throws:
IOException
-
readLine
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
readUTF
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
readString
Reads aStringfrom the font file as bytes using the given encoding.- Parameters:
length- the length of bytes to readencoding- the given encoding- Returns:
- the
Stringread - Throws:
IOException- the font file could not be read
-
RandomAccessSourceFactory.createSource(byte[])andRandomAccessFileOrArray(RandomAccessSource)instead