Java tutorial
//package com.java2s; import java.io.*; import java.util.*; import java.text.SimpleDateFormat; public class Main { public static void hexaDumpHangul(OutputStream outStream, byte[] data, int len, String desc) { //if (desc.compareToIgnoreCase("outflow")==0) return ; PrintWriter out = new PrintWriter(outStream, true); int index = 0; out.println("[[LEN=" + len + "]/[" + desc + "][" + getTime() + "]]"); for (int i = 0; i < len; i++) { index = (i + 1) % 16; out.print(byteToHexa(data[i]) + " "); if (index == 0) { out.println(" " + new String(data, (i + 1) - 16, 16)); } } if (index != 0) { for (int i = 0; i < 16 - index; i++) out.print(" " + " "); out.println(" " + new String(data, data.length - index, index)); } } public static String getTime() { Date currentDate = Calendar.getInstance(TimeZone.getTimeZone("JST"), Locale.getDefault()).getTime(); /** SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault()); **/ SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault()); return formatter.format(currentDate); } public static String byteToHexa(byte byteNum) { char[] hexa = new char[2]; byte highbit = (byte) ((byteNum >> 4) & (byte) 0x0f); byte lowbit = (byte) (byteNum & (byte) 0x0f); switch (highbit) { case 15: hexa[0] = 'f'; break; case 14: hexa[0] = 'e'; break; case 13: hexa[0] = 'd'; break; case 12: hexa[0] = 'c'; break; case 11: hexa[0] = 'b'; break; case 10: hexa[0] = 'a'; break; default: hexa[0] = (char) (highbit + (byte) 0x30); break; } switch (lowbit) { case 15: hexa[1] = 'f'; break; case 14: hexa[1] = 'e'; break; case 13: hexa[1] = 'd'; break; case 12: hexa[1] = 'c'; break; case 11: hexa[1] = 'b'; break; case 10: hexa[1] = 'a'; break; default: hexa[1] = (char) (lowbit + (byte) 0x30); break; } return new String(hexa); } }