Here you can find the source of toHexaString(byte[] data)
public static String toHexaString(byte[] data)
//package com.java2s; /* //from w w w . ja va 2 s . co m * Copyright 2012 Devoteam http://www.devoteam.com * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * * This file is part of Multi-Protocol Test Suite (MTS). * * Multi-Protocol Test Suite (MTS) is free software: you can redistribute * it and/or modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 of the * License. * * Multi-Protocol Test Suite (MTS) 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Multi-Protocol Test Suite (MTS). * If not, see <http://www.gnu.org/licenses/>. * */ public class Main { public static String toHexaString(byte[] data) { return toHexaString(data, 0, -1); } public static String toHexaString(byte[] data, String sep) { return toHexaString(data, 0, -1, sep); } public static String toHexaString(byte[] data, int offset, int length) { return toHexaString(data, offset, length, "."); } public static String toHexaString(byte[] data, int offset, int length, String sep) { StringBuffer buffer = new StringBuffer(); if (length == -1) { length = data.length - offset; } for (int i = offset; i < offset + length; i++) { int value = (data[i] & 0xff) + 0x100; buffer.append(Integer.toString(value, 16).substring(1)); if (sep != null) { buffer.append(sep); } } String res = buffer.toString(); return res; } }