BitcoinUtil { public static byte[] reverseByteArray(byte[] inputByteArray) { byte[] result=new byte[inputByteArray.length]; for (int i=inputByteArray.length-1;i>=0;i--) { result[result.length-1-i]=inputByteArray[i]; } return result; } private  BitcoinUtil(); static long convertSignedIntToUnsigned(int signedInt); static byte[] convertIntToByteArray(int intToConvert); static byte[] convertLongToByteArray(long longToConvert); static byte[] convertBigIntegerToByteArray(BigInteger bigIntegerToConvert,int exactArraySize); static byte[] convertVarIntByteBufferToByteArray(ByteBuffer byteBuffer); static long convertVarIntByteBufferToLong(ByteBuffer byteBuffer); static BigInteger getVarIntBI(byte[] varInt); static long getVarInt(byte[] varInt); static byte getVarIntSize(byte firstByteVarInt); static long getSize(byte[] byteSize); static byte[] reverseByteArray(byte[] inputByteArray); static byte[] convertHexStringToByteArray(String hexString); static String convertByteArrayToHexString(byte[] byteArray); static Date convertIntToDate(int dateInt); static boolean compareMagics(byte[] magic1,byte[] magic2); static byte[] getTransactionHash(BitcoinTransaction transaction); static byte[] getTransactionHashSegwit(BitcoinTransaction transaction);  }
@Test public void reverseByteArray() { byte[] originalByteArray = new byte[]{0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08}; byte[] resultByteArray = BitcoinUtil.reverseByteArray(originalByteArray); byte[] reverseByteArray = new byte[]{0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}; assertArrayEquals( reverseByteArray, resultByteArray,"{0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08} is equivalent to {0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01} in reverse order"); }