@Override public int read( ByteBuffer dst ) { /* * Fill up dst with what comes from the channel, until dst is full. * readAsMuchAsPossible() is constantly called reading essentially * one chunk at a time until either it runs out of stuff coming * from the channel or the actual target buffer is filled. */ int bytesWanted = dst.limit(); int bytesRead = 0; while ( bytesWanted > 0 ) { int bytesReadThisTime = readAsMuchAsPossible( dst, bytesWanted ); if ( bytesReadThisTime == 0 ) { break; } bytesRead += bytesReadThisTime; bytesWanted -= bytesReadThisTime; } return bytesRead == 0 && !moreBlocks ? -1 : bytesRead; }