final GATKBAMIndex index = dataSource.getIndex(reader);
final GATKBAMIndexData indexData = index.readReferenceSequence(referenceSequence);
int currentBinInLowestLevel = GATKBAMIndex.getFirstBinInLevel(GATKBAMIndex.getNumIndexLevels()-1);
Iterator<GenomeLoc> locusIterator = intervals.iterator();
GenomeLoc currentLocus = locusIterator.next();
final long readerStartOffset = position();
int maxChunkCount = 0;
while(currentBinInLowestLevel < GATKBAMIndex.MAX_BINS && currentLocus != null) {
final Bin bin = new Bin(referenceSequence,currentBinInLowestLevel);
final int binStart = index.getFirstLocusInBin(bin);
final int binStop = index.getLastLocusInBin(bin);
// In required, pull bin iterator ahead to the point of the next GenomeLoc.
if(binStop < currentLocus.getStart()) {
currentBinInLowestLevel++;
continue;
}
// At this point, the bin stop is guaranteed to be >= the start of the locus.
// If the bins have gone past the current locus, update the current locus if at all possible.
if(binStart > currentLocus.getStop()) {
currentLocus = locusIterator.hasNext() ? locusIterator.next() : null;
continue;
}
// Code at this point knows that the current bin is neither before nor after the current locus,