1 /** 2 * Copyright (c) 2008, Google Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.android.mail.common.base; 18 19 /** 20 * Static utility methods pertaining especially to byte arrays. Note that I/O-related functionality 21 * belongs in the {@code com.google.common.io} package. 22 * 23 * @author Chris Nokleberg 24 * @author Hiroshi Yamauchi 25 */ 26 public final class ByteArrays { 27 private ByteArrays() {} 28 29 private static final char[] HEX_DIGITS = "0123456789abcdef".toCharArray(); 30 31 /** 32 * Returns the byte array formatted as a lowercase hexadecimal string. The string will be 33 * {@code 2 * bytes.length} characters long. 34 */ 35 public static String toHexString(byte[] bytes) { 36 StringBuilder sb = new StringBuilder(2 * bytes.length); 37 for (byte b : bytes) { 38 sb.append(HEX_DIGITS[(b >> 4) & 0xf]).append(HEX_DIGITS[b & 0xf]); 39 } 40 return sb.toString(); 41 } 42 }