@Test public void testReverseDwordBytes() { assertArrayEquals(new byte[]{1, 2, 3, 4, 5, 6, 7, 8}, Utils.reverseDwordBytes(new byte[]{4, 3, 2, 1, 8, 7, 6, 5}, -1)); assertArrayEquals(new byte[]{1, 2, 3, 4}, Utils.reverseDwordBytes(new byte[]{4, 3, 2, 1, 8, 7, 6, 5}, 4)); assertArrayEquals(new byte[0], Utils.reverseDwordBytes(new byte[]{4, 3, 2, 1, 8, 7, 6, 5}, 0)); assertArrayEquals(new byte[0], Utils.reverseDwordBytes(new byte[0], 0)); }
public static byte[] reverseDwordBytes(byte[] bytes, int trimLength) { checkArgument(bytes.length % 4 == 0); checkArgument(trimLength < 0 || trimLength % 4 == 0); byte[] rev = new byte[trimLength >= 0 && bytes.length > trimLength ? trimLength : bytes.length]; for (int i = 0; i < rev.length; i += 4) { System.arraycopy(bytes, i, rev, i , 4); for (int j = 0; j < 4; j++) { rev[i + j] = bytes[i + 3 - j]; } } return rev; }
Utils { public static byte[] reverseDwordBytes(byte[] bytes, int trimLength) { checkArgument(bytes.length % 4 == 0); checkArgument(trimLength < 0 || trimLength % 4 == 0); byte[] rev = new byte[trimLength >= 0 && bytes.length > trimLength ? trimLength : bytes.length]; for (int i = 0; i < rev.length; i += 4) { System.arraycopy(bytes, i, rev, i , 4); for (int j = 0; j < 4; j++) { rev[i + j] = bytes[i + 3 - j]; } } return rev; } }
Utils { public static byte[] reverseDwordBytes(byte[] bytes, int trimLength) { checkArgument(bytes.length % 4 == 0); checkArgument(trimLength < 0 || trimLength % 4 == 0); byte[] rev = new byte[trimLength >= 0 && bytes.length > trimLength ? trimLength : bytes.length]; for (int i = 0; i < rev.length; i += 4) { System.arraycopy(bytes, i, rev, i , 4); for (int j = 0; j < 4; j++) { rev[i + j] = bytes[i + 3 - j]; } } return rev; }  }
Utils { public static byte[] reverseDwordBytes(byte[] bytes, int trimLength) { checkArgument(bytes.length % 4 == 0); checkArgument(trimLength < 0 || trimLength % 4 == 0); byte[] rev = new byte[trimLength >= 0 && bytes.length > trimLength ? trimLength : bytes.length]; for (int i = 0; i < rev.length; i += 4) { System.arraycopy(bytes, i, rev, i , 4); for (int j = 0; j < 4; j++) { rev[i + j] = bytes[i + 3 - j]; } } return rev; }  static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static void uint32ToByteArrayBE(long val, byte[] out, int offset); static void uint32ToByteArrayLE(long val, byte[] out, int offset); static void uint64ToByteArrayLE(long val, byte[] out, int offset); static void uint32ToByteStreamLE(long val, OutputStream stream); static void int64ToByteStreamLE(long val, OutputStream stream); static void uint64ToByteStreamLE(BigInteger val, OutputStream stream); static boolean isLessThanUnsigned(long n1, long n2); static boolean isLessThanOrEqualToUnsigned(long n1, long n2); static byte[] reverseBytes(byte[] bytes); static byte[] reverseDwordBytes(byte[] bytes, int trimLength); static long readUint32(byte[] bytes, int offset); static long readInt64(byte[] bytes, int offset); static long readUint32BE(byte[] bytes, int offset); static int readUint16BE(byte[] bytes, int offset); static byte[] sha256hash160(byte[] input); static BigInteger decodeMPI(byte[] mpi, boolean hasLength); static byte[] encodeMPI(BigInteger value, boolean includeLength); static BigInteger decodeCompactBits(long compact); static long encodeCompactBits(BigInteger value); static Date rollMockClock(int seconds); static Date rollMockClockMillis(long millis); static void setMockClock(); static void setMockClock(long mockClockSeconds); static Date now(); static long currentTimeMillis(); static long currentTimeSeconds(); static String dateTimeFormat(Date dateTime); static String dateTimeFormat(long dateTime); static String join(Iterable<T> items); static byte[] copyOf(byte[] in, int length); static byte[] appendByte(byte[] bytes, byte b); static String toString(byte[] bytes, String charsetName); static byte[] toBytes(CharSequence str, String charsetName); static byte[] parseAsHexOrBase58(String data); static boolean isWindows(); static byte[] formatMessageForSigning(String message); static boolean checkBitLE(byte[] data, int index); static void setBitLE(byte[] data, int index); static void sleep(long millis); static void setMockSleep(boolean isEnable); static void passMockSleep(); static void finishMockSleep(); static boolean isAndroidRuntime(); static int maxOfMostFreq(int... items); static int maxOfMostFreq(List<Integer> items); static String getResourceAsString(URL url); static InputStream closeUnchecked(InputStream stream); static OutputStream closeUnchecked(OutputStream stream); }
Utils { public static byte[] reverseDwordBytes(byte[] bytes, int trimLength) { checkArgument(bytes.length % 4 == 0); checkArgument(trimLength < 0 || trimLength % 4 == 0); byte[] rev = new byte[trimLength >= 0 && bytes.length > trimLength ? trimLength : bytes.length]; for (int i = 0; i < rev.length; i += 4) { System.arraycopy(bytes, i, rev, i , 4); for (int j = 0; j < 4; j++) { rev[i + j] = bytes[i + 3 - j]; } } return rev; }  static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static void uint32ToByteArrayBE(long val, byte[] out, int offset); static void uint32ToByteArrayLE(long val, byte[] out, int offset); static void uint64ToByteArrayLE(long val, byte[] out, int offset); static void uint32ToByteStreamLE(long val, OutputStream stream); static void int64ToByteStreamLE(long val, OutputStream stream); static void uint64ToByteStreamLE(BigInteger val, OutputStream stream); static boolean isLessThanUnsigned(long n1, long n2); static boolean isLessThanOrEqualToUnsigned(long n1, long n2); static byte[] reverseBytes(byte[] bytes); static byte[] reverseDwordBytes(byte[] bytes, int trimLength); static long readUint32(byte[] bytes, int offset); static long readInt64(byte[] bytes, int offset); static long readUint32BE(byte[] bytes, int offset); static int readUint16BE(byte[] bytes, int offset); static byte[] sha256hash160(byte[] input); static BigInteger decodeMPI(byte[] mpi, boolean hasLength); static byte[] encodeMPI(BigInteger value, boolean includeLength); static BigInteger decodeCompactBits(long compact); static long encodeCompactBits(BigInteger value); static Date rollMockClock(int seconds); static Date rollMockClockMillis(long millis); static void setMockClock(); static void setMockClock(long mockClockSeconds); static Date now(); static long currentTimeMillis(); static long currentTimeSeconds(); static String dateTimeFormat(Date dateTime); static String dateTimeFormat(long dateTime); static String join(Iterable<T> items); static byte[] copyOf(byte[] in, int length); static byte[] appendByte(byte[] bytes, byte b); static String toString(byte[] bytes, String charsetName); static byte[] toBytes(CharSequence str, String charsetName); static byte[] parseAsHexOrBase58(String data); static boolean isWindows(); static byte[] formatMessageForSigning(String message); static boolean checkBitLE(byte[] data, int index); static void setBitLE(byte[] data, int index); static void sleep(long millis); static void setMockSleep(boolean isEnable); static void passMockSleep(); static void finishMockSleep(); static boolean isAndroidRuntime(); static int maxOfMostFreq(int... items); static int maxOfMostFreq(List<Integer> items); static String getResourceAsString(URL url); static InputStream closeUnchecked(InputStream stream); static OutputStream closeUnchecked(OutputStream stream); static final String BITCOIN_SIGNED_MESSAGE_HEADER; static final byte[] BITCOIN_SIGNED_MESSAGE_HEADER_BYTES; static final BaseEncoding HEX; static volatile Date mockTime; }