]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/rocksdb/java/src/test/java/org/rocksdb/util/TestUtil.java
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rocksdb / java / src / test / java / org / rocksdb / util / TestUtil.java
index 57347b084c31c2ad23a22d0cd0378f53a035df00..e4f490c8ea9f5b8f1005689bb92b177fc117c78e 100644 (file)
@@ -5,14 +5,14 @@
 
 package org.rocksdb.util;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+import java.nio.ByteBuffer;
+import java.util.Random;
 import org.rocksdb.CompactionPriority;
 import org.rocksdb.Options;
 import org.rocksdb.WALRecoveryMode;
 
-import java.util.Random;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-
 /**
  * General test utilities.
  */
@@ -58,4 +58,15 @@ public class TestUtil {
     random.nextBytes(str);
     return str;
   }
+
+  /**
+   * Copy a {@link ByteBuffer} into an array for shorthand ease of test coding
+   * @param byteBuffer the buffer to copy
+   * @return a {@link byte[]} containing the same bytes as the input
+   */
+  public static byte[] bufferBytes(final ByteBuffer byteBuffer) {
+    final byte[] result = new byte[byteBuffer.limit()];
+    byteBuffer.get(result);
+    return result;
+  }
 }