Package com.itextpdf.io.source
Class RandomAccessFileOrArray
java.lang.Object
com.itextpdf.io.source.RandomAccessFileOrArray
- All Implemented Interfaces:
-
DataInput
Class that is used to unify reading from random access files and arrays.
-
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessFileOrArray(IRandomAccessSource byteSource) Creates a RandomAccessFileOrArray that wraps the specified byte source. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the underlying source.Creates the view of the byte source of this object.Creates an independent view of this object (with it's own file pointer and push back queue).longGets the current position of the source considering the pushed byte to the source.longlength()Gets the total amount of bytes in the source.intpeek()Gets the next byte without moving current position.intpeek(byte[] buffer) Gets the nextbuffer.lengthbytes without moving current position.voidpushBack(byte b) Pushes a byte back.intread()Reads a single byteintread(byte[] b) Reads the bytes to the buffer.intread(byte[] b, int off, int len) Reads the specified amount of bytes to the buffer applying the offset.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()voidseek(long pos) Sets the current position in the source to the specified index.longskip(long n) Make an attempt to skip the specified amount of bytes in source.intskipBytes(int n)
-
Constructor Details
-
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
-
-
Method Details
-
createView
Creates an independent view of this object (with it's own file pointer and push back 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
Creates the view of the byte source of this object. Closing the view won't affect this object. Closing source will have adverse effect on the view.- Returns:
- the byte source view.
-
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- in case of any reading error.
-
peek
Gets the next byte without moving current position.- Returns:
- the next byte, or -1 if EOF is reached
- Throws:
-
IOException- in case of any reading error.
-
peek
Gets the nextbuffer.lengthbytes without moving current position.- Parameters:
-
buffer- buffer to store read bytes - Returns:
-
the number of read bytes. If it is less than
buffer.lengthit means EOF has been reached. - Throws:
-
IOException- in case of any reading error.
-
read
Reads the specified amount of bytes to the buffer applying the offset.- Parameters:
-
b- destination buffer -
off- offset at which to start storing characters -
len- maximum number of characters to read - Returns:
- the number of bytes actually read or -1 in case of EOF
- Throws:
-
IOException- in case of any I/O error
-
read
Reads the bytes to the buffer. This method will try to read as many bytes as the buffer can hold.- Parameters:
-
b- the destination buffer - Returns:
- the number of bytes actually read
- Throws:
-
IOException- in case of any I/O error
-
readFully
- Specified by:
-
readFullyin interfaceDataInput - Throws:
-
IOException
-
readFully
- Specified by:
-
readFullyin interfaceDataInput - Throws:
-
IOException
-
skip
public long skip(long n) Make an attempt to skip the specified amount of bytes in source. However it may skip less amount of bytes. Possibly zero.- Parameters:
-
n- the number of bytes to skip - Returns:
- the actual number of bytes skipped
-
skipBytes
public int skipBytes(int n) -
close
Closes the underlying source.- Throws:
-
IOException- in case of any I/O error.
-
length
public long length()Gets the total amount of bytes in the source.- Returns:
- source's size.
-
seek
public void seek(long pos) Sets the current position in the source to the specified index.- Parameters:
-
pos- the position to set
-
getPosition
public long getPosition()Gets the current position of the source considering the pushed byte to the source.- Returns:
- the index of last read byte in the source in or the index of last read byte in source - 1 in case byte was pushed.
-
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) | 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:
-
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) + 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:
-
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 read -
encoding- the given encoding - Returns:
-
the
Stringread - Throws:
-
IOException- the font file could not be read
-