11package net .sharksystem .asap .engine ;
22
3+ import net .sharksystem .SharkNotSupportedException ;
34import net .sharksystem .asap .ASAPException ;
45import net .sharksystem .asap .ASAPMessageCompare ;
56import net .sharksystem .asap .ASAPMessages ;
67import net .sharksystem .asap .utils .PeerIDHelper ;
78
9+ import javax .xml .transform .Source ;
810import java .io .IOException ;
911import java .util .ArrayList ;
1012import java .util .Iterator ;
@@ -360,13 +362,12 @@ private List<SourceIndex> getIndexList(boolean chronologically) {
360362 return chronologically ? oldFirstPositionList : newFirstPositionList ;
361363 }
362364
363- @ Override
364- public byte [] getMessage (int position , boolean chronologically ) throws ASAPException , IOException {
365+ private SourceIndex getSourceIndex (int position , boolean chronologically ) throws ASAPException , IOException {
365366 if (position >= this .size )
366367 throw new ASAPException ("position index must not exceed total number of messages: "
367- + position + " >= " + this .size );
368+ + position + " >= " + this .size );
368369
369- SourceIndex sourceIndex = null ;
370+ SourceIndex sourceIndex ;
370371 List <SourceIndex > usedList = this .getIndexList (chronologically );
371372
372373 sourceIndex = this .getSourceIndex (position , usedList );
@@ -380,7 +381,19 @@ public byte[] getMessage(int position, boolean chronologically) throws ASAPExcep
380381 throw new ASAPException ("no message at position: " + position );
381382 }
382383
384+ return sourceIndex ;
385+ }
386+
387+ @ Override
388+ public byte [] getMessage (int position , boolean chronologically ) throws ASAPException , IOException {
389+ SourceIndex sourceIndex = this .getSourceIndex (position , chronologically );
383390 return this .messageSources [sourceIndex .sourceIndex ].getMessage (
384391 sourceIndex .positionInSource , chronologically );
385392 }
393+
394+ @ Override
395+ public ASAPInternalChunk getChunk (int position , boolean chronologically ) throws IOException , ASAPException {
396+ SourceIndex sourceIndex = this .getSourceIndex (position , chronologically );
397+ return this .messageSources [sourceIndex .positionInSource ].getChunk (sourceIndex .positionInSource , chronologically );
398+ }
386399}
0 commit comments