Java ByteBuffer to Hex toHex(ByteBuffer bb)

Here you can find the source of toHex(ByteBuffer bb)

Description

to Hex

License

LGPL

Declaration

public static String toHex(ByteBuffer bb) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.nio.ByteBuffer;

public class Main {
    public static String toHex(ByteBuffer bb) {
        StringBuilder sb = new StringBuilder("[ ");
        while (bb.hasRemaining()) {
            sb.append(String.format("%02X ", bb.get()));
        }// w w w .  ja  v  a2 s .  c o  m
        sb.append("]");
        return sb.toString();
    }

    public static String toString(ByteBuffer bb) {
        StringBuilder sb = new StringBuilder();
        while (bb.hasRemaining()) {
            sb.append((char) bb.get());
        }
        return sb.toString();
    }
}

Related

  1. byteBufferToHex(ByteBuffer buffer)
  2. bytesToHex(ByteBuffer bytes)
  3. bytesToHex(ByteBuffer bytes)
  4. bytesToHexString(ByteBuffer b)
  5. toHex(ByteBuffer bb)
  6. toHex(ByteBuffer buf)
  7. toHex(ByteBuffer buffer)
  8. toHex(ByteBuffer data)
  9. toHexStr(final ByteBuffer data)