org.apache.fontbox.cff

## Class DataInputRandomAccessRead

- java.lang.Object
- - org.apache.fontbox.cff.DataInputRandomAccessRead

All Implemented Interfaces:
  DataInput

    public class DataInputRandomAccessRead
    extends 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 than `Integer.MAX_VALUE`. Straight forward reading may work, but `getPosition()` and `setPosition(int)` may have problems.

### Constructor Summary

Constructors
Constructor and Description
`DataInputRandomAccessRead(org.apache.pdfbox.io.RandomAccessRead randomAccessRead)` Constructor.

### Method Summary

All Methods Instance Methods Concrete Methods
`int` `getPosition()` Returns the current position.
`boolean` `hasRemaining()` Determines if there are any bytes left to read or not.
`int` `length()`
`int` `peekUnsignedByte(int offset)` Peeks one single unsigned byte from the buffer.
`byte` `readByte()` Read one single byte from the buffer.
`byte[]` `readBytes(int length)` Read a number of single byte values from the buffer. Note: when `readBytes(5)` is called, but there are only 3 bytes available, the caller gets an IOException, not the 3 bytes!
`int` `readUnsignedByte()` Read one single unsigned byte from the buffer.
`void` `setPosition(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`

### Constructor Detail

#### DataInputRandomAccessRead

    public DataInputRandomAccessRead(org.apache.pdfbox.io.RandomAccessRead randomAccessRead)

Constructor.

Parameters:
  `randomAccessRead` - the source to be read from

### Method Detail

#### hasRemaining

    public boolean hasRemaining()
                         throws IOException

Determines if there are any bytes left to read or not.

Specified by:
  `hasRemaining` in interface `DataInput`
Returns:
  true if there are any bytes left to read.
Throws:
  `IOException` - when the underlying buffer has already been closed.

#### getPosition

    public int getPosition()
                    throws IOException

Returns the current position.

Specified by:
  `getPosition` in interface `DataInput`
Returns:
  current position.
Throws:
  `IOException` - when the underlying buffer has already been closed.

#### setPosition

    public void setPosition(int position)
                     throws IOException

Sets the current absolute position to the given value. You cannot use `setPosition(-20)` to move 20 bytes back!

Specified by:
  `setPosition` in interface `DataInput`
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

    public byte readByte()
                  throws IOException

Read one single byte from the buffer.

Specified by:
  `readByte` in interface `DataInput`
Returns:
  the byte.
Throws:
  `IOException` - when there are no bytes to read or when the underlying buffer has already been closed.

#### readUnsignedByte

    public int readUnsignedByte()
                         throws IOException

Read one single unsigned byte from the buffer.

Specified by:
  `readUnsignedByte` in interface `DataInput`
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

    public int peekUnsignedByte(int offset)
                         throws IOException

Peeks one single unsigned byte from the buffer.

Specified by:
  `peekUnsignedByte` in interface `DataInput`
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

    public byte[] readBytes(int length)
                     throws IOException

Read a number of single byte values from the buffer.
Note: when `readBytes(5)` is called, but there are only 3 bytes available, the caller gets an IOException, not the 3 bytes!

Specified by:
  `readBytes` in interface `DataInput`
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 than `length` bytes available or when the underlying buffer has already been closed.

#### length

    public int length()
               throws IOException

Specified by:
  `length` in interface `DataInput`
Throws:
  `IOException`