protected int readUShort(int length, boolean bigEndian) throws IOException {
        if (length > 2 || length < 1)
            throw new IOException();
        if (length == 1)
            return input.read();
        else if (bigEndian)
            return ((input.read() * 256) + (input.read()));
        else
            return ((input.read()) + (input.read() * 256));
    }