Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor updates to MemoryMappedFileBuffer #1700

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/main/java/htsjdk/samtools/MemoryMappedFileBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down