diff --git a/src/main/java/htsjdk/samtools/MemoryMappedFileBuffer.java b/src/main/java/htsjdk/samtools/MemoryMappedFileBuffer.java index 39d12adbf2..b26747df69 100644 --- a/src/main/java/htsjdk/samtools/MemoryMappedFileBuffer.java +++ b/src/main/java/htsjdk/samtools/MemoryMappedFileBuffer.java @@ -8,6 +8,7 @@ import java.nio.ByteOrder; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; +import java.nio.file.StandardOpenOption; /** * Traditional implementation of BAM index file access using memory mapped files. @@ -16,14 +17,9 @@ class MemoryMappedFileBuffer implements IndexFileBuffer { private MappedByteBuffer mFileBuffer; MemoryMappedFileBuffer(final File file) { - try { - // Open the file stream. - final FileInputStream fileStream = new FileInputStream(file); - final FileChannel fileChannel = fileStream.getChannel(); + try(final FileChannel fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.READ);) { mFileBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0L, fileChannel.size()); mFileBuffer.order(ByteOrder.LITTLE_ENDIAN); - fileChannel.close(); - fileStream.close(); } catch (final IOException exc) { throw new RuntimeIOException(exc.getMessage(), exc); } @@ -51,7 +47,7 @@ public void skipBytes(final int count) { @Override public void seek(final long position) { - mFileBuffer.position((int)position); + mFileBuffer.position(Math.toIntExact(position)); } @Override