Package org.apache.fontbox.cff
Class DataInputRandomAccessRead
java.lang.Object
org.apache.fontbox.cff.DataInputRandomAccessRead
- All Implemented Interfaces:
DataInput
This class implements the DataInput interface using a RandomAccessRead as source.
Note: things can get hairy when the underlying buffer is larger than
Note: things can get hairy when the underlying buffer is larger than
Integer.MAX_VALUE.
Straight forward reading may work, but getPosition() and setPosition(int)
may have problems.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the current position.booleanDetermines if there are any bytes left to read or not.intlength()intpeekUnsignedByte(int offset) Peeks one single unsigned byte from the buffer.bytereadByte()Read one single byte from the buffer.byte[]readBytes(int length) Read a number of single byte values from the buffer.
Note: whenreadBytes(5)is called, but there are only 3 bytes available, the caller gets an IOException, not the 3 bytes!intRead one single unsigned byte from the buffer.voidsetPosition(int position) Sets the current absolute position to the given value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.fontbox.cff.DataInput
readInt, readOffset, readShort, readUnsignedShort
-
Field Details
-
randomAccessRead
-
-
Constructor Details
-
DataInputRandomAccessRead
Constructor.- Parameters:
randomAccessRead- the source to be read from
-
-
Method Details
-
hasRemaining
Determines if there are any bytes left to read or not.- Specified by:
hasRemainingin interfaceDataInput- Returns:
- true if there are any bytes left to read.
- Throws:
IOException- when the underlying buffer has already been closed.
-
getPosition
Returns the current position.- Specified by:
getPositionin interfaceDataInput- Returns:
- current position.
- Throws:
IOException- when the underlying buffer has already been closed.
-
setPosition
Sets the current absolute position to the given value. You cannot usesetPosition(-20)to move 20 bytes back!- Specified by:
setPositionin interfaceDataInput- Parameters:
position- the given position, must be 0 ≤ position < length.- Throws:
IOException- if the new position is out of rangeor when the underlying buffer has already been closed.
-
readByte
Read one single byte from the buffer.- Specified by:
readBytein interfaceDataInput- Returns:
- the byte.
- Throws:
IOException- when there are no bytes to reador when the underlying buffer has already been closed.
-
readUnsignedByte
Read one single unsigned byte from the buffer.- Specified by:
readUnsignedBytein interfaceDataInput- Returns:
- the unsigned byte as int.
- Throws:
IOException- when there are no bytes to read or when the underlying buffer has already been closed.
-
peekUnsignedByte
Peeks one single unsigned byte from the buffer.- Specified by:
peekUnsignedBytein interfaceDataInput- Parameters:
offset- offset to the byte to be peeked, must be 0 ≤ offset.- Returns:
- the unsigned byte as int.
- Throws:
IOException- when the offset is negative or beyond end_of_buffer or when the underlying buffer has been closed already.
-
readBytes
Read a number of single byte values from the buffer.
Note: whenreadBytes(5)is called, but there are only 3 bytes available, the caller gets an IOException, not the 3 bytes!- Specified by:
readBytesin interfaceDataInput- Parameters:
length- the number of bytes to be read, must be 0 ≤ length.- Returns:
- an array with containing the bytes from the buffer.
- Throws:
IOException- when there are less thanlengthbytes available or when the underlying buffer has already been closed.
-
length
- Specified by:
lengthin interfaceDataInput- Throws:
IOException
-