code: public int drainTo(Collection<? super T> c, int max_elements) {
          int num=Math.min(count, max_elements); // count may increase in the mean time, but that's ok
          if(num == 0)
              return num;
          int read_index=ri; // no lock as we're the only reader
          for(int i=0; i < num; i++) {
              int real_index=realIndex(read_index +i);
              c.add(buf[real_index]);
              buf[real_index]=null;
          }
          publishReadIndex(num);
          return num;
      }
docs: Removes a number of messages and adds them to c.
  Same semantics as {@link java.util.concurrent.BlockingQueue#drainTo(Collection,int)}.
  @param c The collection to which to add the removed messages.
  @param max_elements The max number of messages to remove. The actual number of messages removed may be smaller
  if the buffer has fewer elements
  @return The number of messages removed
  @throws NullPointerException If c is null