class HexUtils {

  public static byte[] decode(final String str) {
    final StringReader reader = new StringReader(str);
    final ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    int ch1 = 0;
    try {
      while (0 < (ch1 = reader.read())) {
        int ch2 = reader.read();
        assertTrue(0 <= ch2);
        byteOut.write(convert(ch1) << 4 | convert(ch2));
      }
      return byteOut.toByteArray();
    } catch (final IOException e) {
      throw new IllegalStateException(e);
    }
  }

}