public static byte[] copyOfRange(ByteBuffer original, int from, int to) {
    int newLength = to - from;
    if (newLength < 0) {
      throw new IllegalArgumentException(from + " > " + to);
    }
    byte[] copy = new byte[newLength];
    ByteBufferUtils.copyFromBufferToArray(copy, original, from, 0, newLength);
    return copy;
  }
Similar to {@link Arrays#copyOfRange(byte[], int, int)}
@param original the buffer from which the copy has to happen
@param from     the starting index
@param to       the ending index
@return a byte[] created out of the copy
hbase-common/src/main/java/org/apache/hadoop/hbase/util/ByteBufferUtils.java