use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.
the class SeekableByteChannelPrefetcherTest method testCloseWhilePrefetching.
@Test
public void testCloseWhilePrefetching() throws Exception {
SeekableByteChannel chan = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 10 * 1024 * 1024);
// read just 1 byte, get the prefetching going
ByteBuffer one = ByteBuffer.allocate(1);
readFully(chan, one);
// closing must not throw an exception, even if the prefetching
// thread is active.
chan.close();
}
use of java.nio.channels.SeekableByteChannel in project gatk by broadinstitute.
the class SeekableByteChannelPrefetcherTest method testRead.
@Test
public void testRead() throws Exception {
SeekableByteChannel chan1 = Files.newByteChannel(Paths.get(input));
SeekableByteChannel chan2 = new SeekableByteChannelPrefetcher(Files.newByteChannel(Paths.get(input)), 1024);
testReading(chan1, chan2, 0);
testReading(chan1, chan2, 128);
testReading(chan1, chan2, 1024);
testReading(chan1, chan2, 1500);
testReading(chan1, chan2, 2048);
testReading(chan1, chan2, 3000);
testReading(chan1, chan2, 6000);
}
use of java.nio.channels.SeekableByteChannel in project jgnash by ccavanaugh.
the class FileMagic method isFile.
private static boolean isFile(final Path path, final byte[] header) {
boolean result = false;
if (Files.exists(path)) {
try (final SeekableByteChannel channel = Files.newByteChannel(path, EnumSet.of(READ))) {
if (channel.size() > 0) {
// must not be a zero length file
final ByteBuffer buff = ByteBuffer.allocate(header.length);
channel.read(buff);
result = Arrays.equals(buff.array(), header);
buff.clear();
}
} catch (final IOException ex) {
Logger.getLogger(FileMagic.class.getName()).log(Level.SEVERE, null, ex);
}
}
return result;
}
Aggregations