Strings { public static byte[] hexStringToByteArray(String hexString) { if (hexString == null) { return null; } int length = hexString.length(); byte[] bytes = new byte[length / 2]; for (int i = 0; i < length; i += 2) { bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4) + Character.digit(hexString.charAt(i + 1), 16)); } return bytes; } private  Strings(); static Set<T> setOf(String input, Function<String, String[]> splitter, Function<String, T> factory); static List<T> listOf(String input, Function<String, String[]> splitter, Function<String, T> factory); static Set<T> setOf(String input, char delimiter, Function<String, T> factory); static Set<T> setOf(String input, Function<String, T> factory); static Set<Pattern> setOfRegex(String input, int regexFlags); static Set<Pattern> setOfRegex(String input); static List<Pattern> listOfRegex(String input, int regexFlags); static List<String> splitLines(final String content); static int compareTo(CharSequence str1, CharSequence str2); static boolean equalsIgnoreCase(String str1, String str2); static String join(CharSequence delimiter, int[] values); static String join(CharSequence delimiter, Iterable<T> values); static String join(CharSequence delimiter, Iterable<T> values, Function<T, String> conversion); static String trim(String str); static String trim(String str, CharacterPredicate predicate); static String createString(final char charToRepeat,
                                      int numberOfRepeats); static String pad(String original,
                             int length,
                             char padChar); static String setLength(String original,
                                   int length,
                                   char padChar); static String justify(Justify justify,
                                 String str,
                                 final int width,
                                 char padWithChar); static String justifyRight(String str,
                                      final int width,
                                      char padWithChar); static String justifyLeft(String str,
                                     final int width,
                                     char padWithChar); static String justifyCenter(String str,
                                       final int width,
                                       char padWithChar); static String getStackTrace(Throwable throwable); static Number asNumber(String value); static Number asNumber(String value, Supplier<Number> defaultValueProvider); static int asInt(String value, int defaultValue); static long asLong(String value, long defaultValue); static double asDouble(String value, double defaultValue); static boolean asBoolean(String value, boolean defaultValue); static Duration asDuration(String timeString); static String duration(long durationInMillis); static Function<String, String> replaceVariablesWith(Function<String, String> replacementsByVariableName); static String replaceVariables(String value, Function<String, String> replacementsByVariableName); static boolean isUuid(String str); static boolean isNullOrEmpty(String str); static boolean isNumeric(String str); static String unquoteIdentifierPart(String identifierPart); static byte[] hexStringToByteArray(String hexString); static boolean startsWithIgnoreCase(String str, String prefix); static String getBegin(String str, int length);  }
@Test public void hexStringToByteArrayShouldReturnCorrectByteArray() { assertThat(Strings.hexStringToByteArray(null)).isNull(); assertThat(Strings.hexStringToByteArray("00")).isEqualTo(new byte[]{ 0 }); assertThat(Strings.hexStringToByteArray("010203")).isEqualTo(new byte[]{ 1, 2, 3 }); assertThat(Strings.hexStringToByteArray("CAFEBABE")).isEqualTo(new byte[]{ -54, -2, -70, -66 }); }