BinaryType implements Binary { public static byte[] parseHex(String hex) { int length = hex.length(); if ((length % 2) != 0) { throw new IllegalArgumentException("Hex has odd length: " + length); } try { byte[] bytes = new byte[length / 2]; int charIndex = 0; for (int byteIndex = 0; byteIndex < bytes.length; byteIndex++) { byte high = parseHexChar(hex.charAt(charIndex++)); byte low = parseHexChar(hex.charAt(charIndex++)); bytes[byteIndex] = (byte) ((high << 4) + low); } return bytes; } catch (Exception e) { throw new IllegalArgumentException("Invalid hexadecimal value: " + hex, e); } } BinaryType(byte[] data);  BinaryType(String base64); @Override byte[] getData(); @Override void getData(byte[] buffer, int offset); @Override int getLength(); @Override String getHex(); @Override String getBase64(); @Override boolean isZeros(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); static byte[] parseHex(String hex); static String formatHex(byte[] data); static byte[] parseBase64(String base64); static String formatBase64(byte[] data); static byte[] toBytes(long value); static byte[] toBytes(int value); static long toLong(byte[] data); static long toInt(byte[] data);  }
@Test public void testParseHex() { BinaryType blob = Blob.ofHex(SAMPLE_BLOB_HEX); verifyBlob8ByteHexAndBase64(blob); assertThat(blob.isZeros()).isFalse(); }