]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/util/ByteUtil.java
1 // Copyright (c) Meta Platforms, Inc. and affiliates.
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
.nio
.ByteBuffer
;
11 import static java
.nio
.charset
.StandardCharsets
.UTF_8
;
13 public class ByteUtil
{
16 * Convert a String to a UTF-8 byte array.
18 * @param str the string
20 * @return the byte array.
22 public static byte[] bytes(final String str
) {
23 return str
.getBytes(UTF_8
);
27 * Compares the first {@code count} bytes of two areas of memory. Returns
28 * zero if they are the same, a value less than zero if {@code x} is
29 * lexically less than {@code y}, or a value greater than zero if {@code x}
30 * is lexically greater than {@code y}. Note that lexical order is determined
31 * as if comparing unsigned char arrays.
33 * Similar to <a href="https://github.com/gcc-mirror/gcc/blob/master/libiberty/memcmp.c">memcmp.c</a>.
35 * @param x the first value to compare with
36 * @param y the second value to compare against
37 * @param count the number of bytes to compare
39 * @return the result of the comparison
41 public static int memcmp(final ByteBuffer x
, final ByteBuffer y
,
43 for (int idx
= 0; idx
< count
; idx
++) {
44 final int aa
= x
.get(idx
) & 0xff;
45 final int bb
= y
.get(idx
) & 0xff;