Index: oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileAccess.java =================================================================== --- oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileAccess.java (revision 1740460) +++ oak-segment/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/FileAccess.java (working copy) @@ -18,12 +18,16 @@ import static com.google.common.base.Preconditions.checkState; import static java.nio.channels.FileChannel.MapMode.READ_ONLY; +import static org.apache.jackrabbit.oak.commons.IOUtils.closeQuietly; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; +import java.nio.channels.FileChannel; +import org.apache.jackrabbit.oak.commons.IOUtils; + /** * A wrapper around either memory mapped files or random access files, to allow * reading from a file. @@ -45,10 +49,16 @@ */ static class Mapped extends FileAccess { - private final MappedByteBuffer buffer; + private final RandomAccessFile file; + private final FileChannel channel; + + private MappedByteBuffer buffer; + Mapped(RandomAccessFile file) throws IOException { - this.buffer = file.getChannel().map(READ_ONLY, 0, file.length()); + this.file = file; + this.channel = file.getChannel(); + this.buffer = channel.map(READ_ONLY, 0, file.length()); } @Override @@ -71,6 +81,9 @@ @Override public void close() { + closeQuietly(channel); + closeQuietly(file); + buffer = null; } }