]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/jmh/src/main/java/org/rocksdb/util/KVUtils.java
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rocksdb / java / jmh / src / main / java / org / rocksdb / util / KVUtils.java
1 /**
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).
6 */
7 package org.rocksdb.util;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 import static java.nio.charset.StandardCharsets.UTF_8;
13
14 public final class KVUtils {
15
16 /**
17 * Get a byte array from a string.
18 *
19 * Assumes UTF-8 encoding
20 *
21 * @param string the string
22 *
23 * @return the bytes.
24 */
25 public static byte[] ba(final String string) {
26 return string.getBytes(UTF_8);
27 }
28
29 /**
30 * Get a string from a byte array.
31 *
32 * Assumes UTF-8 encoding
33 *
34 * @param bytes the bytes
35 *
36 * @return the string.
37 */
38 public static String str(final byte[] bytes) {
39 return new String(bytes, UTF_8);
40 }
41
42 /**
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.
45 *
46 * @param from the first key
47 * @param to the last key
48 *
49 * @return the array of keys
50 */
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));
55 }
56 return keys;
57 }
58 }