* Release resources and return the externally supplied memory segments. This method does not
   * necessarily return the memory segments, in the case when an exception occurred.
   * @throws IOException Thrown, if an exception occurred while processing remaining requests.
  public List<MemorySegment> close() throws IOException {
    // list to collect segments in
    final ArrayList<MemorySegment> segments = new ArrayList<MemorySegment>(this.numBuffers);

    // get all segments from the return buffer queue
    try {
      while (segments.size() < this.numBuffers) {
        final T buffer = this.returnBuffers.take();

        // check the error state of this channel after each segment and raise the exception in case
    } catch (InterruptedException iex) {
      // when the process of waiting for the empty segments is interrupted, we call for an exception
      throw new IOException(
          "The channel closing was interrupted. "
              + "Its not guaranteed that all buffers have been properly written.");

    return segments;
Example #2
 public void dispose() {