Here you can find the source of asString(byte[] array)
Parameter | Description |
---|---|
array | array to convert |
public static String asString(byte[] array)
//package com.java2s; /*/*from ww w . j av a 2 s .co m*/ * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Sly Technologies, Inc. * * This file is part of jNetPcap. * * jNetPcap 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 3 of * the License, or (at your option) any later version. * * This program 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 program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Converts the given byte array to a string using a default separator * character. * * @param array * array to convert * @return the converted string */ public static String asString(byte[] array) { return asString(array, ':'); } /** * Convers the given byte array to a string using the supplied separator * character. * * @param array * array to convert * @param separator * separator character to use in between array elements * @return the converted string */ public static String asString(byte[] array, char separator) { return asString(array, separator, 16); // Default HEX } /** * Converts the given byte array to a string using the supplied separator * character and radix for conversion of the numerical component. * * @param array * array to convert * @param separator * separator character to use in between array elements * @param radix * numerical radix to use for numbers * @return the converted string */ public static String asString(byte[] array, char separator, int radix) { return asString(array, separator, radix, 0, array.length); } /** * Convers the given byte array to a string using the supplied separator * character. * * @param array * array to convert * @param separator * separator character to use in between array elements * @param radix * the radix * @param start * the start * @param len * the len * @return the converted string */ public static String asString(byte[] array, char separator, int radix, int start, int len) { final StringBuilder buf = new StringBuilder(); for (int i = start; i < (start + len); i++) { byte b = array[i]; if (buf.length() != 0) { buf.append(separator); } buf.append(Integer.toString((b < 0) ? b + 256 : b, radix).toUpperCase()); } return buf.toString(); } }