target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void createsExecutionEnvironmentUponInit() { Assert.assertNull(contract.getExecutionEnvironment()); doInit(); ExecutionEnvironment executionEnvironment = contract.getExecutionEnvironment(); Assert.assertNotNull(executionEnvironment); Assert.assertEquals(tx, executionEnvironment.getTransaction()); Assert.assertEquals(block, executionEnvironment.getBlock()); Assert.assertEquals(repository, executionEnvironment.getRepository()); Assert.assertEquals(blockStore, executionEnvironment.getBlockStore()); Assert.assertEquals(receiptStore, executionEnvironment.getReceiptStore()); Assert.assertEquals(logs, executionEnvironment.getLogs()); }
|
public ExecutionEnvironment getExecutionEnvironment() { return executionEnvironment; }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { public ExecutionEnvironment getExecutionEnvironment() { return executionEnvironment; } }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { public ExecutionEnvironment getExecutionEnvironment() { return executionEnvironment; } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { public ExecutionEnvironment getExecutionEnvironment() { return executionEnvironment; } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { public ExecutionEnvironment getExecutionEnvironment() { return executionEnvironment; } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
@Test(expected = NullPointerException.class) public void testToHexString_NullPointerExceptionForNull() { assertEquals("", ByteUtil.toHexString(null)); }
|
@Nonnull public static String toHexString(@Nonnull byte[] data) { return Hex.toHexString(Objects.requireNonNull(data)); }
|
ByteUtil { @Nonnull public static String toHexString(@Nonnull byte[] data) { return Hex.toHexString(Objects.requireNonNull(data)); } }
|
ByteUtil { @Nonnull public static String toHexString(@Nonnull byte[] data) { return Hex.toHexString(Objects.requireNonNull(data)); } private ByteUtil(); }
|
ByteUtil { @Nonnull public static String toHexString(@Nonnull byte[] data) { return Hex.toHexString(Objects.requireNonNull(data)); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { @Nonnull public static String toHexString(@Nonnull byte[] data) { return Hex.toHexString(Objects.requireNonNull(data)); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void getGasForDataFailsWhenNoInit() { assertFails(() -> contract.getGasForData(Hex.decode("aabb"))); }
|
@Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
@Test public void getGasForDataZeroWhenNullData() { doInit(); Assert.assertEquals(0L, contract.getGasForData(null)); }
|
@Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
@Test public void getGasForDataZeroWhenEmptyData() { doInit(); Assert.assertEquals(0L, contract.getGasForData(null)); }
|
@Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
@Test public void getGasForNullDataAndDefaultMethod() { NativeMethod method = mock(NativeMethod.class); when(method.getGas(any(), any())).thenReturn(10L); contract = new EmptyNativeContract(activationConfig) { @Override public Optional<NativeMethod> getDefaultMethod() { return Optional.of(method); } }; doInit(); Assert.assertEquals(10L, contract.getGasForData(null)); }
|
@Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
@Test public void getGasForEmptyDataAndDefaultMethod() { NativeMethod method = mock(NativeMethod.class); when(method.getGas(any(), any())).thenReturn(10L); contract = new EmptyNativeContract(activationConfig) { @Override public Optional<NativeMethod> getDefaultMethod() { return Optional.of(method); } }; doInit(); Assert.assertEquals(10L, contract.getGasForData(new byte[]{})); }
|
@Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
@Test public void getGasForDataZeroWhenInvalidSignature() { doInit(); Assert.assertEquals(0L, contract.getGasForData(Hex.decode("aabb"))); }
|
@Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
@Test public void getGasForDataZeroWhenNoMappedMethod() { doInit(); Assert.assertEquals(0L, contract.getGasForData(Hex.decode("aabbccdd"))); }
|
@Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
NativeContract extends PrecompiledContracts.PrecompiledContract { @Override public long getGasForData(byte[] data) { if (executionEnvironment == null) { throw new RuntimeException("Execution environment is null"); } Optional<NativeMethod.WithArguments> methodWithArguments = parseData(data); if (!methodWithArguments.isPresent()) { return 0L; } return methodWithArguments.get().getGas(); } NativeContract(ActivationConfig activationConfig, RskAddress contractAddress); ExecutionEnvironment getExecutionEnvironment(); abstract List<NativeMethod> getMethods(); abstract Optional<NativeMethod> getDefaultMethod(); void before(); void after(); @Override void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs); @Override long getGasForData(byte[] data); @Override byte[] execute(byte[] data); }
|
@Test public void migrateConfiguration() { Reader initialConfiguration = new StringReader("inline.config.name=\"value\"\n" + "nested {\n" + " nested = {\n" + " #test comment\n" + " config = 13\n" + " }\n" + "}\n" + "flat.config = \"0.0.0.0\"\n" + "another.config=\"don't change\""); Properties migrationProperties = new Properties(); migrationProperties.put("inline.config.name", "inline.config.new.name"); migrationProperties.put("flat.config", "flat_config"); migrationProperties.put("nested.nested.config", "nested.nested.new.config"); migrationProperties.put("unknown.config", "none"); migrationProperties.put("[new]new.key", "new value"); migrationProperties.put("[new] other.new.key", "12"); String migratedConfiguration = Migrator.migrateConfiguration(initialConfiguration, migrationProperties); Config config = ConfigFactory.parseString(migratedConfiguration); assertThat(config.hasPath("inline.config.name"), is(false)); assertThat(config.getString("inline.config.new.name"), is("value")); assertThat(config.hasPath("flat.config"), is(false)); assertThat(config.hasPath("flat_config"), is(true)); assertThat(config.getString("flat_config"), is("0.0.0.0")); assertThat(config.hasPath("nested.nested.config"), is(false)); assertThat(config.getInt("nested.nested.new.config"), is(13)); assertThat(config.hasPath("unknown.config"), is(false)); assertThat(config.getString("another.config"), is("don't change")); assertThat(config.getString("new.key"), is("new value")); assertThat(config.getInt("other.new.key"), is(12)); }
|
public String migrateConfiguration() throws IOException { return migrateConfiguration( Files.newBufferedReader(configuration.getSourceConfiguration(), StandardCharsets.UTF_8), configuration.getMigrationConfiguration() ); }
|
Migrator { public String migrateConfiguration() throws IOException { return migrateConfiguration( Files.newBufferedReader(configuration.getSourceConfiguration(), StandardCharsets.UTF_8), configuration.getMigrationConfiguration() ); } }
|
Migrator { public String migrateConfiguration() throws IOException { return migrateConfiguration( Files.newBufferedReader(configuration.getSourceConfiguration(), StandardCharsets.UTF_8), configuration.getMigrationConfiguration() ); } Migrator(MigratorConfiguration configuration); }
|
Migrator { public String migrateConfiguration() throws IOException { return migrateConfiguration( Files.newBufferedReader(configuration.getSourceConfiguration(), StandardCharsets.UTF_8), configuration.getMigrationConfiguration() ); } Migrator(MigratorConfiguration configuration); String migrateConfiguration(); static String migrateConfiguration(Reader sourceReader, Properties migrationConfiguration); }
|
Migrator { public String migrateConfiguration() throws IOException { return migrateConfiguration( Files.newBufferedReader(configuration.getSourceConfiguration(), StandardCharsets.UTF_8), configuration.getMigrationConfiguration() ); } Migrator(MigratorConfiguration configuration); String migrateConfiguration(); static String migrateConfiguration(Reader sourceReader, Properties migrationConfiguration); }
|
@Test public void newNodeHasGoodReputation() { NodeID id = generateNodeID(); PeerScoringManager manager = createPeerScoringManager(); Assert.assertTrue(manager.hasGoodReputation(id)); }
|
public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } }
|
PeerScoringManager { public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } } }
|
PeerScoringManager { public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } } PeerScoringManager(
PeerScoring.Factory peerScoringFactory,
int nodePeersSize,
PunishmentParameters nodeParameters,
PunishmentParameters ipParameters); }
|
PeerScoringManager { public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } } PeerScoringManager(
PeerScoring.Factory peerScoringFactory,
int nodePeersSize,
PunishmentParameters nodeParameters,
PunishmentParameters ipParameters); void recordEvent(NodeID id, InetAddress address, EventType event); boolean hasGoodReputation(NodeID id); boolean hasGoodReputation(InetAddress address); void banAddress(InetAddress address); void banAddress(String address); void unbanAddress(InetAddress address); void unbanAddress(String address); void banAddressBlock(InetAddressBlock addressBlock); void unbanAddressBlock(InetAddressBlock addressBlock); List<PeerScoringInformation> getPeersInformation(); List<String> getBannedAddresses(); @VisibleForTesting boolean isEmpty(); @VisibleForTesting PeerScoring getPeerScoring(NodeID id); @VisibleForTesting PeerScoring getPeerScoring(InetAddress address); }
|
PeerScoringManager { public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } } PeerScoringManager(
PeerScoring.Factory peerScoringFactory,
int nodePeersSize,
PunishmentParameters nodeParameters,
PunishmentParameters ipParameters); void recordEvent(NodeID id, InetAddress address, EventType event); boolean hasGoodReputation(NodeID id); boolean hasGoodReputation(InetAddress address); void banAddress(InetAddress address); void banAddress(String address); void unbanAddress(InetAddress address); void unbanAddress(String address); void banAddressBlock(InetAddressBlock addressBlock); void unbanAddressBlock(InetAddressBlock addressBlock); List<PeerScoringInformation> getPeersInformation(); List<String> getBannedAddresses(); @VisibleForTesting boolean isEmpty(); @VisibleForTesting PeerScoring getPeerScoring(NodeID id); @VisibleForTesting PeerScoring getPeerScoring(InetAddress address); }
|
@Test public void newAddressHasGoodReputation() throws UnknownHostException { InetAddress address = generateIPAddressV4(); PeerScoringManager manager = createPeerScoringManager(); Assert.assertTrue(manager.hasGoodReputation(address)); }
|
public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } }
|
PeerScoringManager { public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } } }
|
PeerScoringManager { public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } } PeerScoringManager(
PeerScoring.Factory peerScoringFactory,
int nodePeersSize,
PunishmentParameters nodeParameters,
PunishmentParameters ipParameters); }
|
PeerScoringManager { public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } } PeerScoringManager(
PeerScoring.Factory peerScoringFactory,
int nodePeersSize,
PunishmentParameters nodeParameters,
PunishmentParameters ipParameters); void recordEvent(NodeID id, InetAddress address, EventType event); boolean hasGoodReputation(NodeID id); boolean hasGoodReputation(InetAddress address); void banAddress(InetAddress address); void banAddress(String address); void unbanAddress(InetAddress address); void unbanAddress(String address); void banAddressBlock(InetAddressBlock addressBlock); void unbanAddressBlock(InetAddressBlock addressBlock); List<PeerScoringInformation> getPeersInformation(); List<String> getBannedAddresses(); @VisibleForTesting boolean isEmpty(); @VisibleForTesting PeerScoring getPeerScoring(NodeID id); @VisibleForTesting PeerScoring getPeerScoring(InetAddress address); }
|
PeerScoringManager { public boolean hasGoodReputation(NodeID id) { synchronized (accessLock) { return this.getPeerScoring(id).hasGoodReputation(); } } PeerScoringManager(
PeerScoring.Factory peerScoringFactory,
int nodePeersSize,
PunishmentParameters nodeParameters,
PunishmentParameters ipParameters); void recordEvent(NodeID id, InetAddress address, EventType event); boolean hasGoodReputation(NodeID id); boolean hasGoodReputation(InetAddress address); void banAddress(InetAddress address); void banAddress(String address); void unbanAddress(InetAddress address); void unbanAddress(String address); void banAddressBlock(InetAddressBlock addressBlock); void unbanAddressBlock(InetAddressBlock addressBlock); List<PeerScoringInformation> getPeersInformation(); List<String> getBannedAddresses(); @VisibleForTesting boolean isEmpty(); @VisibleForTesting PeerScoring getPeerScoring(NodeID id); @VisibleForTesting PeerScoring getPeerScoring(InetAddress address); }
|
@Test public void testToHexStringOrEmpty_EmptyStringForNull() { assertEquals("", ByteUtil.toHexStringOrEmpty(null)); }
|
@Nonnull public static String toHexStringOrEmpty(@Nullable byte[] data) { return data == null ? "" : toHexString(data); }
|
ByteUtil { @Nonnull public static String toHexStringOrEmpty(@Nullable byte[] data) { return data == null ? "" : toHexString(data); } }
|
ByteUtil { @Nonnull public static String toHexStringOrEmpty(@Nullable byte[] data) { return data == null ? "" : toHexString(data); } private ByteUtil(); }
|
ByteUtil { @Nonnull public static String toHexStringOrEmpty(@Nullable byte[] data) { return data == null ? "" : toHexString(data); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { @Nonnull public static String toHexStringOrEmpty(@Nullable byte[] data) { return data == null ? "" : toHexString(data); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void calculatePunishmentTime() { PunishmentCalculator calculator = new PunishmentCalculator(new PunishmentParameters(100, 10, 1000)); Assert.assertEquals(100, calculator.calculate(0, 0)); }
|
public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
@Test public void calculatePunishmentTimeWithNegativeScore() { PunishmentCalculator calculator = new PunishmentCalculator(new PunishmentParameters(100, 10, 1000)); Assert.assertEquals(200, calculator.calculate(0, -2)); }
|
public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
@Test public void calculateSecondPunishmentTime() { PunishmentCalculator calculator = new PunishmentCalculator(new PunishmentParameters(100, 10, 1000)); Assert.assertEquals(110, calculator.calculate(1, 0)); }
|
public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
@Test public void calculateThirdPunishmentTime() { PunishmentCalculator calculator = new PunishmentCalculator(new PunishmentParameters(100, 10, 1000)); Assert.assertEquals(121, calculator.calculate(2, 0)); }
|
public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
@Test public void calculateThirdPunishmentTimeAndNegativeScore() { PunishmentCalculator calculator = new PunishmentCalculator(new PunishmentParameters(100, 10, 1000)); Assert.assertEquals(242, calculator.calculate(2, -2)); }
|
public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
@Test public void calculateUsingMaxPunishmentTime() { PunishmentCalculator calculator = new PunishmentCalculator(new PunishmentParameters(100, 10, 120)); Assert.assertEquals(120, calculator.calculate(2, 0)); }
|
public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
@Test public void calculateUsingNoMaxPunishmentTime() { PunishmentCalculator calculator = new PunishmentCalculator(new PunishmentParameters(100, 10, 0)); Assert.assertEquals(121, calculator.calculate(2, 0)); }
|
public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
PunishmentCalculator { public long calculate(int punishmentCounter, int score) { long result = this.parameters.getDuration(); long rate = 100L + this.parameters.getIncrementRate(); int counter = punishmentCounter; long maxDuration = this.parameters.getMaximumDuration(); while (counter-- > 0) { result = multiplyExact(result, rate) / 100; if (maxDuration > 0 && result > maxDuration) { return maxDuration; } } if (score < 0) { result *= -score; } return maxDuration > 0 ? Math.min(maxDuration, result) : result; } PunishmentCalculator(PunishmentParameters parameters); long calculate(int punishmentCounter, int score); }
|
@Test public void newStatusHasGoodReputation() { PeerScoring scoring = new PeerScoring(); Assert.assertTrue(scoring.hasGoodReputation()); }
|
public boolean hasGoodReputation() { try { rwlock.writeLock().lock(); if (this.goodReputation) { return true; } if (this.punishmentTime > 0 && this.timeLostGoodReputation > 0 && this.punishmentTime + this.timeLostGoodReputation <= System.currentTimeMillis()) { this.endPunishment(); } return this.goodReputation; } finally { rwlock.writeLock().unlock(); } }
|
PeerScoring { public boolean hasGoodReputation() { try { rwlock.writeLock().lock(); if (this.goodReputation) { return true; } if (this.punishmentTime > 0 && this.timeLostGoodReputation > 0 && this.punishmentTime + this.timeLostGoodReputation <= System.currentTimeMillis()) { this.endPunishment(); } return this.goodReputation; } finally { rwlock.writeLock().unlock(); } } }
|
PeerScoring { public boolean hasGoodReputation() { try { rwlock.writeLock().lock(); if (this.goodReputation) { return true; } if (this.punishmentTime > 0 && this.timeLostGoodReputation > 0 && this.punishmentTime + this.timeLostGoodReputation <= System.currentTimeMillis()) { this.endPunishment(); } return this.goodReputation; } finally { rwlock.writeLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); }
|
PeerScoring { public boolean hasGoodReputation() { try { rwlock.writeLock().lock(); if (this.goodReputation) { return true; } if (this.punishmentTime > 0 && this.timeLostGoodReputation > 0 && this.punishmentTime + this.timeLostGoodReputation <= System.currentTimeMillis()) { this.endPunishment(); } return this.goodReputation; } finally { rwlock.writeLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
PeerScoring { public boolean hasGoodReputation() { try { rwlock.writeLock().lock(); if (this.goodReputation) { return true; } if (this.punishmentTime > 0 && this.timeLostGoodReputation > 0 && this.punishmentTime + this.timeLostGoodReputation <= System.currentTimeMillis()) { this.endPunishment(); } return this.goodReputation; } finally { rwlock.writeLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
@Test public void getInformationFromNewScoring() { PeerScoring scoring = new PeerScoring(); PeerScoringInformation info = new PeerScoringInformation(scoring, "nodeid", "node"); Assert.assertTrue(info.getGoodReputation()); Assert.assertEquals(0, info.getValidBlocks()); Assert.assertEquals(0, info.getInvalidBlocks()); Assert.assertEquals(0, info.getValidTransactions()); Assert.assertEquals(0, info.getInvalidTransactions()); Assert.assertEquals(0, info.getScore()); Assert.assertEquals(0, info.getSuccessfulHandshakes()); Assert.assertEquals(0, info.getFailedHandshakes()); Assert.assertEquals(0, info.getRepeatedMessages()); Assert.assertEquals(0, info.getInvalidNetworks()); Assert.assertEquals("nodeid", info.getId()); Assert.assertEquals("node", info.getType()); }
|
public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } }
|
PeerScoring { public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } } }
|
PeerScoring { public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); }
|
PeerScoring { public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
PeerScoring { public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
@Test public void newStatusHasNoTimeLostGoodReputation() { PeerScoring scoring = new PeerScoring(); Assert.assertEquals(0, scoring.getTimeLostGoodReputation()); }
|
@VisibleForTesting public long getTimeLostGoodReputation() { return this.timeLostGoodReputation; }
|
PeerScoring { @VisibleForTesting public long getTimeLostGoodReputation() { return this.timeLostGoodReputation; } }
|
PeerScoring { @VisibleForTesting public long getTimeLostGoodReputation() { return this.timeLostGoodReputation; } PeerScoring(); PeerScoring(boolean punishmentEnabled); }
|
PeerScoring { @VisibleForTesting public long getTimeLostGoodReputation() { return this.timeLostGoodReputation; } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
PeerScoring { @VisibleForTesting public long getTimeLostGoodReputation() { return this.timeLostGoodReputation; } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
@Test public void testCalcPacketLength() { byte[] test = new byte[]{0x0f, 0x10, 0x43}; byte[] expected = new byte[]{0x00, 0x00, 0x00, 0x03}; assertArrayEquals(expected, ByteUtil.calcPacketLength(test)); }
|
public static byte[] calcPacketLength(byte[] msg) { int msgLen = msg.length; return new byte[]{ (byte) ((msgLen >> 24) & 0xFF), (byte) ((msgLen >> 16) & 0xFF), (byte) ((msgLen >> 8) & 0xFF), (byte) ((msgLen) & 0xFF)}; }
|
ByteUtil { public static byte[] calcPacketLength(byte[] msg) { int msgLen = msg.length; return new byte[]{ (byte) ((msgLen >> 24) & 0xFF), (byte) ((msgLen >> 16) & 0xFF), (byte) ((msgLen >> 8) & 0xFF), (byte) ((msgLen) & 0xFF)}; } }
|
ByteUtil { public static byte[] calcPacketLength(byte[] msg) { int msgLen = msg.length; return new byte[]{ (byte) ((msgLen >> 24) & 0xFF), (byte) ((msgLen >> 16) & 0xFF), (byte) ((msgLen >> 8) & 0xFF), (byte) ((msgLen) & 0xFF)}; } private ByteUtil(); }
|
ByteUtil { public static byte[] calcPacketLength(byte[] msg) { int msgLen = msg.length; return new byte[]{ (byte) ((msgLen >> 24) & 0xFF), (byte) ((msgLen >> 16) & 0xFF), (byte) ((msgLen >> 8) & 0xFF), (byte) ((msgLen) & 0xFF)}; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static byte[] calcPacketLength(byte[] msg) { int msgLen = msg.length; return new byte[]{ (byte) ((msgLen >> 24) & 0xFF), (byte) ((msgLen >> 16) & 0xFF), (byte) ((msgLen >> 8) & 0xFF), (byte) ((msgLen) & 0xFF)}; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void web3_sha3() throws Exception { String toHash = "RSK"; Web3 web3 = createWeb3(); String result = web3.web3_sha3(toHash); assertTrue("hash does not match", result.compareTo("0x80553b6b348ae45ab8e8bf75e77064818c0a772f13cf8d3a175d3815aec59b56") == 0); }
|
@Override public String web3_sha3(String data) throws Exception { String s = null; try { byte[] result = HashUtil.keccak256(data.getBytes(StandardCharsets.UTF_8)); return s = TypeConverter.toJsonHex(result); } finally { if (logger.isDebugEnabled()) { logger.debug("web3_sha3({}): {}", data, s); } } }
|
Web3Impl implements Web3 { @Override public String web3_sha3(String data) throws Exception { String s = null; try { byte[] result = HashUtil.keccak256(data.getBytes(StandardCharsets.UTF_8)); return s = TypeConverter.toJsonHex(result); } finally { if (logger.isDebugEnabled()) { logger.debug("web3_sha3({}): {}", data, s); } } } }
|
Web3Impl implements Web3 { @Override public String web3_sha3(String data) throws Exception { String s = null; try { byte[] result = HashUtil.keccak256(data.getBytes(StandardCharsets.UTF_8)); return s = TypeConverter.toJsonHex(result); } finally { if (logger.isDebugEnabled()) { logger.debug("web3_sha3({}): {}", data, s); } } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); }
|
Web3Impl implements Web3 { @Override public String web3_sha3(String data) throws Exception { String s = null; try { byte[] result = HashUtil.keccak256(data.getBytes(StandardCharsets.UTF_8)); return s = TypeConverter.toJsonHex(result); } finally { if (logger.isDebugEnabled()) { logger.debug("web3_sha3({}): {}", data, s); } } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); }
|
Web3Impl implements Web3 { @Override public String web3_sha3(String data) throws Exception { String s = null; try { byte[] result = HashUtil.keccak256(data.getBytes(StandardCharsets.UTF_8)); return s = TypeConverter.toJsonHex(result); } finally { if (logger.isDebugEnabled()) { logger.debug("web3_sha3({}): {}", data, s); } } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); public Ethereum eth; }
|
@Test public void recordEvent() { PeerScoring scoring = new PeerScoring(); scoring.recordEvent(EventType.INVALID_BLOCK); Assert.assertEquals(1, scoring.getEventCounter(EventType.INVALID_BLOCK)); Assert.assertEquals(0, scoring.getEventCounter(EventType.INVALID_TRANSACTION)); Assert.assertEquals(1, scoring.getTotalEventCounter()); }
|
public void recordEvent(EventType evt) { try { rwlock.writeLock().lock(); counters[evt.ordinal()]++; switch (evt) { case INVALID_NETWORK: case INVALID_BLOCK: case INVALID_TRANSACTION: case INVALID_MESSAGE: case INVALID_HEADER: if (score > 0) { score = 0; } score--; break; case UNEXPECTED_MESSAGE: case FAILED_HANDSHAKE: case SUCCESSFUL_HANDSHAKE: case REPEATED_MESSAGE: break; default: if (score >= 0) { score++; } break; } } finally { rwlock.writeLock().unlock(); } }
|
PeerScoring { public void recordEvent(EventType evt) { try { rwlock.writeLock().lock(); counters[evt.ordinal()]++; switch (evt) { case INVALID_NETWORK: case INVALID_BLOCK: case INVALID_TRANSACTION: case INVALID_MESSAGE: case INVALID_HEADER: if (score > 0) { score = 0; } score--; break; case UNEXPECTED_MESSAGE: case FAILED_HANDSHAKE: case SUCCESSFUL_HANDSHAKE: case REPEATED_MESSAGE: break; default: if (score >= 0) { score++; } break; } } finally { rwlock.writeLock().unlock(); } } }
|
PeerScoring { public void recordEvent(EventType evt) { try { rwlock.writeLock().lock(); counters[evt.ordinal()]++; switch (evt) { case INVALID_NETWORK: case INVALID_BLOCK: case INVALID_TRANSACTION: case INVALID_MESSAGE: case INVALID_HEADER: if (score > 0) { score = 0; } score--; break; case UNEXPECTED_MESSAGE: case FAILED_HANDSHAKE: case SUCCESSFUL_HANDSHAKE: case REPEATED_MESSAGE: break; default: if (score >= 0) { score++; } break; } } finally { rwlock.writeLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); }
|
PeerScoring { public void recordEvent(EventType evt) { try { rwlock.writeLock().lock(); counters[evt.ordinal()]++; switch (evt) { case INVALID_NETWORK: case INVALID_BLOCK: case INVALID_TRANSACTION: case INVALID_MESSAGE: case INVALID_HEADER: if (score > 0) { score = 0; } score--; break; case UNEXPECTED_MESSAGE: case FAILED_HANDSHAKE: case SUCCESSFUL_HANDSHAKE: case REPEATED_MESSAGE: break; default: if (score >= 0) { score++; } break; } } finally { rwlock.writeLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
PeerScoring { public void recordEvent(EventType evt) { try { rwlock.writeLock().lock(); counters[evt.ordinal()]++; switch (evt) { case INVALID_NETWORK: case INVALID_BLOCK: case INVALID_TRANSACTION: case INVALID_MESSAGE: case INVALID_HEADER: if (score > 0) { score = 0; } score--; break; case UNEXPECTED_MESSAGE: case FAILED_HANDSHAKE: case SUCCESSFUL_HANDSHAKE: case REPEATED_MESSAGE: break; default: if (score >= 0) { score++; } break; } } finally { rwlock.writeLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
@Test public void getZeroScoreWhenEmpty() { PeerScoring scoring = new PeerScoring(); Assert.assertEquals(0, scoring.getScore()); }
|
public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } }
|
PeerScoring { public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } } }
|
PeerScoring { public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); }
|
PeerScoring { public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
PeerScoring { public int getScore() { try { rwlock.readLock().lock(); return score; } finally { rwlock.readLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
@Test public void startPunishment() throws InterruptedException { PeerScoring scoring = new PeerScoring(); Assert.assertEquals(0, scoring.getPunishmentTime()); Assert.assertEquals(0, scoring.getPunishmentCounter()); scoring.startPunishment(1000); Assert.assertEquals(1, scoring.getPunishmentCounter()); Assert.assertFalse(scoring.hasGoodReputation()); Assert.assertEquals(1000, scoring.getPunishmentTime()); TimeUnit.MILLISECONDS.sleep(10); Assert.assertFalse(scoring.hasGoodReputation()); TimeUnit.MILLISECONDS.sleep(2000); Assert.assertTrue(scoring.hasGoodReputation()); Assert.assertEquals(1, scoring.getPunishmentCounter()); }
|
@VisibleForTesting public void startPunishment(long expirationTime) { if (!punishmentEnabled) { return; } try { rwlock.writeLock().lock(); this.goodReputation = false; this.punishmentTime = expirationTime; this.punishmentCounter++; this.timeLostGoodReputation = System.currentTimeMillis(); } finally { rwlock.writeLock().unlock(); } }
|
PeerScoring { @VisibleForTesting public void startPunishment(long expirationTime) { if (!punishmentEnabled) { return; } try { rwlock.writeLock().lock(); this.goodReputation = false; this.punishmentTime = expirationTime; this.punishmentCounter++; this.timeLostGoodReputation = System.currentTimeMillis(); } finally { rwlock.writeLock().unlock(); } } }
|
PeerScoring { @VisibleForTesting public void startPunishment(long expirationTime) { if (!punishmentEnabled) { return; } try { rwlock.writeLock().lock(); this.goodReputation = false; this.punishmentTime = expirationTime; this.punishmentCounter++; this.timeLostGoodReputation = System.currentTimeMillis(); } finally { rwlock.writeLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); }
|
PeerScoring { @VisibleForTesting public void startPunishment(long expirationTime) { if (!punishmentEnabled) { return; } try { rwlock.writeLock().lock(); this.goodReputation = false; this.punishmentTime = expirationTime; this.punishmentCounter++; this.timeLostGoodReputation = System.currentTimeMillis(); } finally { rwlock.writeLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
PeerScoring { @VisibleForTesting public void startPunishment(long expirationTime) { if (!punishmentEnabled) { return; } try { rwlock.writeLock().lock(); this.goodReputation = false; this.punishmentTime = expirationTime; this.punishmentCounter++; this.timeLostGoodReputation = System.currentTimeMillis(); } finally { rwlock.writeLock().unlock(); } } PeerScoring(); PeerScoring(boolean punishmentEnabled); void recordEvent(EventType evt); int getScore(); int getEventCounter(EventType evt); int getTotalEventCounter(); boolean isEmpty(); boolean hasGoodReputation(); @VisibleForTesting void startPunishment(long expirationTime); @VisibleForTesting long getPunishmentTime(); int getPunishmentCounter(); @VisibleForTesting long getTimeLostGoodReputation(); }
|
@Test public void recognizeIPV4AddressMask8Bits() throws UnknownHostException { InetAddress address = generateIPAddressV4(); InetAddressBlock mask = new InetAddressBlock(address, 8); Assert.assertTrue(mask.contains(address)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void containsIPV4() throws UnknownHostException { InetAddress address = generateIPAddressV4(); InetAddress address2 = alterByte(address, 3); InetAddressBlock mask = new InetAddressBlock(address, 8); Assert.assertTrue(mask.contains(address2)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void doesNotContainIPV4WithAlteredByte() throws UnknownHostException { InetAddress address = generateIPAddressV4(); InetAddress address2 = alterByte(address, 2); InetAddressBlock mask = new InetAddressBlock(address, 8); Assert.assertFalse(mask.contains(address2)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void doesNotContainIPV6() throws UnknownHostException { InetAddress address = generateIPAddressV4(); InetAddress address2 = generateIPAddressV6(); InetAddressBlock mask = new InetAddressBlock(address, 8); Assert.assertFalse(mask.contains(address2)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void using16BitsMask() throws UnknownHostException { InetAddress address = generateIPAddressV4(); InetAddress address2 = alterByte(address, 2); InetAddressBlock mask = new InetAddressBlock(address, 16); Assert.assertTrue(mask.contains(address2)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void usingIPV4With9BitsMask() throws UnknownHostException { InetAddress address = generateIPAddressV4(); byte[] bytes = address.getAddress(); bytes[2] ^= 1; InetAddress address2 = InetAddress.getByAddress(bytes); bytes[2] ^= 2; InetAddress address3 = InetAddress.getByAddress(bytes); InetAddressBlock mask = new InetAddressBlock(address, 9); Assert.assertTrue(mask.contains(address2)); Assert.assertFalse(mask.contains(address3)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void usingIPV6With9BitsMask() throws UnknownHostException { InetAddress address = generateIPAddressV6(); byte[] bytes = address.getAddress(); bytes[14] ^= 1; InetAddress address2 = InetAddress.getByAddress(bytes); bytes[14] ^= 2; InetAddress address3 = InetAddress.getByAddress(bytes); InetAddressBlock mask = new InetAddressBlock(address, 9); Assert.assertTrue(mask.contains(address2)); Assert.assertFalse(mask.contains(address3)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void testByteArrayToLong() { assertEquals(Long.MAX_VALUE, ByteUtil.byteArrayToLong(new byte[]{ (byte)127, (byte)255, (byte)255, (byte)255, (byte)255, (byte)255, (byte)255, (byte)255, } )); assertEquals(0, ByteUtil.byteArrayToLong(new byte[]{ } )); }
|
public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; }
|
ByteUtil { public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; } }
|
ByteUtil { public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; } private ByteUtil(); }
|
ByteUtil { public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void usingIPV4With18BitsMask() throws UnknownHostException { InetAddress address = generateIPAddressV4(); byte[] bytes = address.getAddress(); bytes[1] ^= 2; InetAddress address2 = InetAddress.getByAddress(bytes); bytes[1] ^= 4; InetAddress address3 = InetAddress.getByAddress(bytes); InetAddressBlock mask = new InetAddressBlock(address, 18); Assert.assertTrue(mask.contains(address2)); Assert.assertFalse(mask.contains(address3)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void usingIPV6With18BitsMask() throws UnknownHostException { InetAddress address = generateIPAddressV6(); byte[] bytes = address.getAddress(); bytes[13] ^= 2; InetAddress address2 = InetAddress.getByAddress(bytes); bytes[13] ^= 4; InetAddress address3 = InetAddress.getByAddress(bytes); InetAddressBlock mask = new InetAddressBlock(address, 18); Assert.assertTrue(mask.contains(address2)); Assert.assertFalse(mask.contains(address3)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void doesNotContainIPV4() throws UnknownHostException { InetAddress address = generateIPAddressV6(); InetAddress address2 = generateIPAddressV4(); InetAddressBlock mask = new InetAddressBlock(address, 8); Assert.assertFalse(mask.contains(address2)); }
|
public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { public boolean contains(InetAddress address) { byte[] addressBytes = address.getAddress(); if (addressBytes.length != this.bytes.length) { return false; } int k; for (k = 0; k < this.nbytes; k++) { if (addressBytes[k] != this.bytes[k]) { return false; } } if (this.mask != (byte)0xff) { return (addressBytes[k] & this.mask) == (this.bytes[k] & this.mask); } return true; } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void equals() throws UnknownHostException { InetAddress address1 = generateIPAddressV4(); InetAddress address2 = alterByte(address1, 0); InetAddress address3 = generateIPAddressV6(); InetAddressBlock block1 = new InetAddressBlock(address1, 8); InetAddressBlock block2 = new InetAddressBlock(address2, 9); InetAddressBlock block3 = new InetAddressBlock(address1, 1); InetAddressBlock block4 = new InetAddressBlock(address1, 8); InetAddressBlock block5 = new InetAddressBlock(address3, 8); Assert.assertTrue(block1.equals(block1)); Assert.assertTrue(block2.equals(block2)); Assert.assertTrue(block3.equals(block3)); Assert.assertTrue(block4.equals(block4)); Assert.assertTrue(block5.equals(block5)); Assert.assertTrue(block1.equals(block4)); Assert.assertTrue(block4.equals(block1)); Assert.assertFalse(block1.equals(block2)); Assert.assertFalse(block1.equals(block3)); Assert.assertFalse(block1.equals(block5)); Assert.assertFalse(block1.equals(null)); Assert.assertFalse(block1.equals("block")); Assert.assertEquals(block1.hashCode(), block4.hashCode()); }
|
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof InetAddressBlock)) { return false; } InetAddressBlock block = (InetAddressBlock)obj; return block.mask == this.mask && Arrays.equals(block.bytes, this.bytes); }
|
InetAddressBlock { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof InetAddressBlock)) { return false; } InetAddressBlock block = (InetAddressBlock)obj; return block.mask == this.mask && Arrays.equals(block.bytes, this.bytes); } }
|
InetAddressBlock { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof InetAddressBlock)) { return false; } InetAddressBlock block = (InetAddressBlock)obj; return block.mask == this.mask && Arrays.equals(block.bytes, this.bytes); } InetAddressBlock(InetAddress address, int bits); }
|
InetAddressBlock { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof InetAddressBlock)) { return false; } InetAddressBlock block = (InetAddressBlock)obj; return block.mask == this.mask && Arrays.equals(block.bytes, this.bytes); } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
InetAddressBlock { @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof InetAddressBlock)) { return false; } InetAddressBlock block = (InetAddressBlock)obj; return block.mask == this.mask && Arrays.equals(block.bytes, this.bytes); } InetAddressBlock(InetAddress address, int bits); boolean contains(InetAddress address); String getDescription(); @Override int hashCode(); @Override boolean equals(Object obj); @VisibleForTesting byte[] getBytes(); @VisibleForTesting byte getMask(); }
|
@Test public void doesNotContainsNewIPV4Address() throws UnknownHostException { InetAddressTable table = new InetAddressTable(); Assert.assertFalse(table.contains(generateIPAddressV4())); }
|
public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; }
|
InetAddressTable { public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; } }
|
InetAddressTable { public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; } }
|
InetAddressTable { public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; } void addAddress(InetAddress address); void removeAddress(InetAddress address); void addAddressBlock(InetAddressBlock addressBlock); void removeAddressBlock(InetAddressBlock addressBlock); boolean contains(InetAddress address); List<InetAddress> getAddressList(); List<InetAddressBlock> getAddressBlockList(); }
|
InetAddressTable { public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; } void addAddress(InetAddress address); void removeAddress(InetAddress address); void addAddressBlock(InetAddressBlock addressBlock); void removeAddressBlock(InetAddressBlock addressBlock); boolean contains(InetAddress address); List<InetAddress> getAddressList(); List<InetAddressBlock> getAddressBlockList(); }
|
@Test public void doesNotContainsNewIPV6Address() throws UnknownHostException { InetAddressTable table = new InetAddressTable(); Assert.assertFalse(table.contains(generateIPAddressV6())); }
|
public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; }
|
InetAddressTable { public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; } }
|
InetAddressTable { public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; } }
|
InetAddressTable { public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; } void addAddress(InetAddress address); void removeAddress(InetAddress address); void addAddressBlock(InetAddressBlock addressBlock); void removeAddressBlock(InetAddressBlock addressBlock); boolean contains(InetAddress address); List<InetAddress> getAddressList(); List<InetAddressBlock> getAddressBlockList(); }
|
InetAddressTable { public boolean contains(InetAddress address) { if (this.addresses.contains(address)) { return true; } if (this.blocks.isEmpty()) { return false; } InetAddressBlock[] bs = this.blocks.toArray(new InetAddressBlock[0]); for (InetAddressBlock mask : bs) { if (mask.contains(address)) { return true; } } return false; } void addAddress(InetAddress address); void removeAddress(InetAddress address); void addAddressBlock(InetAddressBlock addressBlock); void removeAddressBlock(InetAddressBlock addressBlock); boolean contains(InetAddress address); List<InetAddress> getAddressList(); List<InetAddressBlock> getAddressBlockList(); }
|
@Test public void hasMask() { Assert.assertFalse(InetAddressUtils.hasMask(null)); Assert.assertFalse(InetAddressUtils.hasMask("/")); Assert.assertFalse(InetAddressUtils.hasMask("1234/")); Assert.assertFalse(InetAddressUtils.hasMask("/1234")); Assert.assertFalse(InetAddressUtils.hasMask("1234/1234/1234")); Assert.assertFalse(InetAddressUtils.hasMask("1234 Assert.assertTrue(InetAddressUtils.hasMask("1234/1234")); }
|
public static boolean hasMask(String text) { if (text == null) { return false; } String[] parts = text.split("/"); return parts.length == 2 && parts[0].length() != 0 && parts[1].length() != 0; }
|
InetAddressUtils { public static boolean hasMask(String text) { if (text == null) { return false; } String[] parts = text.split("/"); return parts.length == 2 && parts[0].length() != 0 && parts[1].length() != 0; } }
|
InetAddressUtils { public static boolean hasMask(String text) { if (text == null) { return false; } String[] parts = text.split("/"); return parts.length == 2 && parts[0].length() != 0 && parts[1].length() != 0; } private InetAddressUtils(); }
|
InetAddressUtils { public static boolean hasMask(String text) { if (text == null) { return false; } String[] parts = text.split("/"); return parts.length == 2 && parts[0].length() != 0 && parts[1].length() != 0; } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static boolean hasMask(String text) { if (text == null) { return false; } String[] parts = text.split("/"); return parts.length == 2 && parts[0].length() != 0 && parts[1].length() != 0; } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void getAddressFromIPV4() throws InvalidInetAddressException { InetAddress address = InetAddressUtils.getAddressForBan("192.168.56.1"); Assert.assertNotNull(address); byte[] bytes = address.getAddress(); Assert.assertNotNull(bytes); Assert.assertEquals(4, bytes.length); Assert.assertArrayEquals(new byte[] { (byte)192, (byte)168, (byte)56, (byte)1}, bytes); }
|
public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void getAddressFromIPV6() throws InvalidInetAddressException, UnknownHostException { InetAddress address = InetAddressUtils.getAddressForBan("fe80::498a:7f0e:e63d:6b98"); InetAddress expected = InetAddress.getByName("fe80::498a:7f0e:e63d:6b98"); Assert.assertNotNull(address); byte[] bytes = address.getAddress(); Assert.assertNotNull(bytes); Assert.assertEquals(16, bytes.length); Assert.assertArrayEquals(expected.getAddress(), bytes); }
|
public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void getAddressFromNull() { try { InetAddressUtils.getAddressForBan(null); Assert.fail(); } catch (InvalidInetAddressException ex) { Assert.assertEquals("null address", ex.getMessage()); } }
|
public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test(expected = IllegalArgumentException.class) public void testByteArrayToLongThrowsWhenOverflow() { assertEquals(Long.MAX_VALUE, ByteUtil.byteArrayToLong(new byte[]{ (byte)255, (byte)255, (byte)255, (byte)255, (byte)255, (byte)255, (byte)255, (byte)255, (byte)123, } )); }
|
public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; }
|
ByteUtil { public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; } }
|
ByteUtil { public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; } private ByteUtil(); }
|
ByteUtil { public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static long byteArrayToLong(byte[] b) { if (b == null || b.length == 0) { return 0; } if (b.length > 8) { throw new IllegalArgumentException("byte array can't have more than 8 bytes if it is to be cast to long"); } long result = 0; for (int i = 0; i < b.length; i++) { result <<= 8; result |= (b[i] & 0xFF); } return result; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void getAddressFromEmptyString() { try { InetAddressUtils.getAddressForBan(""); Assert.fail(); } catch (InvalidInetAddressException ex) { Assert.assertEquals("empty address", ex.getMessage()); } }
|
public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void getAddressFromBlankString() { try { InetAddressUtils.getAddressForBan(" "); Assert.fail(); } catch (InvalidInetAddressException ex) { Assert.assertEquals("empty address", ex.getMessage()); } }
|
public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void getLocalAddress() { try { InetAddressUtils.getAddressForBan("127.0.0.1"); Assert.fail(); } catch (InvalidInetAddressException ex) { Assert.assertEquals("local address: '127.0.0.1'", ex.getMessage()); } }
|
public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void getLocalHost() { try { InetAddressUtils.getAddressForBan("localhost"); Assert.fail(); } catch (InvalidInetAddressException ex) { Assert.assertEquals("local address: 'localhost'", ex.getMessage()); } }
|
public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void getAnyLocalAddress() { try { InetAddressUtils.getAddressForBan("0.0.0.0"); Assert.fail(); } catch (InvalidInetAddressException ex) { Assert.assertEquals("local address: '0.0.0.0'", ex.getMessage()); } }
|
public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddress getAddressForBan(@CheckForNull String hostname) throws InvalidInetAddressException { if (hostname == null) { throw new InvalidInetAddressException("null address", null); } String name = hostname.trim(); if (name.length() == 0) { throw new InvalidInetAddressException("empty address", null); } try { InetAddress address = InetAddress.getByName(name); if (address.isLoopbackAddress() || address.isAnyLocalAddress()) { throw new InvalidInetAddressException("local address: '" + name + "'", null); } return address; } catch (UnknownHostException ex) { throw new InvalidInetAddressException("unknown host: '" + name + "'", ex); } } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void parseAddressBlock() throws InvalidInetAddressException, InvalidInetAddressBlockException, UnknownHostException { InetAddressBlock result = InetAddressUtils.parse("192.162.12.0/8"); Assert.assertNotNull(result); Assert.assertArrayEquals(InetAddress.getByName("192.162.12.0").getAddress(), result.getBytes()); Assert.assertEquals((byte)0xff, result.getMask()); }
|
public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void parseAddressBlockWithNonNumericBits() throws InvalidInetAddressException { try { InetAddressUtils.parse("192.162.12.0/a"); Assert.fail(); } catch (InvalidInetAddressBlockException ex) { Assert.assertEquals("Invalid mask", ex.getMessage()); } }
|
public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void parseAddressBlockWithNegativeNumberOfBits() throws UnknownHostException, InvalidInetAddressException { try { InetAddressUtils.parse("192.162.12.0/-10"); Assert.fail(); } catch (InvalidInetAddressBlockException ex) { Assert.assertEquals("Invalid mask", ex.getMessage()); } }
|
public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void parseAddressBlockWithZeroBits() throws InvalidInetAddressException { try { InetAddressUtils.parse("192.162.12.0/0"); Assert.fail(); } catch (InvalidInetAddressBlockException ex) { Assert.assertEquals("Invalid mask", ex.getMessage()); } }
|
public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void parseAddressBlockWithTooBigNumberOfBits() throws InvalidInetAddressException { try { InetAddressUtils.parse("192.162.12.0/1000"); Assert.fail(); } catch (InvalidInetAddressBlockException ex) { Assert.assertEquals("Invalid mask", ex.getMessage()); } }
|
public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
InetAddressUtils { public static InetAddressBlock parse(String text) throws InvalidInetAddressException { String[] parts = text.split("/"); InetAddress address; address = InetAddressUtils.getAddressForBan(parts[0]); int nbits; try { nbits = Integer.parseInt(parts[1]); } catch (NumberFormatException ex) { throw new InvalidInetAddressBlockException("Invalid mask", ex); } if (nbits <= 0 || nbits > address.getAddress().length * 8) { throw new InvalidInetAddressBlockException("Invalid mask", null); } return new InetAddressBlock(address, nbits); } private InetAddressUtils(); static boolean hasMask(String text); static InetAddress getAddressForBan(@CheckForNull String hostname); static InetAddressBlock parse(String text); }
|
@Test public void testByteArrayToInt() { assertEquals(0, ByteUtil.byteArrayToInt(null)); assertEquals(0, ByteUtil.byteArrayToInt(new byte[0])); }
|
public static int byteArrayToInt(byte[] b) { if (b == null || b.length == 0) { return 0; } return new BigInteger(1, b).intValue(); }
|
ByteUtil { public static int byteArrayToInt(byte[] b) { if (b == null || b.length == 0) { return 0; } return new BigInteger(1, b).intValue(); } }
|
ByteUtil { public static int byteArrayToInt(byte[] b) { if (b == null || b.length == 0) { return 0; } return new BigInteger(1, b).intValue(); } private ByteUtil(); }
|
ByteUtil { public static int byteArrayToInt(byte[] b) { if (b == null || b.length == 0) { return 0; } return new BigInteger(1, b).intValue(); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int byteArrayToInt(byte[] b) { if (b == null || b.length == 0) { return 0; } return new BigInteger(1, b).intValue(); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void emptyScoringHasGoodReputation() { ScoringCalculator calculator = new ScoringCalculator(); PeerScoring scoring = new PeerScoring(); Assert.assertTrue(calculator.hasGoodReputation(scoring)); }
|
public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
@Test public void scoringWithOneValidBlockHasGoodReputation() { ScoringCalculator calculator = new ScoringCalculator(); PeerScoring scoring = new PeerScoring(); scoring.recordEvent(EventType.VALID_BLOCK); Assert.assertTrue(calculator.hasGoodReputation(scoring)); }
|
public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
@Test public void scoringWithOneValidTransactionHasGoodReputation() { ScoringCalculator calculator = new ScoringCalculator(); PeerScoring scoring = new PeerScoring(); scoring.recordEvent(EventType.VALID_TRANSACTION); Assert.assertTrue(calculator.hasGoodReputation(scoring)); }
|
public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
@Test public void scoringWithOneInvalidBlockHasBadReputation() { ScoringCalculator calculator = new ScoringCalculator(); PeerScoring scoring = new PeerScoring(); scoring.recordEvent(EventType.INVALID_BLOCK); Assert.assertFalse(calculator.hasGoodReputation(scoring)); }
|
public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
@Test public void scoringWithOneInvalidTransactionHasNoBadReputation() { ScoringCalculator calculator = new ScoringCalculator(); PeerScoring scoring = new PeerScoring(); scoring.recordEvent(EventType.INVALID_TRANSACTION); Assert.assertTrue(calculator.hasGoodReputation(scoring)); }
|
public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
ScoringCalculator { public boolean hasGoodReputation(PeerScoring scoring) { return scoring.getEventCounter(EventType.INVALID_BLOCK) < 1 && scoring.getEventCounter(EventType.INVALID_MESSAGE) < 1 && scoring.getEventCounter(EventType.INVALID_HEADER) < 1; } boolean hasGoodReputation(PeerScoring scoring); }
|
@Test public void testNumBytes() { String test1 = "0"; String test2 = "1"; String test3 = "1000000000"; int expected1 = 1; int expected2 = 1; int expected3 = 4; assertEquals(expected1, ByteUtil.numBytes(test1)); assertEquals(expected2, ByteUtil.numBytes(test2)); assertEquals(expected3, ByteUtil.numBytes(test3)); }
|
public static int numBytes(String val) { return new BigInteger(val).bitLength() / 8 + 1; }
|
ByteUtil { public static int numBytes(String val) { return new BigInteger(val).bitLength() / 8 + 1; } }
|
ByteUtil { public static int numBytes(String val) { return new BigInteger(val).bitLength() / 8 + 1; } private ByteUtil(); }
|
ByteUtil { public static int numBytes(String val) { return new BigInteger(val).bitLength() / 8 + 1; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int numBytes(String val) { return new BigInteger(val).bitLength() / 8 + 1; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testStripLeadingZeroes() { byte[] test1 = null; byte[] test2 = new byte[]{}; byte[] test3 = new byte[]{0x00}; byte[] test4 = new byte[]{0x00, 0x01}; byte[] test5 = new byte[]{0x00, 0x00, 0x01}; byte[] expected1 = null; byte[] expected2 = new byte[]{0}; byte[] expected3 = new byte[]{0}; byte[] expected4 = new byte[]{0x01}; byte[] expected5 = new byte[]{0x01}; assertArrayEquals(expected1, ByteUtil.stripLeadingZeroes(test1)); assertArrayEquals(expected2, ByteUtil.stripLeadingZeroes(test2)); assertArrayEquals(expected3, ByteUtil.stripLeadingZeroes(test3)); assertArrayEquals(expected4, ByteUtil.stripLeadingZeroes(test4)); assertArrayEquals(expected5, ByteUtil.stripLeadingZeroes(test5)); }
|
public static byte[] stripLeadingZeroes(byte[] data) { return stripLeadingZeroes(data, ZERO_BYTE_ARRAY); }
|
ByteUtil { public static byte[] stripLeadingZeroes(byte[] data) { return stripLeadingZeroes(data, ZERO_BYTE_ARRAY); } }
|
ByteUtil { public static byte[] stripLeadingZeroes(byte[] data) { return stripLeadingZeroes(data, ZERO_BYTE_ARRAY); } private ByteUtil(); }
|
ByteUtil { public static byte[] stripLeadingZeroes(byte[] data) { return stripLeadingZeroes(data, ZERO_BYTE_ARRAY); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static byte[] stripLeadingZeroes(byte[] data) { return stripLeadingZeroes(data, ZERO_BYTE_ARRAY); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testMatchingNibbleLength1() { byte[] a = new byte[]{0x00, 0x01}; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(1, result); }
|
public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testMatchingNibbleLength2() { byte[] a = new byte[]{0x00}; byte[] b = new byte[]{0x00, 0x01}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(1, result); }
|
public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testMatchingNibbleLength3() { byte[] a = new byte[]{0x00}; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(1, result); }
|
public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testMatchingNibbleLength4() { byte[] a = new byte[]{0x01}; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(0, result); }
|
public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testNiceNiblesOutput_1() { byte[] test = {7, 0, 7, 5, 7, 0, 7, 0, 7, 9}; String result = "\\x07\\x00\\x07\\x05\\x07\\x00\\x07\\x00\\x07\\x09"; assertEquals(result, ByteUtil.nibblesToPrettyString(test)); }
|
public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); }
|
ByteUtil { public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); } }
|
ByteUtil { public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); } private ByteUtil(); }
|
ByteUtil { public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void eth_syncing_returnFalseWhenNotSyncing() { World world = new World(); SimpleBlockProcessor nodeProcessor = new SimpleBlockProcessor(); nodeProcessor.lastKnownBlockNumber = 0; Web3Impl web3 = createWeb3(world, nodeProcessor, null); Object result = web3.eth_syncing(); assertTrue("Node is not syncing, must return false", !(boolean)result); }
|
@Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } }
|
Web3Impl implements Web3 { @Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } } }
|
Web3Impl implements Web3 { @Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); }
|
Web3Impl implements Web3 { @Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); }
|
Web3Impl implements Web3 { @Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); public Ethereum eth; }
|
@Test public void testNiceNiblesOutput_2() { byte[] test = {7, 0, 7, 0xf, 7, 0, 0xa, 0, 7, 9}; String result = "\\x07\\x00\\x07\\x0f\\x07\\x00\\x0a\\x00\\x07\\x09"; assertEquals(result, ByteUtil.nibblesToPrettyString(test)); }
|
public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); }
|
ByteUtil { public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); } }
|
ByteUtil { public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); } private ByteUtil(); }
|
ByteUtil { public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static String nibblesToPrettyString(byte[] nibbles) { StringBuilder builder = new StringBuilder(); for (byte nibble : nibbles) { final String nibbleString = oneByteToHexString(nibble); builder.append("\\x").append(nibbleString); } return builder.toString(); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test(expected = NullPointerException.class) public void testMatchingNibbleLength5() { byte[] a = null; byte[] b = new byte[]{0x00}; ByteUtil.matchingNibbleLength(a, b); }
|
public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test(expected = NullPointerException.class) public void testMatchingNibbleLength6() { byte[] a = new byte[]{0x00}; byte[] b = null; ByteUtil.matchingNibbleLength(a, b); }
|
public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testMatchingNibbleLength7() { byte[] a = new byte[0]; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(0, result); }
|
public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int matchingNibbleLength(byte[] a, byte[] b) { int i = 0; int length = a.length < b.length ? a.length : b.length; while (i < length) { if (a[i] != b[i]) { return i; } i++; } return i; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void firstNonZeroByte_1() { byte[] data = Hex.decode("0000000000000000000000000000000000000000000000000000000000000000"); int result = ByteUtil.firstNonZeroByte(data); assertEquals(-1, result); }
|
public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } private ByteUtil(); }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void firstNonZeroByte_2() { byte[] data = Hex.decode("0000000000000000000000000000000000000000000000000000000000332211"); int result = ByteUtil.firstNonZeroByte(data); assertEquals(29, result); }
|
public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } private ByteUtil(); }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void firstNonZeroByte_3() { byte[] data = Hex.decode("2211009988776655443322110099887766554433221100998877665544332211"); int result = ByteUtil.firstNonZeroByte(data); assertEquals(0, result); }
|
public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } private ByteUtil(); }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int firstNonZeroByte(byte[] data) { for (int i = 0; i < data.length; ++i) { if (data[i] != 0) { return i; } } return -1; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void setBitTest() { byte[] data = ByteBuffer.allocate(4).putInt(0).array(); int posBit = 24; int expected = 16777216; int result = -1; byte[] ret = ByteUtil.setBit(data, posBit, 1); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); posBit = 25; expected = 50331648; ret = ByteUtil.setBit(data, posBit, 1); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); posBit = 2; expected = 50331652; ret = ByteUtil.setBit(data, posBit, 1); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); posBit = 24; expected = 33554436; ret = ByteUtil.setBit(data, posBit, 0); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); posBit = 25; expected = 4; ret = ByteUtil.setBit(data, posBit, 0); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); posBit = 2; expected = 0; ret = ByteUtil.setBit(data, posBit, 0); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); }
|
public static byte[] setBit(byte[] data, int pos, int val) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - (pos) / 8; int posBit = (pos) % 8; byte setter = (byte) (1 << (posBit)); byte toBeSet = data[posByte]; byte result; if (val == 1) { result = (byte) (toBeSet | setter); } else { result = (byte) (toBeSet & ~setter); } data[posByte] = result; return data; }
|
ByteUtil { public static byte[] setBit(byte[] data, int pos, int val) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - (pos) / 8; int posBit = (pos) % 8; byte setter = (byte) (1 << (posBit)); byte toBeSet = data[posByte]; byte result; if (val == 1) { result = (byte) (toBeSet | setter); } else { result = (byte) (toBeSet & ~setter); } data[posByte] = result; return data; } }
|
ByteUtil { public static byte[] setBit(byte[] data, int pos, int val) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - (pos) / 8; int posBit = (pos) % 8; byte setter = (byte) (1 << (posBit)); byte toBeSet = data[posByte]; byte result; if (val == 1) { result = (byte) (toBeSet | setter); } else { result = (byte) (toBeSet & ~setter); } data[posByte] = result; return data; } private ByteUtil(); }
|
ByteUtil { public static byte[] setBit(byte[] data, int pos, int val) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - (pos) / 8; int posBit = (pos) % 8; byte setter = (byte) (1 << (posBit)); byte toBeSet = data[posByte]; byte result; if (val == 1) { result = (byte) (toBeSet | setter); } else { result = (byte) (toBeSet & ~setter); } data[posByte] = result; return data; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static byte[] setBit(byte[] data, int pos, int val) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - (pos) / 8; int posBit = (pos) % 8; byte setter = (byte) (1 << (posBit)); byte toBeSet = data[posByte]; byte result; if (val == 1) { result = (byte) (toBeSet | setter); } else { result = (byte) (toBeSet & ~setter); } data[posByte] = result; return data; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void getBitTest() { byte[] data = ByteBuffer.allocate(4).putInt(0).array(); ByteUtil.setBit(data, 24, 1); ByteUtil.setBit(data, 25, 1); ByteUtil.setBit(data, 2, 1); List<Integer> found = new ArrayList<>(); for (int i = 0; i < (data.length * 8); i++) { int res = ByteUtil.getBit(data, i); if (res == 1) if (i != 24 && i != 25 && i != 2) assertTrue(false); else found.add(i); else { if (i == 24 || i == 25 || i == 2) assertTrue(false); } } if (found.size() != 3) assertTrue(false); assertTrue(found.get(0) == 2); assertTrue(found.get(1) == 24); assertTrue(found.get(2) == 25); }
|
public static int getBit(byte[] data, int pos) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - pos / 8; int posBit = pos % 8; byte dataByte = data[posByte]; return Math.min(1, (dataByte & 0xff & (1 << (posBit)))); }
|
ByteUtil { public static int getBit(byte[] data, int pos) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - pos / 8; int posBit = pos % 8; byte dataByte = data[posByte]; return Math.min(1, (dataByte & 0xff & (1 << (posBit)))); } }
|
ByteUtil { public static int getBit(byte[] data, int pos) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - pos / 8; int posBit = pos % 8; byte dataByte = data[posByte]; return Math.min(1, (dataByte & 0xff & (1 << (posBit)))); } private ByteUtil(); }
|
ByteUtil { public static int getBit(byte[] data, int pos) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - pos / 8; int posBit = pos % 8; byte dataByte = data[posByte]; return Math.min(1, (dataByte & 0xff & (1 << (posBit)))); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int getBit(byte[] data, int pos) { if ((data.length * 8) - 1 < pos) { throw new Error("outside byte array limit, pos: " + pos); } int posByte = data.length - 1 - pos / 8; int posBit = pos % 8; byte dataByte = data[posByte]; return Math.min(1, (dataByte & 0xff & (1 << (posBit)))); } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void testNumberOfLeadingZeros() { int n0 = ByteUtil.numberOfLeadingZeros(new byte[0]); assertEquals(0, n0); int n1 = ByteUtil.numberOfLeadingZeros(Hex.decode("05")); assertEquals(5, n1); int n2 = ByteUtil.numberOfLeadingZeros(Hex.decode("01")); assertEquals(7, n2); int n3 = ByteUtil.numberOfLeadingZeros(Hex.decode("00")); assertEquals(8, n3); int n4 = ByteUtil.numberOfLeadingZeros(Hex.decode("ff")); assertEquals(0, n4); byte[] v1 = Hex.decode("1040"); int n5 = ByteUtil.numberOfLeadingZeros(v1); assertEquals(3, n5); byte[] v2 = new byte[4]; System.arraycopy(v1, 0, v2, 2, v1.length); int n6 = ByteUtil.numberOfLeadingZeros(v2); assertEquals(19, n6); byte[] v3 = new byte[8]; int n7 = ByteUtil.numberOfLeadingZeros(v3); assertEquals(64, n7); }
|
public static int numberOfLeadingZeros(byte[] bytes) { int i = firstNonZeroByte(bytes); if (i == -1) { return bytes.length * 8; } else { int byteLeadingZeros = Integer.numberOfLeadingZeros((int)bytes[i] & 0xff) - 24; return i * 8 + byteLeadingZeros; } }
|
ByteUtil { public static int numberOfLeadingZeros(byte[] bytes) { int i = firstNonZeroByte(bytes); if (i == -1) { return bytes.length * 8; } else { int byteLeadingZeros = Integer.numberOfLeadingZeros((int)bytes[i] & 0xff) - 24; return i * 8 + byteLeadingZeros; } } }
|
ByteUtil { public static int numberOfLeadingZeros(byte[] bytes) { int i = firstNonZeroByte(bytes); if (i == -1) { return bytes.length * 8; } else { int byteLeadingZeros = Integer.numberOfLeadingZeros((int)bytes[i] & 0xff) - 24; return i * 8 + byteLeadingZeros; } } private ByteUtil(); }
|
ByteUtil { public static int numberOfLeadingZeros(byte[] bytes) { int i = firstNonZeroByte(bytes); if (i == -1) { return bytes.length * 8; } else { int byteLeadingZeros = Integer.numberOfLeadingZeros((int)bytes[i] & 0xff) - 24; return i * 8 + byteLeadingZeros; } } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static int numberOfLeadingZeros(byte[] bytes) { int i = firstNonZeroByte(bytes); if (i == -1) { return bytes.length * 8; } else { int byteLeadingZeros = Integer.numberOfLeadingZeros((int)bytes[i] & 0xff) - 24; return i * 8 + byteLeadingZeros; } } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void eth_syncing_returnSyncingResultWhenSyncing() { World world = new World(); SimpleBlockProcessor nodeProcessor = new SimpleBlockProcessor(); nodeProcessor.lastKnownBlockNumber = 5; Web3Impl web3 = createWeb3(world, nodeProcessor, null); Object result = web3.eth_syncing(); assertTrue("Node is syncing, must return sync manager", result instanceof Web3.SyncingResult); assertTrue("Highest block is 5", ((Web3.SyncingResult)result).highestBlock.compareTo("0x5") == 0); assertTrue("Simple blockchain starts from genesis block", ((Web3.SyncingResult)result).currentBlock.compareTo("0x0") == 0); }
|
@Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } }
|
Web3Impl implements Web3 { @Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } } }
|
Web3Impl implements Web3 { @Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); }
|
Web3Impl implements Web3 { @Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); }
|
Web3Impl implements Web3 { @Override public Object eth_syncing() { long currentBlock = this.blockchain.getBestBlock().getNumber(); long highestBlock = this.nodeBlockProcessor.getLastKnownBlockNumber(); if (highestBlock <= currentBlock){ return false; } SyncingResult s = new SyncingResult(); try { s.startingBlock = TypeConverter.toQuantityJsonHex(initialBlockNumber); s.currentBlock = TypeConverter.toQuantityJsonHex(currentBlock); s.highestBlock = toQuantityJsonHex(highestBlock); return s; } finally { logger.debug("eth_syncing(): starting {}, current {}, highest {} ", s.startingBlock, s.currentBlock, s.highestBlock); } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); public Ethereum eth; }
|
@Test public void testParseBytes() { byte[] shortByteArray = new byte[]{0,1}; byte[] normalByteArray = new byte[]{0,1,2,3,4,5}; byte[] normalByteArrayOffset3LeadingZeroes = new byte[]{3,4,5,0,0,0}; byte[] b1 = ByteUtil.parseBytes(shortByteArray, shortByteArray.length+1, 10); assertEquals(b1,ByteUtil.EMPTY_BYTE_ARRAY); byte[] b2 = ByteUtil.parseBytes(shortByteArray, shortByteArray.length-1, 0); assertEquals(b1,ByteUtil.EMPTY_BYTE_ARRAY); byte[] b3 = ByteUtil.parseBytes(normalByteArray, normalByteArray.length -3, normalByteArrayOffset3LeadingZeroes.length); for (int i=0; i < b3.length; i++) { assertEquals(b3[i],normalByteArrayOffset3LeadingZeroes[i]); } }
|
public static byte[] parseBytes(byte[] input, int offset, int len) { if (offset >= input.length || len == 0) { return EMPTY_BYTE_ARRAY; } byte[] bytes = new byte[len]; System.arraycopy(input, offset, bytes, 0, Math.min(input.length - offset, len)); return bytes; }
|
ByteUtil { public static byte[] parseBytes(byte[] input, int offset, int len) { if (offset >= input.length || len == 0) { return EMPTY_BYTE_ARRAY; } byte[] bytes = new byte[len]; System.arraycopy(input, offset, bytes, 0, Math.min(input.length - offset, len)); return bytes; } }
|
ByteUtil { public static byte[] parseBytes(byte[] input, int offset, int len) { if (offset >= input.length || len == 0) { return EMPTY_BYTE_ARRAY; } byte[] bytes = new byte[len]; System.arraycopy(input, offset, bytes, 0, Math.min(input.length - offset, len)); return bytes; } private ByteUtil(); }
|
ByteUtil { public static byte[] parseBytes(byte[] input, int offset, int len) { if (offset >= input.length || len == 0) { return EMPTY_BYTE_ARRAY; } byte[] bytes = new byte[len]; System.arraycopy(input, offset, bytes, 0, Math.min(input.length - offset, len)); return bytes; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); }
|
ByteUtil { public static byte[] parseBytes(byte[] input, int offset, int len) { if (offset >= input.length || len == 0) { return EMPTY_BYTE_ARRAY; } byte[] bytes = new byte[len]; System.arraycopy(input, offset, bytes, 0, Math.min(input.length - offset, len)); return bytes; } private ByteUtil(); static byte[] appendByte(byte[] bytes, byte b); static byte[] cloneBytes(byte[] bytes); static byte[] bigIntegerToBytes(BigInteger b, int numBytes); static byte[] bigIntegerToBytes(BigInteger value); static byte[] parseBytes(byte[] input, int offset, int len); static byte[] parseWord(byte[] input, int idx); static byte[] parseWord(byte[] input, int offset, int idx); static int matchingNibbleLength(byte[] a, byte[] b); static byte[] longToBytes(long val); static byte[] longToBytesNoLeadZeroes(long val); static byte[] intToBytes(int val); static byte[] intToBytesNoLeadZeroes(int val); @Nonnull static String toHexStringOrEmpty(@Nullable byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data); @Nonnull static String toHexString(@Nonnull byte[] data, int off, int length); static byte[] calcPacketLength(byte[] msg); static int byteArrayToInt(byte[] b); static long byteArrayToLong(byte[] b); static String nibblesToPrettyString(byte[] nibbles); static String oneByteToHexString(byte value); static int numBytes(String val); static int firstNonZeroByte(byte[] data); static byte[] stripLeadingZeroes(byte[] data); static byte[] stripLeadingZeroes(byte[] data, byte[] valueForZero); static boolean increment(byte[] bytes); static byte[] copyToArray(BigInteger value); static ByteArrayWrapper wrap(byte[] data); static byte[] setBit(byte[] data, int pos, int val); static int getBit(byte[] data, int pos); static byte[] and(byte[] b1, byte[] b2); static byte[] or(byte[] b1, byte[] b2); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftLeft(byte[] byteArray, int shiftBitCount); @java.lang.SuppressWarnings("squid:S3034") static byte[] shiftRight(byte[] byteArray, int shiftBitCount); static byte[] merge(byte[]... arrays); static boolean isSingleZero(byte[] array); static boolean isAllZeroes(byte[] array); static Set<T> difference(Set<T> setA, Set<T> setB); static int length(byte[]... bytes); static short bigEndianToShort(byte[] bs); static short bigEndianToShort(byte[] bs, int off); static byte[] shortToBytes(short n); static int numberOfLeadingZeros(byte[] bytes); static byte[] leftPadBytes(@Nonnull byte[] original, int newLength); static boolean fastEquals(byte[] left, byte[] right); static final byte[] EMPTY_BYTE_ARRAY; }
|
@Test public void getBalanceWithAccount() throws Exception { World world = new World(); Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(10000)).build(); Web3Impl web3 = createWeb3(world); org.junit.Assert.assertEquals("0x" + ByteUtil.toHexString(BigInteger.valueOf(10000).toByteArray()), web3.eth_getBalance(ByteUtil.toHexString(acc1.getAddress().getBytes()))); }
|
@Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); }
|
Web3Impl implements Web3 { @Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); } }
|
Web3Impl implements Web3 { @Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); }
|
Web3Impl implements Web3 { @Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); }
|
Web3Impl implements Web3 { @Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); public Ethereum eth; }
|
@Test public void testGetValueShortString1() { String expected = "123·(10^24)"; String result = Utils.getValueShortString(new BigInteger("123456789123445654363653463")); assertEquals(expected, result); }
|
public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void testGetValueShortString2() { String expected = "123·(10^3)"; String result = Utils.getValueShortString(new BigInteger("123456")); assertEquals(expected, result); }
|
public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void testGetValueShortString3() { String expected = "1·(10^3)"; String result = Utils.getValueShortString(new BigInteger("1234")); assertEquals(expected, result); }
|
public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void testGetValueShortString4() { String expected = "123·(10^0)"; String result = Utils.getValueShortString(new BigInteger("123")); assertEquals(expected, result); }
|
public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void testGetValueShortString5() { byte[] decimal = Hex.decode("3913517ebd3c0c65000000"); String expected = "69·(10^24)"; String result = Utils.getValueShortString(new BigInteger(decimal)); assertEquals(expected, result); }
|
public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static String getValueShortString(BigInteger number) { BigInteger result = number; int pow = 0; while (result.compareTo(_1000_) == 1 || result.compareTo(_1000_) == 0) { result = result.divide(_1000_); pow += 3; } return result.toString() + "·(" + "10^" + pow + ")"; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void testAddressStringToBytes() { String HexStr = "6c386a4b26f73c802f34673f7248bb118f97424a"; byte[] expected = Hex.decode(HexStr); byte[] result = Utils.addressStringToBytes(HexStr); assertEquals(Arrays.areEqual(expected, result), true); HexStr = "6c386a4b26f73c802f34673f7248bb118f97424"; expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); HexStr = new String(Hex.encode("I am longer than 20 bytes, i promise".getBytes())); expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); HexStr = new String(Hex.encode("I am short".getBytes())); expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); }
|
public static byte[] addressStringToBytes(String hex) { final byte[] addr; try { addr = Hex.decode(hex); } catch (DecoderException addressIsNotValid) { return null; } if (isValidAddress(addr)) { return addr; } return null; }
|
Utils { public static byte[] addressStringToBytes(String hex) { final byte[] addr; try { addr = Hex.decode(hex); } catch (DecoderException addressIsNotValid) { return null; } if (isValidAddress(addr)) { return addr; } return null; } }
|
Utils { public static byte[] addressStringToBytes(String hex) { final byte[] addr; try { addr = Hex.decode(hex); } catch (DecoderException addressIsNotValid) { return null; } if (isValidAddress(addr)) { return addr; } return null; } }
|
Utils { public static byte[] addressStringToBytes(String hex) { final byte[] addr; try { addr = Hex.decode(hex); } catch (DecoderException addressIsNotValid) { return null; } if (isValidAddress(addr)) { return addr; } return null; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static byte[] addressStringToBytes(String hex) { final byte[] addr; try { addr = Hex.decode(hex); } catch (DecoderException addressIsNotValid) { return null; } if (isValidAddress(addr)) { return addr; } return null; } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void TestValidateArrayWithOffset() { byte[] data = new byte[10]; Utils.validateArrayAllegedSize(data, 1, 0); Utils.validateArrayAllegedSize(data, 8, 1); Utils.validateArrayAllegedSize(data, 0, 10); Utils.validateArrayAllegedSize(data, 8, 2); Utils.validateArrayAllegedSize(data, 11, -1); Utils.validateArrayAllegedSize(data, -2, 12); try { Utils.validateArrayAllegedSize(data, 0, 11); fail("should have failed"); } catch (IllegalArgumentException e) { } try { Utils.validateArrayAllegedSize(data, 2, 9); fail("should have failed"); } catch (IllegalArgumentException e) { } try { Utils.validateArrayAllegedSize(new byte[0], 1, 0); fail("should have failed"); } catch (IllegalArgumentException e) { } byte[] noData = null; try { Utils.validateArrayAllegedSize(noData, 1, 1); fail("should have failed"); } catch (NullPointerException e) { } }
|
public static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize) { if (data.length < Math.addExact(allegedSize, offset)) { throw new IllegalArgumentException("The specified size exceeds the size of the payload"); } }
|
Utils { public static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize) { if (data.length < Math.addExact(allegedSize, offset)) { throw new IllegalArgumentException("The specified size exceeds the size of the payload"); } } }
|
Utils { public static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize) { if (data.length < Math.addExact(allegedSize, offset)) { throw new IllegalArgumentException("The specified size exceeds the size of the payload"); } } }
|
Utils { public static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize) { if (data.length < Math.addExact(allegedSize, offset)) { throw new IllegalArgumentException("The specified size exceeds the size of the payload"); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize) { if (data.length < Math.addExact(allegedSize, offset)) { throw new IllegalArgumentException("The specified size exceeds the size of the payload"); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void TestSafeCopyOfRangeWithValidArrays() { Utils.safeCopyOfRange(new byte[2], 0, 1); Utils.safeCopyOfRange(new byte[100], 97, 3); Utils.safeCopyOfRange(new byte[0], 0, 0); }
|
public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); }
|
Utils { public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); } }
|
Utils { public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); } }
|
Utils { public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void getBalanceWithAccountAndLatestBlock() throws Exception { World world = new World(); Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(10000)).build(); Web3Impl web3 = createWeb3(world); org.junit.Assert.assertEquals("0x" + ByteUtil.toHexString(BigInteger.valueOf(10000).toByteArray()), web3.eth_getBalance(ByteUtil.toHexString(acc1.getAddress().getBytes()), "latest")); }
|
@Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); }
|
Web3Impl implements Web3 { @Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); } }
|
Web3Impl implements Web3 { @Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); }
|
Web3Impl implements Web3 { @Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); }
|
Web3Impl implements Web3 { @Override public String eth_getBalance(String address, String block) { AccountInformationProvider accountInformationProvider = web3InformationRetriever.getInformationProvider(block); RskAddress addr = new RskAddress(address); Coin balance = accountInformationProvider.getBalance(addr); return toQuantityJsonHex(balance.asBigInteger()); } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); public Ethereum eth; }
|
@Test public void TestSafeCopyOfRangeWithInvalidArrays() { try { Utils.safeCopyOfRange(new byte[2], 1, 2); fail("should have failed"); } catch (IllegalArgumentException e){ } try { Utils.safeCopyOfRange(new byte[100], 98, 3); fail("should have failed"); } catch (IllegalArgumentException e){ } try { Utils.safeCopyOfRange(new byte[0], 0, 1); fail("should have failed"); } catch (IllegalArgumentException e){ } try { Utils.safeCopyOfRange(new byte[0], 1, 0); fail("should have failed"); } catch (IllegalArgumentException e){ } }
|
public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); }
|
Utils { public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); } }
|
Utils { public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); } }
|
Utils { public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static byte[] safeCopyOfRange(byte[] data, int from, int size) { validateArrayAllegedSize(data, from, size); return Arrays.copyOfRange(data, from, from + size); } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void isHexadecimalString() { String[] hexStrings = new String[] { "0x1", "0xaaa", "0xAAA", "0xAFe1", "0x10", "0xA12" }; java.util.Arrays.stream(hexStrings).forEach(s -> Assert.assertTrue(s, Utils.isHexadecimalString(s))); String[] nonHexStrings = new String[] { "hellothisisnotahex", "123", "AAA", "AFe1", "0xab123z", "0xnothing" }; java.util.Arrays.stream(nonHexStrings).forEach(s -> Assert.assertFalse(s, Utils.isHexadecimalString(s))); }
|
public static boolean isHexadecimalString(String s) { return s.matches("^0x[\\da-fA-F]+$"); }
|
Utils { public static boolean isHexadecimalString(String s) { return s.matches("^0x[\\da-fA-F]+$"); } }
|
Utils { public static boolean isHexadecimalString(String s) { return s.matches("^0x[\\da-fA-F]+$"); } }
|
Utils { public static boolean isHexadecimalString(String s) { return s.matches("^0x[\\da-fA-F]+$"); } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static boolean isHexadecimalString(String s) { return s.matches("^0x[\\da-fA-F]+$"); } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void isDecimalString() { String[] decStrings = new String[] { "1", "123", "045670", "220", "0", "01" }; java.util.Arrays.stream(decStrings).forEach(s -> Assert.assertTrue(s, Utils.isDecimalString(s))); String[] nonDecStrings = new String[] { "hellothisisnotadec", "123a", "0b", "b1", "AAA", "0xabcd", "0x123" }; java.util.Arrays.stream(nonDecStrings).forEach(s -> Assert.assertFalse(s, Utils.isDecimalString(s))); }
|
public static boolean isDecimalString(String s) { return s.matches("^\\d+$"); }
|
Utils { public static boolean isDecimalString(String s) { return s.matches("^\\d+$"); } }
|
Utils { public static boolean isDecimalString(String s) { return s.matches("^\\d+$"); } }
|
Utils { public static boolean isDecimalString(String s) { return s.matches("^\\d+$"); } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static boolean isDecimalString(String s) { return s.matches("^\\d+$"); } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void decimalStringToLong() { Object[] cases = new Object[] { "1", 1L, "123", 123L, "045670", 45670L, "220", 220L, "0", 0L, "01", 1L }; for (int i = 0; i < cases.length/2; i++) { String s = (String) cases[i*2]; long expected = (long) cases[i*2+1]; Assert.assertEquals(expected, Utils.decimalStringToLong(s)); } }
|
public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } }
|
Utils { public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } } }
|
Utils { public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } } }
|
Utils { public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test(expected = IllegalArgumentException.class) public void decimalStringToLongFail() { Utils.decimalStringToLong("zzz"); }
|
public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } }
|
Utils { public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } } }
|
Utils { public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } } }
|
Utils { public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static long decimalStringToLong(String s) { try { return Long.parseLong(s, 10); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid decimal number: %s", s), e); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test public void hexadecimalStringToLong() { Object[] cases = new Object[] { "0x1", 1L, "0xaaa", 2730L, "0xAAA", 2730L, "0xAFe1", 45025L, "0x10", 16L, "0xA12", 2578L }; for (int i = 0; i < cases.length/2; i++) { String s = (String) cases[i*2]; long expected = (long) cases[i*2+1]; Assert.assertEquals(expected, Utils.hexadecimalStringToLong(s)); } }
|
public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } }
|
Utils { public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } } }
|
Utils { public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } } }
|
Utils { public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
@Test(expected = IllegalArgumentException.class) public void hexadecimalStringToLongFail() { Utils.hexadecimalStringToLong("abcd"); }
|
public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } }
|
Utils { public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } } }
|
Utils { public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } } }
|
Utils { public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); }
|
Utils { public static long hexadecimalStringToLong(String s) { if (!s.startsWith("0x")) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s)); } try { return Long.parseLong(s.substring(2), 16); } catch (NumberFormatException e) { throw new IllegalArgumentException(String.format("Invalid hexadecimal number: %s", s), e); } } static BigInteger unifiedNumericToBigInteger(String number); static String longToDateTime(long timestamp); static String getValueShortString(BigInteger number); static byte[] addressStringToBytes(String hex); static boolean isValidAddress(byte[] addr); static String getAddressShortString(byte[] addr); static SecureRandom getRandom(); static String getHashListShort(List<byte[]> blockHashes); static long toUnixTime(long javaTime); static long fromUnixTime(long unixTime); static T[] mergeArrays(T[] ... arr); static String align(String s, char fillChar, int targetLen, boolean alignRight); static String repeat(String s, int n); static boolean contains(List<byte[]> list, byte[] valueToFind); static void validateArrayAllegedSize(byte[] data, int offset, int allegedSize); static byte[] safeCopyOfRange(byte[] data, int from, int size); static boolean isDecimalString(String s); static boolean isHexadecimalString(String s); static long decimalStringToLong(String s); static long hexadecimalStringToLong(String s); static int significantBitCount(int number); static final double JAVA_VERSION; }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.