code: public static void boundsCheck(final byte[] buffer, final long index, final int length)
      {
          final int capacity = buffer.length;
          final long resultingPosition = index + (long)length;
          if (index < 0 || resultingPosition > capacity)
          {
              throw new IndexOutOfBoundsException("index=" + index + " length=" + length + " capacity=" + capacity);
          }
      }
docs: Bounds check the access range and throw a {@link IndexOutOfBoundsException} if exceeded.
  
  @param buffer to be checked.
  @param index  at which the access will begin.
  @param length of the range accessed.