Skip to content

Commit 4ea1aba

Browse files
committed
Merge pull request #522 from tomwhite/expose-end-of-block-for-bgzf
Add a method to expose whether the stream is positioned at the end of a BGZF block.
2 parents 8dd4559 + e595f61 commit 4ea1aba

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/java/htsjdk/samtools/util/BlockCompressedInputStream.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ public int available()
132132
return mCurrentBlock.length - mCurrentOffset;
133133
}
134134

135+
/**
136+
* @return <code>true</code> if the stream is at the end of a BGZF block,
137+
* <code>false</code> otherwise.
138+
*/
139+
public boolean endOfBlock() {
140+
return (mCurrentBlock != null && mCurrentOffset == mCurrentBlock.length);
141+
}
142+
135143
/**
136144
* Closes the underlying InputStream or RandomAccessFile
137145
*/

src/tests/java/htsjdk/samtools/util/BlockCompressedOutputStreamTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ public void testBasic() throws Exception {
6363
for(int i = 0; (line = reader.readLine()) != null; ++i) {
6464
Assert.assertEquals(line + "\n", linesWritten.get(i));
6565
}
66+
67+
final BlockCompressedInputStream bcis2 = new BlockCompressedInputStream(f);
68+
int available = bcis2.available();
69+
Assert.assertFalse(bcis2.endOfBlock(), "Should not be at end of block");
70+
Assert.assertTrue(available > 0);
71+
byte[] buffer = new byte[available];
72+
Assert.assertEquals(bcis2.read(buffer), available, "Should read to end of block");
73+
Assert.assertTrue(bcis2.endOfBlock(), "Should be at end of block");
6674
}
6775

6876
@Test

0 commit comments

Comments
 (0)