Java ByteBuffer to Hex toHexStream(ByteBuffer data)

Here you can find the source of toHexStream(ByteBuffer data)

Description

Convert data from given ByteBuffer to hex

License

Open Source License

Parameter

Parameter Description
data a parameter

Return

hex

Declaration

public static String toHexStream(ByteBuffer data) 

Method Source Code

//package com.java2s;
/**/*from   w w w.  j  a  v a 2  s .c  o m*/
 * This file is part of Aion-Lightning <aion-lightning.org>.
 *
 *  Aion-Lightning is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Aion-Lightning is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details. *
 *  You should have received a copy of the GNU General Public License
 *  along with Aion-Lightning.
 *  If not, see <http://www.gnu.org/licenses/>.
 */

import java.nio.ByteBuffer;

public class Main {
    /**
     * Convert data from given ByteBuffer to hex
     *
     * @param data
     * @return hex
     */
    public static String toHexStream(ByteBuffer data) {
        StringBuilder result = new StringBuilder();
        int counter = 0;
        int b;
        while (data.hasRemaining()) {
            b = data.get() & 0xff;
            result.append(String.format("%02X ", b));

            counter++;
            if (counter % 16 == 0) {
                result.append("\n");
            }
        }
        return result.toString();
    }
}

Related

  1. toHex(ByteBuffer bb)
  2. toHex(ByteBuffer buf)
  3. toHex(ByteBuffer buffer)
  4. toHex(ByteBuffer data)
  5. toHexStr(final ByteBuffer data)
  6. toHexString(ByteBuffer bb)
  7. toHexString(ByteBuffer bb)
  8. toHexString(ByteBuffer bb, boolean withSpaces)
  9. toHexString(ByteBuffer buffer)