Here you can find the source of toHexDumpString(ByteBuffer data)
Parameter | Description |
---|---|
data | The source |
static public StringBuilder toHexDumpString(ByteBuffer data)
//package com.java2s; /**//from ww w.j av a 2 s .co m * Copyright (c) 2010-2015, openHAB.org and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html */ import java.nio.ByteBuffer; public class Main { /** * Generates a hex string representative of byte data * @param data The source * @return The hex string */ static public String toHexDumpString(byte data) { return String.format("%02X", (0xFF & data)); } /** * Generates a string hex dump from a byte array * @param data The source * @return The StringBuilder with hex dump */ static public StringBuilder toHexDumpString(byte[] data) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.length; i++) { byte c = data[i]; if (i > 0) sb.append(' '); sb.append(toHexDumpString(c)); } return sb; } /** * Generates a string hex dump from a ByteBuffer * @param data The source * @return The StringBuilder with hex dump */ static public StringBuilder toHexDumpString(ByteBuffer data) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < data.position(); i++) { byte c = data.get(i); if (i > 0) sb.append(' '); sb.append(toHexDumpString(c)); } return sb; } }