static public long readAllAsync(final IAsyncOpener opener,final List<AsyncTransfer> transfers) throws IOException {
  int ntries=0;
  long totalBytesRead=0;
  final long totalBytesExpected;
{
    long n=0;
    for (    AsyncTransfer transfer : transfers) {
      n+=transfer.m_bytesToRead;
    }
    totalBytesExpected=n;
  }
  try {
    while (true) {
      ntries++;
      if (ntries == 100) {
        log.warn("reading on channel: remaining=" + (totalBytesExpected - totalBytesRead) + ", ntransfers="+ transfers.size()+ ", ntries="+ ntries+ ", bytesRead="+ totalBytesRead);
      }
 else       if (ntries == 1000) {
        log.error("reading on channel: remaining=" + (totalBytesExpected - totalBytesRead) + ", ntransfers="+ transfers.size()+ ", ntries="+ ntries+ ", bytesRead="+ totalBytesRead);
      }
 else       if (ntries > 10000) {
        throw new RuntimeException("reading on channel: remaining=" + (totalBytesExpected - totalBytesRead) + ", ntransfers="+ transfers.size()+ ", ntries="+ ntries+ ", bytesRead="+ totalBytesRead);
      }
      final AsynchronousFileChannel channel=opener.getAsyncChannel();
      try {
        for (        AsyncTransfer transfer : transfers) {
          transfer.read(channel);
        }
        totalBytesRead=0;
        for (        AsyncTransfer transfer : transfers) {
          totalBytesRead+=transfer.complete();
        }
        return totalBytesRead;
      }
 catch (      InterruptedException ex) {
        throw new RuntimeException(ex);
      }
catch (      ExecutionException ex) {
        final Throwable cause=ex.getCause();
        if (InnerCause.isInnerCause(cause,ClosedByInterruptException.class)) {
          throw new IOException(ex);
        }
 else         if (InnerCause.isInnerCause(cause,AsynchronousCloseException.class)) {
          continue;
        }
 else         if (InnerCause.isInnerCause(cause,ClosedChannelException.class)) {
          continue;
        }
 else {
          throw new RuntimeException(ex);
        }
      }
    }
  }
  finally {
    for (    AsyncTransfer transfer : transfers) {
      transfer.cancel();
    }
  }
}

static public long readAllAsync ( final IAsyncOpener opener , final List < AsyncTransfer > transfers ) throws IOException { int ntries = 0 ; long totalBytesRead = 0 ; final long totalBytesExpected ; { long n = 0 ; for ( AsyncTransfer transfer : transfers ) { n += transfer . m_bytesToRead ; } totalBytesExpected = n ; } try { while ( true ) { ntries ++ ; if ( ntries == 100 ) { log . warn ( "reading on channel: remaining=" + ( totalBytesExpected - totalBytesRead ) + ", ntransfers=" + transfers . size ( ) + ", ntries=" + ntries + ", bytesRead=" + totalBytesRead ) ; } else if ( ntries == 1000 ) { log . error ( "reading on channel: remaining=" + ( totalBytesExpected - totalBytesRead ) + ", ntransfers=" + transfers . size ( ) + ", ntries=" + ntries + ", bytesRead=" + totalBytesRead ) ; } else if ( ntries > 10000 ) { throw new RuntimeException ( "reading on channel: remaining=" + ( totalBytesExpected - totalBytesRead ) + ", ntransfers=" + transfers . size ( ) + ", ntries=" + ntries + ", bytesRead=" + totalBytesRead ) ; } final AsynchronousFileChannel channel = opener . getAsyncChannel ( ) ; try { for ( AsyncTransfer transfer : transfers ) { transfer . read ( channel ) ; } totalBytesRead = 0 ; for ( AsyncTransfer transfer : transfers ) { totalBytesRead += transfer . complete ( ) ; } return totalBytesRead ; } catch ( InterruptedException ex ) { throw new RuntimeException ( ex ) ; } catch ( ExecutionException ex ) { final Throwable cause = ex . getCause ( ) ; if ( InnerCause . isInnerCause ( cause , ClosedByInterruptException . class ) ) { throw new IOException ( ex ) ; } else if ( InnerCause . isInnerCause ( cause , AsynchronousCloseException . class ) ) { continue ; } else if ( InnerCause . isInnerCause ( cause , ClosedChannelException . class ) ) { continue ; } else { throw new RuntimeException ( ex ) ; } } } } finally { for ( AsyncTransfer transfer : transfers ) { transfer . cancel ( ) ; } } }
readallasync will make repeated attempts to read data into the transfer buffers defined in the list of asynctransfer instances .
