code: public static ByteBuffer slice(ByteBuffer buffer, int length) {
          final int l = buffer.limit();
          buffer.limit(buffer.position() + length);
          final ByteBuffer slice = buffer.slice();
          buffer.limit(l);
          buffer.position(buffer.position() + length);
          return slice;
      }
docs: Returns a newly allocated {@link ByteBuffer#slice()}, starting from the current {@link ByteBuffer#position() position}, of
  a given {@link ByteBuffer}. The slice and the original buffer will share their contents. <br> Upon return from this
  method, the original buffer's {@link ByteBuffer#position() position} will have advanced by {@code length}, and the returned
  buffer's position will be 0.
  <p>
  This method is not thread-safe.
  
  @param buffer The buffer to slice.
  @param length The length in bytes of the slice.
  @return A slice of the buffer.
  @see ByteBuffer#slice()