Tools { public static byte[] hexStringToByteArray (String s) { s = s.replaceAll("[^a-zA-Z0-9]", "").toLowerCase(); int len = s.length(); if (len % 2 != 0) { throw new IllegalArgumentException("Uneven hexadecimal string"); } byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) + Character.digit(s.charAt(i + 1), 16)); } return data; }  static int getRandom(int min, int max); static String getMethodName(final int depth); static Transaction applyBIP69(Transaction transaction); static List<TransactionSignature> getChannelSignatures(Channel channel, Transaction transaction); static String InputStreamToString(InputStream in); static boolean arrayListContainsByteArray(ArrayList<byte[]> arrayList, byte[] bytes); static int boolToInt(boolean bool); static T getRandomItemFromList(List<T> list); static List<T> getRandomSubList(List<T> input, int subsetSize); static String byteToString(byte[] array); static String byteToString58(byte[] array); static String bytesToHex(byte[] bytes); static boolean checkSignature(Transaction transaction, int index, TransactionOutput outputToSpend, ECKey key, byte[] signature); static boolean checkSignature(Transaction transaction, int index, Script outputToSpend, ECKey key, TransactionSignature signature); static boolean checkTransactionFees(int size, Transaction transaction, TransactionOutput output); static boolean checkTransactionLockTime(Transaction transaction, int locktime); static int currentTime(); static int currentTimeFlooredToCurrentDay(); static long getCoinValueFromOutput(List<TransactionOutput> output); static Script getDummyScript(); static String getFourCharacterHash(String s); static Message getMessage(String data); static Script getMultisigInputScript(ECDSASignature client, ECDSASignature server); static byte[] getRandomByte(int amount); static List<byte[]> byteBufferListToByteArrayList(List<ByteBuffer> byteBufferList); static byte[] copyRandomByteInByteArray(byte[] dest, int offset, int length); static TransactionSignature getSignature(Transaction transactionToSign, int index, TransactionOutput outputToSpend, ECKey key); static TransactionSignature getSignature(Transaction transactionToSign, int index, byte[] outputToSpend, ECKey key); static long getTransactionFees(int size); static long getTransactionFees(int size, float feePerByte); static long getTransactionFees(int inputs, int outputs); static long getTransactionFees(int inputs, int outputs, float feePerByte); static boolean checkIfExistingInOutPutsAreEqual(Transaction o, Transaction n); static byte[] hashSecret(byte[] secret); static String hashSecretToString(byte[] secret); static byte[] hashSha(byte[] secret); static byte[] hashSha(byte[] secret, int rounds); static byte[] hexStringToByteArray(String s); static boolean intToBool(int i); static Transaction setTransactionLockTime(Transaction transaction, int locktime); static String stacktraceToString(Exception e); static byte[] stringToByte(String string); static byte[] stringToByte58(String string);  }
@Test public void hexStringToByteArray () { assertArrayEquals(Tools.hexStringToByteArray("010a"), new byte[]{(byte) 1, (byte) 10}); assertArrayEquals(Tools.hexStringToByteArray("0001"), new byte[]{(byte) 0, (byte) 1}); assertArrayEquals(Tools.hexStringToByteArray("ac de"), new byte[]{(byte) 0xac, (byte) 0xde}); boolean hasThrown = false; try { Tools.hexStringToByteArray("a"); } catch (IllegalArgumentException e) { hasThrown = true; } assertTrue(hasThrown); }