Code cleanup and formatting. Migrated to java 1.8.
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / data / HexConverter.java
1 /*
2  * Svjatoslav Commons - shared library of common functionality.
3  * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 3 of the GNU Lesser General Public License
7  * or later as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.commons.data;
11
12 public class HexConverter {
13
14     static final String hexCharacters = "0123456789ABCDEF";
15
16     public static String byteArrayToHex(final byte[] bytes) {
17
18         if (bytes == null)
19             return null;
20
21         final StringBuilder result = new StringBuilder(2 * bytes.length);
22
23         for (final byte b : bytes)
24             result.append(hexCharacters.charAt((b & 0xF0) >> 4)).append(
25                     hexCharacters.charAt((b & 0x0F)));
26
27         return result.toString();
28     }
29
30 }