]>
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 java
.util
.ArrayList
;
10 import java
.util
.List
;
12 import static java
.nio
.charset
.StandardCharsets
.UTF_8
;
14 public final class KVUtils
{
17 * Get a byte array from a string.
19 * Assumes UTF-8 encoding
21 * @param string the string
25 public static byte[] ba(final String string
) {
26 return string
.getBytes(UTF_8
);
30 * Get a string from a byte array.
32 * Assumes UTF-8 encoding
34 * @param bytes the bytes
38 public static String
str(final byte[] bytes
) {
39 return new String(bytes
, UTF_8
);
43 * Get a list of keys where the keys are named key1..key1+N
44 * in the range of {@code from} to {@code to} i.e. keyFrom..keyTo.
46 * @param from the first key
47 * @param to the last key
49 * @return the array of keys
51 public static List
<byte[]> keys(final int from
, final int to
) {
52 final List
<byte[]> keys
= new ArrayList
<>(to
- from
);
53 for (int i
= from
; i
< to
; i
++) {
54 keys
.add(ba("key" + i
));