@ Override public void writeToOutput ( final ChannelWriterOutputView output ) throws IOException { int recordsLeft = this . numRecords ; int currentMemSeg = 0 ; while ( recordsLeft > 0 ) { final MemorySegment currentIndexSegment = this . sortIndex . get ( currentMemSeg ++ ) ; int offset = 0 ; // check whether we have a full or partially full segment if ( recordsLeft >= this . indexEntriesPerSegment ) { // full segment for ( ; offset <= this . lastIndexEntryOffset ; offset += this . indexEntrySize ) { final long pointer = currentIndexSegment . getLong ( offset ) ; this . recordBuffer . setReadPosition ( pointer ) ; this . serializer . copy ( this . recordBuffer , output ) ; } recordsLeft -= this . indexEntriesPerSegment ; } else { // partially filled segment for ( ; recordsLeft > 0 ; recordsLeft -- , offset += this . indexEntrySize ) { final long pointer = currentIndexSegment . getLong ( offset ) ; this . recordBuffer . setReadPosition ( pointer ) ; this . serializer . copy ( this . recordBuffer , output ) ; } } } }
Writes the records in this buffer in their logical order to the given output .