MCPcopy Create free account
hub / github.com/DeNA/PacketProxy / fromString

Method fromString

src/main/java/core/org/xbill/DNS/utils/base16.java:45–71  ·  view source on GitHub ↗

Convert a hex-encoded String to binary data @param str A String containing the encoded data @return An array containing the binary data, or null if the string is invalid

(String str)

Source from the content-addressed store, hash-verified

43 * @return An array containing the binary data, or null if the string is invalid
44 */
45public static byte []
46fromString(String str) {
47 ByteArrayOutputStream bs = new ByteArrayOutputStream();
48 byte [] raw = str.getBytes();
49 for (int i = 0; i < raw.length; i++) {
50 if (!Character.isWhitespace((char)raw[i]))
51 bs.write(raw[i]);
52 }
53 byte [] in = bs.toByteArray();
54 if (in.length % 2 != 0) {
55 return null;
56 }
57
58 bs.reset();
59 DataOutputStream ds = new DataOutputStream(bs);
60
61 for (int i = 0; i < in.length; i += 2) {
62 byte high = (byte) Base16.indexOf(Character.toUpperCase((char)in[i]));
63 byte low = (byte) Base16.indexOf(Character.toUpperCase((char)in[i+1]));
64 try {
65 ds.writeByte((high << 4) + low);
66 }
67 catch (IOException e) {
68 }
69 }
70 return bs.toByteArray();
71}
72
73}

Callers

nothing calls this directly

Calls 5

indexOfMethod · 0.80
getBytesMethod · 0.65
writeMethod · 0.65
toByteArrayMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected