import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
import java.nio.file.Path;
import org.eclipse.jdt.annotation.NonNull;
return file.getChannel();
}
+ /**
+ * Map the contents of the file into memory.
+ *
+ * @return A {@link MappedByteBuffer}
+ * @throws IOException if an I/O error occurs
+ */
+ @NonNull MappedByteBuffer map() throws IOException {
+ return channel().map(MapMode.READ_WRITE, 0, maxSize());
+ }
+
void close() throws IOException {
file.close();
}
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
import org.eclipse.jdt.annotation.NonNull;
/**
MappedFileWriter(final JournalSegmentFile file, final int maxEntrySize) {
super(file, maxEntrySize);
- mappedBuffer = mapBuffer(file.channel(), file.maxSize());
- buffer = mappedBuffer.slice();
- reader = new MappedFileReader(file, mappedBuffer);
- }
-
- private static @NonNull MappedByteBuffer mapBuffer(final FileChannel channel, final int maxSegmentSize) {
try {
- return channel.map(FileChannel.MapMode.READ_WRITE, 0, maxSegmentSize);
+ mappedBuffer = file.map();
} catch (IOException e) {
throw new StorageException(e);
}
+ buffer = mappedBuffer.slice();
+ reader = new MappedFileReader(file, mappedBuffer);
}
@Override