]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/jmh/src/main/java/org/rocksdb/util/KVUtils.java
2 * Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
3 * This source code is licensed under both the GPLv2 (found in the
4 * COPYING file in the root directory) and Apache 2.0 License
5 * (found in the LICENSE.Apache file in the root directory).
7 package org
.rocksdb
.util
;
9 import static java
.nio
.charset
.StandardCharsets
.UTF_8
;
11 import java
.nio
.ByteBuffer
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 public final class KVUtils
{
18 * Get a byte array from a string.
20 * Assumes UTF-8 encoding
22 * @param string the string
26 public static byte[] ba(final String string
) {
27 return string
.getBytes(UTF_8
);
31 * Get a string from a byte array.
33 * Assumes UTF-8 encoding
35 * @param bytes the bytes
39 public static String
str(final byte[] bytes
) {
40 return new String(bytes
, UTF_8
);
44 * Get a list of keys where the keys are named key1..key1+N
45 * in the range of {@code from} to {@code to} i.e. keyFrom..keyTo.
47 * @param from the first key
48 * @param to the last key
50 * @return the array of keys
52 public static List
<byte[]> keys(final int from
, final int to
) {
53 final List
<byte[]> keys
= new ArrayList
<>(to
- from
);
54 for (int i
= from
; i
< to
; i
++) {
55 keys
.add(ba("key" + i
));
60 public static List
<ByteBuffer
> keys(
61 final List
<ByteBuffer
> keyBuffers
, final int from
, final int to
) {
62 final List
<ByteBuffer
> keys
= new ArrayList
<>(to
- from
);
63 for (int i
= from
; i
< to
; i
++) {
64 final ByteBuffer key
= keyBuffers
.get(i
);
66 key
.put(ba("key" + i
));