code: private void checkIndex(final long index) throws IndexOutOfBoundsException {
          final long missingBytes = index + 1 - this.writerIndex;
          if (missingBytes <= 0) {
              // we got all the bytes needed
              return;
          }
  
          try {
              final int read = readFromStream(missingBytes);
              if (read == -1 || read < missingBytes) {
                  throw new IndexOutOfBoundsException();
              }
          } catch (final IOException e) {
              throw new IndexOutOfBoundsException();
          }
      }
docs: Convenience method for checking if we can get the byte at the specified
  index. If we can't, then we will try and read the missing bytes off of
  the underlying {@link InputStream}. If that fails, e.g. we don't ready
  enough bytes off of the stream, then we will eventually throw an
  {@link IndexOutOfBoundsException}
  
  @param index
  the actual index to check. I.e., this is the actual index in
  our byte array, irrespective of what the lowerBoundary is set
  to.
  @throws IndexOutOfBoundsException
  @throws IOException