46 lines
1.2 KiB
Java
46 lines
1.2 KiB
Java
package org.warp.jcwdb;
|
|
|
|
import com.esotericsoftware.kryo.io.Input;
|
|
import com.esotericsoftware.kryo.io.Output;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.channels.Channels;
|
|
import java.nio.channels.SeekableByteChannel;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.StandardOpenOption;
|
|
|
|
public class FileIndexManager implements IndexManager {
|
|
private final SeekableByteChannel dataFileChannel, metadataFileChannel;
|
|
private final FileAllocator fileAllocator;
|
|
|
|
public FileIndexManager(Path dataFile, Path metadataFile) throws IOException {
|
|
dataFileChannel = Files.newByteChannel(dataFile, StandardOpenOption.CREATE);
|
|
metadataFileChannel = Files.newByteChannel(metadataFile, StandardOpenOption.CREATE);
|
|
fileAllocator = new FileAllocator(dataFileChannel);
|
|
}
|
|
|
|
@Override
|
|
public <T> T get(long l, int type, DBReader<T> r) {
|
|
Input i = new Input(Channels.newInputStream(dataFileChannel));
|
|
T result = r.read(i);
|
|
i.close();
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
public void set(long index, int type, DBWriter w) throws IOException {
|
|
fileAllocator.write(index, type, w);
|
|
}
|
|
|
|
@Override
|
|
public void delete(long index) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public boolean has(long index) {
|
|
return false;
|
|
}
|
|
}
|