private final void sendChunkTo(ByteBuffer in,SocketChannel sc,ByteBuffer out) throws IOException {
  int bytesSent=in.remaining();
  if (in.isDirect()) {
    flushBuffer(sc,out);
    while (in.remaining() > 0) {
      sc.write(in);
    }
  }
 else {
    int OUT_MAX=out.remaining();
    if (bytesSent <= OUT_MAX) {
      out.put(in);
    }
 else {
      final byte[] bytes=in.array();
      int off=in.arrayOffset() + in.position();
      int len=bytesSent;
      while (len > 0) {
        int bytesThisTime=len;
        if (bytesThisTime > OUT_MAX) {
          bytesThisTime=OUT_MAX;
        }
        out.put(bytes,off,bytesThisTime);
        off+=bytesThisTime;
        len-=bytesThisTime;
        flushBuffer(sc,out);
        OUT_MAX=out.remaining();
      }
      in.position(in.limit());
    }
  }
  this.size-=bytesSent;
}

private final void sendChunkTo ( ByteBuffer in , SocketChannel sc , ByteBuffer out ) throws IOException { int bytesSent = in . remaining ( ) ; if ( in . isDirect ( ) ) { flushBuffer ( sc , out ) ; while ( in . remaining ( ) > 0 ) { sc . write ( in ) ; } } else { int OUT_MAX = out . remaining ( ) ; if ( bytesSent <= OUT_MAX ) { out . put ( in ) ; } else { final byte [ ] bytes = in . array ( ) ; int off = in . arrayOffset ( ) + in . position ( ) ; int len = bytesSent ; while ( len > 0 ) { int bytesThisTime = len ; if ( bytesThisTime > OUT_MAX ) { bytesThisTime = OUT_MAX ; } out . put ( bytes , off , bytesThisTime ) ; off += bytesThisTime ; len -= bytesThisTime ; flushBuffer ( sc , out ) ; OUT_MAX = out . remaining ( ) ; } in . position ( in . limit ( ) ) ; } } this . size -= bytesSent ; }
sends the data from " in " by writing it to " sc " through " out " ( out is used to chunk to data and is probably a direct memory buffer ) .
