Package com.aowagie.text.pdf
Class RandomAccessFileOrArray
- java.lang.Object
-
- com.aowagie.text.pdf.RandomAccessFileOrArray
-
- All Implemented Interfaces:
java.io.DataInput
public class RandomAccessFileOrArray extends java.lang.Object implements java.io.DataInput
An implementation of a RandomAccessFile for input only that accepts a file or a byte array as data source.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
arrayIn
private int
arrayInPtr
private byte
back
private java.lang.String
filename
private boolean
isBack
private boolean
plainRandomAccess
private MappedRandomAccessFile
rf
private int
startOffset
Holds value of property startOffset.private java.io.RandomAccessFile
trf
-
Constructor Summary
Constructors Constructor Description RandomAccessFileOrArray(byte[] arrayIn)
RandomAccessFileOrArray(RandomAccessFileOrArray file)
RandomAccessFileOrArray(java.io.InputStream is)
RandomAccessFileOrArray(java.lang.String filename)
RandomAccessFileOrArray(java.lang.String filename, boolean forceRead, boolean plainRandomAccess)
RandomAccessFileOrArray(java.net.URL url)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
int
getFilePointer()
java.nio.ByteBuffer
getNioByteBuffer()
int
getStartOffset()
Getter for property startOffset.private static byte[]
InputStreamToArray(java.io.InputStream is)
private void
insureOpen()
boolean
isOpen()
int
length()
(package private) void
pushBack(byte b)
int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
boolean
readBoolean()
byte
readByte()
char
readChar()
double
readDouble()
double
readDoubleLE()
float
readFloat()
float
readFloatLE()
void
readFully(byte[] b)
void
readFully(byte[] b, int off, int len)
int
readInt()
int
readIntLE()
Reads a signed 32-bit integer from this stream in little-endian order.java.lang.String
readLine()
long
readLong()
long
readLongLE()
short
readShort()
short
readShortLE()
Reads a signed 16-bit number from this stream in little-endian order.int
readUnsignedByte()
long
readUnsignedInt()
Reads an unsigned 32-bit integer from this stream.long
readUnsignedIntLE()
int
readUnsignedShort()
int
readUnsignedShortLE()
Reads an unsigned 16-bit number from this stream in little-endian order.java.lang.String
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 Detail
-
rf
private MappedRandomAccessFile rf
-
trf
private java.io.RandomAccessFile trf
-
plainRandomAccess
private boolean plainRandomAccess
-
filename
private java.lang.String filename
-
arrayIn
private byte[] arrayIn
-
arrayInPtr
private int arrayInPtr
-
back
private byte back
-
isBack
private boolean isBack
-
startOffset
private int startOffset
Holds value of property startOffset.
-
-
Constructor Detail
-
RandomAccessFileOrArray
public RandomAccessFileOrArray(java.lang.String filename) throws java.io.IOException
- Throws:
java.io.IOException
-
RandomAccessFileOrArray
RandomAccessFileOrArray(java.lang.String filename, boolean forceRead, boolean plainRandomAccess) throws java.io.IOException
- Throws:
java.io.IOException
-
RandomAccessFileOrArray
public RandomAccessFileOrArray(java.net.URL url) throws java.io.IOException
- Throws:
java.io.IOException
-
RandomAccessFileOrArray
RandomAccessFileOrArray(java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.IOException
-
RandomAccessFileOrArray
public RandomAccessFileOrArray(byte[] arrayIn)
-
RandomAccessFileOrArray
RandomAccessFileOrArray(RandomAccessFileOrArray file)
-
-
Method Detail
-
InputStreamToArray
private static byte[] InputStreamToArray(java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.IOException
-
pushBack
void pushBack(byte b)
-
read
public int read() throws java.io.IOException
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException
- Throws:
java.io.IOException
-
skipBytes
public int skipBytes(int n) throws java.io.IOException
- Specified by:
skipBytes
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
reOpen
public void reOpen() throws java.io.IOException
- Throws:
java.io.IOException
-
insureOpen
private void insureOpen() throws java.io.IOException
- Throws:
java.io.IOException
-
isOpen
public boolean isOpen()
-
close
public void close() throws java.io.IOException
- Throws:
java.io.IOException
-
length
public int length() throws java.io.IOException
- Throws:
java.io.IOException
-
seek
public void seek(int pos) throws java.io.IOException
- Throws:
java.io.IOException
-
seek
public void seek(long pos) throws java.io.IOException
- Throws:
java.io.IOException
-
getFilePointer
public int getFilePointer() throws java.io.IOException
- Throws:
java.io.IOException
-
readBoolean
public boolean readBoolean() throws java.io.IOException
- Specified by:
readBoolean
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readByte
public byte readByte() throws java.io.IOException
- Specified by:
readByte
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOException
- Specified by:
readUnsignedByte
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readShort
public short readShort() throws java.io.IOException
- Specified by:
readShort
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readShortLE
public final short readShortLE() throws java.io.IOException
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:
java.io.EOFException
- if this stream reaches the end before reading two bytes.java.io.IOException
- if an I/O error occurs.
-
readUnsignedShort
public int readUnsignedShort() throws java.io.IOException
- Specified by:
readUnsignedShort
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUnsignedShortLE
public final int readUnsignedShortLE() throws java.io.IOException
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:
java.io.EOFException
- if this stream reaches the end before reading two bytes.java.io.IOException
- if an I/O error occurs.
-
readChar
public char readChar() throws java.io.IOException
- Specified by:
readChar
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readInt
public int readInt() throws java.io.IOException
- Specified by:
readInt
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readIntLE
public final int readIntLE() throws java.io.IOException
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:
java.io.EOFException
- if this stream reaches the end before reading four bytes.java.io.IOException
- if an I/O error occurs.
-
readUnsignedInt
public final long readUnsignedInt() throws java.io.IOException
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:
java.io.EOFException
- if this stream reaches the end before reading four bytes.java.io.IOException
- if an I/O error occurs.
-
readUnsignedIntLE
public final long readUnsignedIntLE() throws java.io.IOException
- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException
- Specified by:
readLong
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readLongLE
public final long readLongLE() throws java.io.IOException
- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException
- Specified by:
readFloat
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFloatLE
public final float readFloatLE() throws java.io.IOException
- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException
- Specified by:
readDouble
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readDoubleLE
public final double readDoubleLE() throws java.io.IOException
- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine() throws java.io.IOException
- Specified by:
readLine
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUTF
public java.lang.String readUTF() throws java.io.IOException
- Specified by:
readUTF
in interfacejava.io.DataInput
- Throws:
java.io.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
public java.nio.ByteBuffer getNioByteBuffer() throws java.io.IOException
- Returns:
- a buffer of nio bytes
- Throws:
java.io.IOException
- Exception with information about a IO error- Since:
- 2.0.8
-
-