class StringUtilities {

    public static String toHexString(byte[] arr, String byteSeparator)
    {
        final int len = Utilities.checkNull(arr, "arr").length * 2
                + (byteSeparator == null || arr.length <= 1 ? 0 : byteSeparator.length() * (arr.length - 1));
        final StringBuilder sb = new StringBuilder(len);
        if (byteSeparator == null || arr.length <= 1)
        {
            for (int index = 0; index < arr.length; ++index)
            {
                final byte b = arr[index];
                sb.append(HEX_CHARS[(b & 0xF0) >> 4]);
                sb.append(HEX_CHARS[b & 0xF]);
            }
        }
        else
        {
            for (int index = 0; index < arr.length - 1; ++index)
            {
                final byte b = arr[index];
                sb.append(HEX_CHARS[(b & 0xF0) >> 4]);
                sb.append(HEX_CHARS[b & 0xF]);
                sb.append(byteSeparator);
            }
            final byte b = arr[arr.length - 1];
            sb.append(HEX_CHARS[(b & 0xF0) >> 4]);
            sb.append(HEX_CHARS[b & 0xF]);
        }

        return sb.toString();
    }

    private  StringUtilities();

}