code: public static void flipToFlush(ByteBuffer buffer, int position) {
          buffer.limit(buffer.position());
          buffer.position(position);
      }
docs: Flip the buffer to Flush mode.
  The limit is set to the first unused byte(the old position) and
  the position is set to the passed position.
  <p>
  This method is used as a replacement of {@link Buffer#flip()}.
  
  @param buffer   the buffer to be flipped
  @param position The position of valid data to flip to. This should
  be the return value of the previous call to {@link #flipToFill(ByteBuffer)}