Here you can find the source of appendHexStream(StringBuilder sb, byte[] bytes, String delimiter, boolean prefixEachValue, boolean upperCase)
public static void appendHexStream(StringBuilder sb, byte[] bytes, String delimiter, boolean prefixEachValue, boolean upperCase)
//package com.java2s; /*/*from w w w. j ava 2 s.com*/ * TeleStax, Open Source Cloud Communications * Copyright 2011-2013, Telestax Inc and individual contributors * by the @authors tag. * * This program is free software: you can redistribute it and/or modify * under the terms of the GNU Affero 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 Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> */ public class Main { /** Same as {@link #toHexStream(byte[], String, boolean, boolean)}, but appends to an existing StringBuilder. */ public static void appendHexStream(StringBuilder sb, byte[] bytes, String delimiter, boolean prefixEachValue, boolean upperCase) { sb.ensureCapacity(bytes.length * (prefixEachValue ? 4 : 2) + (bytes.length - 1) * (delimiter == null ? 0 : delimiter.length())); for (int i = 0; i < bytes.length; i++) { if (prefixEachValue) sb.append("0x"); char c1 = Character.forDigit((bytes[i] & 0xF0) >> 4, 16); char c2 = Character.forDigit((bytes[i] & 0x0F), 16); sb.append(upperCase ? Character.toUpperCase(c1) : c1); sb.append(upperCase ? Character.toUpperCase(c2) : c2); if (delimiter != null && i < bytes.length - 1) sb.append(delimiter); } } }