From 3894a5599baf217f036ddfb9f4ac2ac0b4d7a2de Mon Sep 17 00:00:00 2001 From: Satoshi Kataoka Date: Fri, 16 Aug 2013 16:55:49 +0900 Subject: [PATCH] Consolidate hex string utils Change-Id: Id4f4a287e3a2790b22bff7ad4a4617bf2ee82884 --- .../com/android/inputmethod/latin/utils/StringUtils.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/java/src/com/android/inputmethod/latin/utils/StringUtils.java b/java/src/com/android/inputmethod/latin/utils/StringUtils.java index 20cc5d815..be4184093 100644 --- a/java/src/com/android/inputmethod/latin/utils/StringUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/StringUtils.java @@ -370,12 +370,19 @@ public final class StringUtils { return sb.toString(); } + /** + * Convert hex string to byte array. The string length must be an even number. + */ @UsedForTesting public static byte[] hexStringToByteArray(String hexString) { if (TextUtils.isEmpty(hexString)) { return null; } final int N = hexString.length(); + if (N % 2 != 0) { + throw new NumberFormatException("Input hex string length must be an even number." + + " Length = " + N); + } final byte[] bytes = new byte[N / 2]; for (int i = 0; i < N; i += 2) { bytes[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)