package org.rocksdb;
+import java.nio.ByteBuffer;
+
/**
* SstFileWriter is used to create sst files that can be added to the
* database later. All keys in files generated by SstFileWriter will have
*/
@Deprecated
public SstFileWriter(final EnvOptions envOptions, final Options options,
- final AbstractComparator<? extends AbstractSlice<?>> comparator) {
+ final AbstractComparator comparator) {
super(newSstFileWriter(
envOptions.nativeHandle_, options.nativeHandle_, comparator.nativeHandle_,
comparator.getComparatorType().getValue()));
put(nativeHandle_, key.getNativeHandle(), value.getNativeHandle());
}
+ /**
+ * Add a Put key with value to currently opened file.
+ *
+ * @param key the specified key to be inserted.
+ * @param value the value associated with the specified key.
+ *
+ * @throws RocksDBException thrown if error happens in underlying
+ * native library.
+ */
+ public void put(final ByteBuffer key, final ByteBuffer value) throws RocksDBException {
+ assert key.isDirect() && value.isDirect();
+ putDirect(nativeHandle_, key, key.position(), key.remaining(), value, value.position(),
+ value.remaining());
+ key.position(key.limit());
+ value.position(value.limit());
+ }
+
/**
* Add a Put key with value to currently opened file.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/
-public void put(final byte[] key, final byte[] value)
- throws RocksDBException {
- put(nativeHandle_, key, value);
-}
+ public void put(final byte[] key, final byte[] value) throws RocksDBException {
+ put(nativeHandle_, key, value);
+ }
/**
* Add a Merge key with value to currently opened file.
finish(nativeHandle_);
}
+ /**
+ * Return the current file size.
+ *
+ * @throws RocksDBException thrown if error happens in underlying
+ * native library.
+ */
+ public long fileSize() throws RocksDBException {
+ return fileSize(nativeHandle_);
+ }
+
private native static long newSstFileWriter(
final long envOptionsHandle, final long optionsHandle,
final long userComparatorHandle, final byte comparatorType);
private native void put(final long handle, final byte[] key,
final byte[] value) throws RocksDBException;
+ private native void putDirect(long handle, ByteBuffer key, int keyOffset, int keyLength,
+ ByteBuffer value, int valueOffset, int valueLength) throws RocksDBException;
+
+ private native long fileSize(long handle) throws RocksDBException;
+
private native void merge(final long handle, final long keyHandle,
final long valueHandle) throws RocksDBException;