class DataInputByteArray implements DataInput
{

    private final byte[] inputBuffer;
    private int bufferPosition = 0;

    /**
     * Constructor.
     * @param buffer the buffer to be read
     */
    public DataInputByteArray(byte[] buffer)
    {
        inputBuffer = buffer;
    }

    /**
     * Determines if there are any bytes left to read or not. 
     * @return true if there are any bytes left to read
     */
    @Override
    public boolean hasRemaining() throws IOException
    {
        return bufferPosition < inputBuffer.length;
    }

    /**
     * Returns the current position.
     * @return current position
     */
    @Override
    public int getPosition()
    {
        return bufferPosition;
    }

    /**
     * Sets the current position to the given value.
     * 
     * @param position the given position
     * @throws IOException if the new position ist out of range
     */
    @Override
    public void setPosition(int position) throws IOException
    {<FILL_FUNCTION_BODY>}

    /**
     * Read one single byte from the buffer.
     * @return the byte
     * @throws IOException if an error occurs during reading
     */
    @Override
    public byte readByte() throws IOException
    {
        if (!hasRemaining())
        {
            throw new IOException("End off buffer reached");
        }
        return inputBuffer[bufferPosition++];
    }

    /**
     * Read one single unsigned byte from the buffer.
     * @return the unsigned byte as int
     * @throws IOException if an error occurs during reading
     */
    @Override
    public int readUnsignedByte() throws IOException
    {
        if (!hasRemaining())
        {
            throw new IOException("End off buffer reached");
        }
        return inputBuffer[bufferPosition++] & 0xff;
    }

    /**
     * Peeks one single unsigned byte from the buffer.
     * 
     * @param offset offset to the byte to be peeked
     * @return the unsigned byte as int
     * @throws IOException if an error occurs during reading
     */
    @Override
    public int peekUnsignedByte(int offset) throws IOException
    {
        if (offset < 0)
        {
            throw new IOException("offset is negative");
        }
        if (bufferPosition + offset >= inputBuffer.length)
        {
            throw new IOException("Offset position is out of range " + (bufferPosition + offset)
                    + " >= " + inputBuffer.length);
        }
        return inputBuffer[bufferPosition + offset] & 0xff;
    }

    /**
     * Read a number of single byte values from the buffer.
     * @param length the number of bytes to be read
     * @return an array with containing the bytes from the buffer 
     * @throws IOException if an error occurs during reading
     */
    @Override
    public byte[] readBytes(int length) throws IOException
    {
        if (length < 0)
        {
            throw new IOException("length is negative"); 
        }
        if (inputBuffer.length - bufferPosition < length)
        {
            throw new IOException("Premature end of buffer reached");
        }
        byte[] bytes = new byte[length];
        System.arraycopy(inputBuffer, bufferPosition, bytes, 0, length);
        bufferPosition += length;
        return bytes;
    }

    @Override
    public int length() throws IOException
    {
        return inputBuffer.length;
    }
}

        if (position < 0)
        {
            throw new IOException("position is negative");
        }
        if (position >= inputBuffer.length)
        {
            throw new IOException(
                    "New position is out of range " + position + " >= " + inputBuffer.length);
        }
        bufferPosition = position;
    
<no_super_class>