Here you can find the source of dumpBytes(byte bb[])
Parameter | Description |
---|---|
bb | the byte array |
public static String dumpBytes(byte bb[])
//package com.java2s; /* /* w w w.j ava 2s. c om*/ *FastExcel,(c) copyright 2009 yAma<guooscar@gmail.com>. *WEB: http://fastexcel.sourceforge.net * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library 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 Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. */ public class Main { /** * Dump byte array as hex string. * * @param bb * the byte array */ public static String dumpBytes(byte bb[]) { StringBuffer result = new StringBuffer(bb.length * 4); String ss; int c = 8;// 8 byte one line int lineCount = bb.length / c; int t = bb.length % c; if (t != 0) { lineCount++; } for (int i = 0; i < lineCount; i++) { result.append(i * c + "\t:"); int tt = c; if (t != 0 && i == lineCount - 1) { tt = t; } char cc[] = new char[tt]; for (int j = 0; j < tt; j++) { ss = "0" + Integer.toHexString(bb[i * c + j]); result.append(ss.substring(ss.length() - 2) + ","); cc[j] = (char) bb[i * c + j]; } for (int k = 0; k < c - tt; k++) { result.append("--,");// fill hole with '--' } result.append("\t:"); result.append(cc); result.append("\n"); } return result.toString(); } }