use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.
the class SeekableByteChannelPrefetcherTest method testPartialBuffers.
@Test
public void testPartialBuffers() throws Exception {
SeekableByteChannel chan1 = Files.newByteChannel(Paths.get(input));
SeekableByteChannel chan2 = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 1024);
// get a partial buffer
testSeeking(chan1, chan2, (int) chan1.size() - 127);
// make sure normal reads can use the full buffer
for (int i = 0; i < 2; i++) {
testSeeking(chan1, chan2, i * 1024);
}
// get a partial buffer, replacing one of the full ones
testSeeking(chan1, chan2, (int) chan1.size() - 127);
// make sure the buffers are still OK
for (int i = 0; i < 2; i++) {
testSeeking(chan1, chan2, i * 1024);
}
}
use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.
the class SeekableByteChannelPrefetcherTest method testDoubleWrapping.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testDoubleWrapping() throws Exception {
SeekableByteChannel chan1 = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 1024);
new SeekableByteChannelPrefetcher(chan1, 1024);
}
use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.
the class SeekableByteChannelPrefetcherTest method testEOF.
@Test
public void testEOF() throws Exception {
SeekableByteChannel chan1 = Files.newByteChannel(Paths.get(input));
SeekableByteChannel chan2 = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 1024);
// read the final 128 bytes, exactly.
testSeeking(chan1, chan2, (int) chan1.size() - 128);
// read truncated because we're asking for beyond EOF
testSeeking(chan1, chan2, (int) chan1.size() - 64);
// read starting past EOF
testSeeking(chan1, chan2, (int) chan1.size() + 128);
// read more than a whole block past EOF
testSeeking(chan1, chan2, (int) chan1.size() + 1024 * 2);
}
use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.
the class SeekableByteChannelPrefetcherTest method testSeek.
@Test
public void testSeek() throws Exception {
SeekableByteChannel chan1 = Files.newByteChannel(Paths.get(input));
SeekableByteChannel chan2 = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 1024);
testSeeking(chan1, chan2, 1024);
testSeeking(chan1, chan2, 1500);
testSeeking(chan1, chan2, 128);
testSeeking(chan1, chan2, 256);
testSeeking(chan1, chan2, 128);
// yes, testReading - let's make sure that reading more than one block still works
// even after a seek.
testReading(chan1, chan2, 1500);
testSeeking(chan1, chan2, 2048);
testSeeking(chan1, chan2, 0);
testSeeking(chan1, chan2, 3000);
testSeeking(chan1, chan2, 6000);
testSeeking(chan1, chan2, (int) chan1.size() - 127);
testSeeking(chan1, chan2, (int) chan1.size() - 128);
testSeeking(chan1, chan2, (int) chan1.size() - 129);
}
use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.
the class GenomicsDBImport method getReaderFromVCFUri.
/**
* Creates a feature reader object from a given VCF URI (can also be
* a local file path) and returns it
* @param variantPath URI or file path
* @return Feature reader
*/
private AbstractFeatureReader<VariantContext, LineIterator> getReaderFromVCFUri(final String variantPath) {
final String variantURI = IOUtils.getPath(variantPath).toAbsolutePath().toUri().toString();
final Function<SeekableByteChannel, SeekableByteChannel> cloudWrapper = (cloudPrefetchBuffer > 0 ? is -> SeekableByteChannelPrefetcher.addPrefetcher(cloudPrefetchBuffer, is) : Function.identity());
final Function<SeekableByteChannel, SeekableByteChannel> cloudIndexWrapper = (cloudIndexPrefetchBuffer > 0 ? is -> SeekableByteChannelPrefetcher.addPrefetcher(cloudIndexPrefetchBuffer, is) : Function.identity());
return AbstractFeatureReader.getFeatureReader(variantURI, null, new VCFCodec(), true, cloudWrapper, cloudIndexWrapper);
}
Aggregations