@Test public void testGetUnsignedByte() throws Exception { int bytesLen = 100; byte[] bytes = TestUtils.randomByteArray(bytesLen); Buffer b = Buffer.buffer(bytes); for (int i = 0; i < bytesLen; i++) { assertEquals(Byte.toUnsignedLong(bytes[i]), b.getUnsignedByte(i)); } }
@Test public void testGetUnsignedByte() throws Exception { int bytesLen = 100; byte[] bytes = TestUtils.randomByteArray(bytesLen); Buffer b = Buffer.buffer(bytes); for (int i = 0; i < bytesLen; i++) { assertEquals(Byte.toUnsignedLong(bytes[i]), b.getUnsignedByte(i)); } }
@Override protected long decrement(int index) { if(counters[index] == 0) return 0; return Byte.toUnsignedLong(--counters[index]); }
@Override protected long count(int index) { return Byte.toUnsignedLong(counters[index]); }
@Override public final long longValue() { return Byte.toUnsignedLong(value); }
@Override public final long longValue() { return Byte.toUnsignedLong(value); }
@Override protected long increment(int index) { if(Byte.toUnsignedLong(counters[index]) == MAX) { overflowHandler.run(); return MAX; } return Byte.toUnsignedLong(++counters[index]); }
@Override public Map<Integer, Long> getCountMap() { Map<Integer, Long> result = new HashMap<>(); for (int i = 0; i < counters.length; i++) { long count = Byte.toUnsignedLong(counters[i]); if (count > 0) { result.put(i, count); } } return result; }
private void verifyCrc(ByteBuffer in) { long crcValue = 0; for (int i = 0; i < 4; ++i) { crcValue |= toUnsignedLong(in.get()) << i * 8; } long readCrc = crc.getValue(); if (crcValue != readCrc) { throw new RuntimeException("CRC value missmatch. Expected: " + crcValue + ", Got: " + readCrc); } }
byte b = (byte)255; int c = Byte.toUnsignedInt(b); // 255 long asLong = Byte.toUnsignedLong(b); // 255
@Override public long nextLong(long limit) { if (limit < 1) { throw new IllegalArgumentException("Limit must be strictly positive, but is: " + limit); } int bitSize = (Long.SIZE - Long.numberOfLeadingZeros(limit - 1)); byte[] bytes = getBytes(bitSize); long result = Byte.toUnsignedLong(bytes[0]); for (int i = 1; i < bytes.length; i++) { result <<= 8; result ^= Byte.toUnsignedLong(bytes[i]); } return result < limit ? result : nextLong(limit); }
@Override public long longValue(int index) {return Byte.toUnsignedLong (super.byteValue(index));} @Override public int intValue(int index) {return Byte.toUnsignedInt (super.byteValue(index));}
Assert.assertEquals(512L * 512L * 2L, (long) data.capacity()); for (int index = 0; index < data.capacity(); ++index) { Assert.assertEquals(0xffL, Byte.toUnsignedLong(data.get(index)));
public long readVarInt2(long max) throws IOException { long fb = Byte.toUnsignedLong(readByte()); long value; if (fb == ScriptOp.OP_PUSHDATA1.getByte()) { value = Byte.toUnsignedLong(readByte()); } else if (fb == ScriptOp.OP_PUSHDATA2.getByte()) { value = Short.toUnsignedLong(readShort()); } else if (fb == ScriptOp.OP_PUSHDATA4.getByte()) { value = Integer.toUnsignedLong(readInt()); } else{ value = fb; } if (Long.compareUnsigned(value, max) > 0) { throw new IOException(ErrorCode.ParamError); } return value; } public String readVarString() throws IOException {
public long readVarInt2(long max) throws IOException { long fb = Byte.toUnsignedLong(readByte()); long value; if (fb == ScriptOp.OP_PUSHDATA1.getByte()) { value = Byte.toUnsignedLong(readByte()); } else if (fb == ScriptOp.OP_PUSHDATA2.getByte()) { value = Short.toUnsignedLong(readShort()); } else if (fb == ScriptOp.OP_PUSHDATA4.getByte()) { value = Integer.toUnsignedLong(readInt()); } else{ value = fb; } if (Long.compareUnsigned(value, max) > 0) { throw new IOException(ErrorCode.ParamError); } return value; } public String readVarString() throws IOException {
Assert.assertEquals(512L * 512L * 3L, (long) data.capacity()); for (int index = 0; index < data.capacity(); ++index) { Assert.assertEquals(0xffL, Byte.toUnsignedLong(data.get(index)));
Assert.assertEquals(512L * 512L, (long) data.capacity()); for (int index = 0; index < data.capacity(); ++index) { Assert.assertEquals(0xffL, Byte.toUnsignedLong(data.get(index)));
public long readVarInt(long max) throws IOException { long fb = Byte.toUnsignedLong(readByte()); long value; if (fb == 0xFD) { value = Short.toUnsignedLong(readShort()); } else if (fb == 0xFE) { value = Integer.toUnsignedLong(readInt()); } else if (fb == 0xFF) { value = readLong(); } else { value = fb; } if (Long.compareUnsigned(value, max) > 0) { throw new IOException(); } return value; }
public long readVarInt(long max) throws IOException { long fb = Byte.toUnsignedLong(readByte()); long value; if (fb == 0xFD) { value = Short.toUnsignedLong(readShort()); } else if (fb == 0xFE) { value = Integer.toUnsignedLong(readInt()); } else if (fb == 0xFF) { value = readLong(); } else { value = fb; } if (Long.compareUnsigned(value, max) > 0) { throw new IOException(ErrorCode.ParamError); } return value; } public long readVarInt2(long max) throws IOException {
public long readVarInt(long max) throws IOException { long fb = Byte.toUnsignedLong(readByte()); long value; if (fb == 0xFD) { value = Short.toUnsignedLong(readShort()); } else if (fb == 0xFE) { value = Integer.toUnsignedLong(readInt()); } else if (fb == 0xFF) { value = readLong(); } else { value = fb; } if (Long.compareUnsigned(value, max) > 0) { throw new IOException(ErrorCode.ParamError); } return value; } public long readVarInt2(long max) throws IOException {