BitcoinUtil { public static byte[] convertVarIntByteBufferToByteArray(ByteBuffer byteBuffer) { byte originalVarIntSize=byteBuffer.get(); byte varIntSize=getVarIntSize(originalVarIntSize); byte[] varInt=new byte[varIntSize]; varInt[0]=originalVarIntSize; byteBuffer.get(varInt,1,varIntSize-1); return varInt; } 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 convertVarIntByteBufferToByteArray() { byte[] originVarInt = new byte[]{0x01}; ByteBuffer testByteBuffer = ByteBuffer.allocate(1).put(originVarInt); testByteBuffer.flip(); byte[] varIntByteArray = BitcoinUtil.convertVarIntByteBufferToByteArray(testByteBuffer); assertArrayEquals( originVarInt,varIntByteArray,"0x01 in ByteBuffer must be equivalent to the varint represented in array {0x01}"); }