Java ByteBuffer Print print(ByteBuffer byteBuffer)

Here you can find the source of print(ByteBuffer byteBuffer)

Description

print

License

Open Source License

Declaration

public static String print(ByteBuffer byteBuffer) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

public class Main {
    public static String print(String txt) {
        StringBuilder builder = new StringBuilder();
        builder.append("byte[] a= DatatypeConverter.parseHexBinary(\"");
        for (byte b : txt.getBytes()) {
            builder.append(getTwoDigitHex(b));
        }//from  ww  w  .j  av a2  s  .co m
        builder.append("\");");
        return builder.toString();
    }

    public static String print(ByteBuffer byteBuffer) {
        String text = new String(byteBuffer.array());
        return print(text);
    }

    private static String getTwoDigitHex(byte b) {
        String hex = String.format("%02X ", b).substring(0, 2);
        return hex;
    }
}

Related

  1. print(ByteBuffer bb)
  2. printBuffer(ByteBuffer buffer)
  3. printBuffer(ByteBuffer buffer)
  4. printBuffer(String msg, ByteBuffer buffer)
  5. printByteBuffer(ByteBuffer buf)