]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/java/src/main/java/org/rocksdb/RocksIterator.java
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / RocksIterator.java
index 12c06f04e565b0e5065a8f956d14e4a51301a399..94611cd7a4753487f8be310b83373f21d1e0d860 100644 (file)
@@ -5,6 +5,8 @@
 
 package org.rocksdb;
 
+import java.nio.ByteBuffer;
+
 /**
  * <p>An iterator that yields a sequence of key/value pairs from a source.
  * Multiple implementations are provided by this library.
@@ -37,6 +39,28 @@ public class RocksIterator extends AbstractRocksIterator<RocksDB> {
     return key0(nativeHandle_);
   }
 
+  /**
+   * <p>Return the key for the current entry.  The underlying storage for
+   * the returned slice is valid only until the next modification of
+   * the iterator.</p>
+   *
+   * <p>REQUIRES: {@link #isValid()}</p>
+   *
+   * @param key the out-value to receive the retrieved key.
+   *     It is using position and limit. Limit is set according to key size.
+   *     Supports direct buffer only.
+   * @return The size of the actual key. If the return key is greater than the
+   *     length of {@code key}, then it indicates that the size of the
+   *     input buffer {@code key} is insufficient and partial result will
+   *     be returned.
+   */
+  public int key(ByteBuffer key) {
+    assert (isOwningHandle() && key.isDirect());
+    int result = keyDirect0(nativeHandle_, key, key.position(), key.remaining());
+    key.limit(Math.min(key.position() + result, key.limit()));
+    return result;
+  }
+
   /**
    * <p>Return the value for the current entry.  The underlying storage for
    * the returned slice is valid only until the next modification of
@@ -50,6 +74,28 @@ public class RocksIterator extends AbstractRocksIterator<RocksDB> {
     return value0(nativeHandle_);
   }
 
+  /**
+   * <p>Return the value for the current entry.  The underlying storage for
+   * the returned slice is valid only until the next modification of
+   * the iterator.</p>
+   *
+   * <p>REQUIRES: {@link #isValid()}</p>
+   *
+   * @param value the out-value to receive the retrieved value.
+   *     It is using position and limit. Limit is set according to value size.
+   *     Supports direct buffer only.
+   * @return The size of the actual value. If the return value is greater than the
+   *     length of {@code value}, then it indicates that the size of the
+   *     input buffer {@code value} is insufficient and partial result will
+   *     be returned.
+   */
+  public int value(ByteBuffer value) {
+    assert (isOwningHandle() && value.isDirect());
+    int result = valueDirect0(nativeHandle_, value, value.position(), value.remaining());
+    value.limit(Math.min(value.position() + result, value.limit()));
+    return result;
+  }
+
   @Override protected final native void disposeInternal(final long handle);
   @Override final native boolean isValid0(long handle);
   @Override final native void seekToFirst0(long handle);
@@ -58,8 +104,15 @@ public class RocksIterator extends AbstractRocksIterator<RocksDB> {
   @Override final native void prev0(long handle);
   @Override final native void seek0(long handle, byte[] target, int targetLen);
   @Override final native void seekForPrev0(long handle, byte[] target, int targetLen);
+  @Override
+  final native void seekDirect0(long handle, ByteBuffer target, int targetOffset, int targetLen);
+  @Override
+  final native void seekForPrevDirect0(
+      long handle, ByteBuffer target, int targetOffset, int targetLen);
   @Override final native void status0(long handle) throws RocksDBException;
 
   private native byte[] key0(long handle);
   private native byte[] value0(long handle);
+  private native int keyDirect0(long handle, ByteBuffer buffer, int bufferOffset, int bufferLen);
+  private native int valueDirect0(long handle, ByteBuffer buffer, int bufferOffset, int bufferLen);
 }