BitcoinUtil { public static byte getVarIntSize(byte firstByteVarInt) { int unsignedByte=firstByteVarInt & 0xFF; if (unsignedByte==0xFD) { return 3; } if (unsignedByte==0xFE) { return 5; } if (unsignedByte==0xFF) { return 9; } return 1; } 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 getVarIntSizeByte() { byte[] originalVarInt = new byte[] {0x02}; byte varIntSize = BitcoinUtil.getVarIntSize(originalVarInt[0]); assertEquals( 1, varIntSize,"varInt {0x02} must be of size 1"); }
@Test public void getVarIntSizeWord() { byte[] originalVarInt = new byte[] {(byte)0xFD,0x01,0x00}; byte varIntSize = BitcoinUtil.getVarIntSize(originalVarInt[0]); assertEquals( 3, varIntSize,"varInt {0xFD,0x01,0x00} must be of size 3"); }
@Test public void getVarIntSizeDWord() { byte[] originalVarInt = new byte[] {(byte)0xFE,0x01,0x00,0x00,0x00}; byte varIntSize = BitcoinUtil.getVarIntSize(originalVarInt[0]); assertEquals( 5, varIntSize,"varInt {0xFE,0x01,0x00,0x00,0x00} must be of size 5"); }
@Test public void getVarIntSizeQWord() { byte[] originalVarInt = new byte[] {(byte)0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; byte varIntSize = BitcoinUtil.getVarIntSize(originalVarInt[0]); assertEquals( 9, varIntSize,"varInt {0xFF,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00} must be of size 9"); }