Package com.lowagie.text.pdf
Class RandomAccessFileOrArray
java.lang.Object
com.lowagie.text.pdf.RandomAccessFileOrArray
- All Implemented Interfaces:
Closeable
,DataInput
,AutoCloseable
An implementation of a RandomAccessFile for input only that accepts a file or a byte array as data source.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) byte[]
(package private) int
(package private) byte
(package private) String
(package private) boolean
(package private) boolean
(package private) MappedRandomAccessFile
private int
Holds value of property startOffset.(package private) RandomAccessFile
-
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessFileOrArray
(byte[] arrayIn) RandomAccessFileOrArray
(String filename) RandomAccessFileOrArray
(String filename, boolean forceRead, boolean plainRandomAccess) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
int
int
Getter for property startOffset.static byte[]
protected void
boolean
isOpen()
int
length()
void
pushBack
(byte b) int
read()
int
read
(byte[] b) int
read
(byte[] b, int off, int len) boolean
byte
readByte()
char
readChar()
final char
Reads a Unicode character from this stream in little-endian order.double
final double
float
final float
void
readFully
(byte[] b) void
readFully
(byte[] b, int off, int len) int
readInt()
final int
Reads a signed 32-bit integer from this stream in little-endian order.readLine()
long
readLong()
final long
short
final short
Reads a signed 16-bit number from this stream in little-endian order.int
final long
Reads an unsigned 32-bit integer from this stream.final long
int
final int
Reads an unsigned 16-bit number from this stream in little-endian order.readUTF()
void
reOpen()
void
seek
(int pos) void
seek
(long pos) void
setStartOffset
(int startOffset) Setter for property startOffset.long
skip
(long n) int
skipBytes
(int n)
-
Field Details
-
rf
-
trf
RandomAccessFile trf -
plainRandomAccess
boolean plainRandomAccess -
filename
String filename -
arrayIn
byte[] arrayIn -
arrayInPtr
int arrayInPtr -
back
byte back -
isBack
boolean isBack -
startOffset
private int startOffsetHolds value of property startOffset.
-
-
Constructor Details
-
RandomAccessFileOrArray
- Throws:
IOException
-
RandomAccessFileOrArray
public RandomAccessFileOrArray(String filename, boolean forceRead, boolean plainRandomAccess) throws IOException - Throws:
IOException
-
RandomAccessFileOrArray
- Throws:
IOException
-
RandomAccessFileOrArray
- Throws:
IOException
-
RandomAccessFileOrArray
public RandomAccessFileOrArray(byte[] arrayIn) -
RandomAccessFileOrArray
-
-
Method Details
-
InputStreamToArray
- Throws:
IOException
-
pushBack
public void pushBack(byte b) -
read
- Throws:
IOException
-
read
- Throws:
IOException
-
read
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
skip
- Throws:
IOException
-
skipBytes
- Specified by:
skipBytes
in interfaceDataInput
- Throws:
IOException
-
reOpen
- Throws:
IOException
-
insureOpen
- Throws:
IOException
-
isOpen
public boolean isOpen() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
length
- Throws:
IOException
-
seek
- Throws:
IOException
-
seek
- Throws:
IOException
-
getFilePointer
- Throws:
IOException
-
readBoolean
- Specified by:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
readByte
- Specified by:
readByte
in interfaceDataInput
- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedByte
in interfaceDataInput
- Throws:
IOException
-
readShort
- Specified by:
readShort
in 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, areb1
andb2
, where each of the two values is between0
and255
, 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:
readUnsignedShort
in 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, areb1
andb2
, where0 <= b1, b2 <= 255
, then the result is equal to:(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 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:
readChar
in 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, areb1
andb2
, 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:
readInt
in 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) + b1
This 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) + b4
This 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:
readLong
in interfaceDataInput
- Throws:
IOException
-
readLongLE
- Throws:
IOException
-
readFloat
- Specified by:
readFloat
in interfaceDataInput
- Throws:
IOException
-
readFloatLE
- Throws:
IOException
-
readDouble
- Specified by:
readDouble
in interfaceDataInput
- Throws:
IOException
-
readDoubleLE
- Throws:
IOException
-
readLine
- Specified by:
readLine
in interfaceDataInput
- Throws:
IOException
-
readUTF
- Specified by:
readUTF
in interfaceDataInput
- Throws:
IOException
-
getStartOffset
public int getStartOffset()Getter for property startOffset.- Returns:
- Value of property startOffset.
-
setStartOffset
public void setStartOffset(int startOffset) Setter for property startOffset.- Parameters:
startOffset
- New value of property startOffset.
-
getNioByteBuffer
- Returns:
- a ByteBuffer
- Throws:
IOException
- on error- Since:
- 2.0.8
-