import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
import org.eclipse.jdt.annotation.NonNull;
/**
private final MappedFileReader reader;
private final ByteBuffer buffer;
- MappedFileWriter(final JournalSegmentFile file, final FileChannel channel, final int maxEntrySize) {
- super(file, channel, maxEntrySize);
+ MappedFileWriter(final JournalSegmentFile file, final int maxEntrySize) {
+ super(file, maxEntrySize);
- mappedBuffer = mapBuffer(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
@Override
DiskFileWriter toDisk() {
close();
- return new DiskFileWriter(file, channel, maxEntrySize);
+ return new DiskFileWriter(file, maxEntrySize);
}
@Override