Java Byte Array Print printBytesToString(byte[] bytes, String structName)

Here you can find the source of printBytesToString(byte[] bytes, String structName)

Description

print Bytes To String

License

Apache License

Declaration

public static void printBytesToString(byte[] bytes, String structName) 

Method Source Code

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

public class Main {

    public static void printBytesToString(byte[] bytes, String structName) {
        System.out.println("*************" + structName + "**************");

        StringBuilder stringBuilder = new StringBuilder();

        for (Byte byteStr : bytes) {
            String hexByteStr = Integer.toHexString(byteStr.intValue());

            if (hexByteStr.length() < 2) {
                stringBuilder.append("0");
            }// ww w .j  a va  2 s.  c o  m

            if (hexByteStr.length() > 2) {
                hexByteStr = hexByteStr.substring(hexByteStr.length() - 2, hexByteStr.length());
            }

            stringBuilder.append(hexByteStr);
            stringBuilder.append(" ");
        }

        System.out.println(stringBuilder.toString());
        System.out.println("************************************");
    }
}

Related

  1. printBytes(byte[] data)
  2. printBytes(String comment, byte[] input)
  3. printBytes(String x)
  4. printBytesHexEncoded(final byte[] byteArray)
  5. printByteSize(long bytes)
  6. printByteWithChar(byte[] byteArray)