Skip to contentPackage: Hex
Hex
Coverage
1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Red Hat Inc and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Red Hat Inc - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.kura.simulator.util;
14:
15: import com.google.common.io.BaseEncoding;
16:
17: public final class Hex {
18:
19: private Hex() {
20: }
21:
22: /**
23: * Render a byte array as hex string
24: *
25: * @param payload
26: * the data to render
27: * @param maxLength
28: * the maximum number of byes to render
29: * @return the string
30: */
31: public static String toHex(final byte[] payload, final int maxLength) {
32:• return BaseEncoding.base16().encode(payload, 0, payload.length > maxLength ? maxLength : payload.length)
33: + (payload.length > maxLength ? "..." : "");
34: }
35: }