View Javadoc
1   /*
2    * Created on Jun 6, 2005
3    *
4    * StringUtils provides a set of utility functions for dealing with Strings
5    */
6   package net.sf.mindoro.commons.util;
7   
8   /***
9    * StringUtils provides a set of utility functions for dealing with Strings
10   * 
11   * @author aisrael
12   */
13  public final class StringUtils {
14  
15      /***
16       * Instances of StringUtils should NOT be constructed in regular
17       * programming.
18       */
19      private StringUtils() {
20          // noop
21      }
22  
23      private static final char[] HEXTABLE = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
24              'a', 'b', 'c', 'd', 'e', 'f' };
25  
26      /***
27       * @param bytes
28       *            byte[]
29       * @return String
30       */
31      public static String toHex(final byte[] bytes) {
32          final StringBuffer sb = new StringBuffer(bytes.length * 2);
33          for (int i = 0; i < bytes.length; ++i) {
34              sb.append(HEXTABLE[(bytes[i] & 0xF0) >> 4]).append(HEXTABLE[bytes[i] & 0x0F]);
35          }
36          return sb.toString();
37      }
38  
39  }