public static String toStringBinary(final ByteBuffer b, int off, int len) {
    StringBuilder result = new StringBuilder();
    // Just in case we are passed a 'len' that is > buffer length...
    if (off >= b.capacity()) {
      return result.toString();
    }
    if (off + len > b.capacity()) {
      len = b.capacity() - off;
    }
    for (int i = off; i < off + len; ++i) {
      int ch = b.get(i) & 0xFF;
      if (
        (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')
          || " `~!@#$%^&*()-_=+[]{}|;:'\",.<>/?".indexOf(ch) >= 0
      ) {
        result.append((char) ch);
      } else {
        result.append(String.format("\\x%02X", ch));
      }
    }
    return result.toString();
  }
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