Package org.apache.fontbox.cff
Class DataInputRandomAccessRead
- java.lang.Object
-
- org.apache.fontbox.cff.DataInputRandomAccessRead
-
- All Implemented Interfaces:
DataInput
public class DataInputRandomAccessRead extends java.lang.Object implements DataInput
This class implements the DataInput interface using a RandomAccessRead as source.
Note: things can get hairy when the underlying buffer is larger thanInteger.MAX_VALUE. Straight forward reading may work, butgetPosition()andsetPosition(int)may have problems.
-
-
Field Summary
Fields Modifier and Type Field Description private RandomAccessReadrandomAccessRead
-
Constructor Summary
Constructors Constructor Description DataInputRandomAccessRead(RandomAccessRead randomAccessRead)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetPosition()Returns the current position.booleanhasRemaining()Determines 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!intreadUnsignedByte()Read 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, wait
-
Methods inherited from interface org.apache.fontbox.cff.DataInput
readInt, readOffset, readShort, readUnsignedShort
-
-
-
-
Field Detail
-
randomAccessRead
private final RandomAccessRead randomAccessRead
-
-
Constructor Detail
-
DataInputRandomAccessRead
public DataInputRandomAccessRead(RandomAccessRead randomAccessRead)
Constructor.- Parameters:
randomAccessRead- the source to be read from
-
-
Method Detail
-
hasRemaining
public boolean hasRemaining() throws java.io.IOExceptionDetermines 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:
java.io.IOException- when the underlying buffer has already been closed.
-
getPosition
public int getPosition() throws java.io.IOExceptionReturns the current position.- Specified by:
getPositionin interfaceDataInput- Returns:
- current position.
- Throws:
java.io.IOException- when the underlying buffer has already been closed.
-
setPosition
public void setPosition(int position) throws java.io.IOExceptionSets 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:
java.io.IOException- if the new position is out of rangeor when the underlying buffer has already been closed.
-
readByte
public byte readByte() throws java.io.IOExceptionRead one single byte from the buffer.
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOExceptionRead one single unsigned byte from the buffer.- Specified by:
readUnsignedBytein interfaceDataInput- Returns:
- the unsigned byte as int.
- Throws:
java.io.IOException- when there are no bytes to read or when the underlying buffer has already been closed.
-
peekUnsignedByte
public int peekUnsignedByte(int offset) throws java.io.IOExceptionPeeks 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:
java.io.IOException- when the offset is negative or beyond end_of_buffer or when the underlying buffer has been closed already.
-
readBytes
public byte[] readBytes(int length) throws java.io.IOExceptionRead 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:
java.io.IOException- when there are less thanlengthbytes available or when the underlying buffer has already been closed.
-
-