code: public static ByteBuffer allocateDirect(int capacity) {
          ByteBuffer buf = ByteBuffer.allocateDirect(capacity);
          buf.limit(0);
          return buf;
      }
docs: Allocate ByteBuffer in flush mode.
  The position and limit will both be zero, indicating that the buffer is
  empty and in flush mode.
  
  @param capacity capacity of the allocated ByteBuffer
  @return Buffer