Skip to content

Commit

Permalink
Don't rely on DatatypeConverter, which is no longer default in 1.9.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuetschard committed Dec 14, 2017
1 parent 97cc8a7 commit 38cae5c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gapic/src/main/com/google/gapid/util/ProtoDebugTextFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,19 @@ private static String escapeText(final String input) {
}
}

public static String escapeBytes(final ByteString input) {
public static char[] escapeBytes(final ByteString input) {
return escapeBytes(input.toByteArray());
}

public static String escapeBytes(final byte[] input) {
return javax.xml.bind.DatatypeConverter.printHexBinary(input).toLowerCase();
private static final char[] HEX_CHARS = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
public static char[] escapeBytes(final byte[] input) {
char[] r = new char[input.length * 2];
for (int i = 0, j = 0; i < input.length; i++, j += 2) {
r[j + 0] = HEX_CHARS[(input[i] & 0xF0) >> 4];
r[j + 1] = HEX_CHARS[input[i] & 0xF];
}
return r;
}
}

0 comments on commit 38cae5c

Please sign in to comment.