String chr = "chr1";
int end = 300000000;
int start = end / 5;
int stopafter = 10;
int counter = 0;
BAMFileReader bamreader = new BAMFileReader(new File(bamfile));
CloseableIterator<PicardAlignment> bamiter = bamreader.query(chr, start, end, true);
while (bamiter.hasNext()) {
Alignment bamrecord = bamiter.next();
if (counter >= stopafter) {
break;
} else {
counter++;
}
}
bamreader.close();
boolean closeSucceeded = false;
try {
CloseableIterator<PicardAlignment> bamiter2 = bamreader.query(chr, start, end, true);
} catch (NullPointerException npe) {
closeSucceeded = true;
}
assertTrue(closeSucceeded);