@Test public void shouldExpandCapacityOfUInt64(){ BigInteger bigUint64 = BigInteger.valueOf(Long.MAX_VALUE); PlainBuffer buf = new PlainBuffer(); assertEquals(Buffer.DEFAULT_SIZE,buf.data.length); for(int i=0;i<Buffer.DEFAULT_SIZE+1;i+=8) { buf.putUInt64(bigUint64.longValue()); } /* Buffer should have been expanded at this point*/ assertEquals(Buffer.DEFAULT_SIZE*2,buf.data.length); }
public byte[] toBytes() { Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); buf.putUInt32(mask); if (has(Flag.SIZE)) buf.putUInt64(size); if (has(Flag.UIDGID)) { buf.putUInt32(uid); buf.putUInt32(gid); } if (has(Flag.MODE)) buf.putUInt32(mode.getMask()); if (has(Flag.ACMODTIME)) { buf.putUInt32(atime); buf.putUInt32(mtime); } if (has(Flag.EXTENDED)) { buf.putUInt32(ext.size()); for (Entry<String, String> entry : ext.entrySet()) { buf.putString(entry.getKey()); buf.putString(entry.getValue()); } } return buf.getCompactData(); }
@Test public void shouldHaveCorrectValueForMaxUInt64() { byte[] maxUInt64InBytes = new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF }; BigInteger maxUInt64 = new BigInteger(1, maxUInt64InBytes); new PlainBuffer().putUInt64(maxUInt64); // no exception BigInteger tooBig = maxUInt64.add(BigInteger.ONE); try { new PlainBuffer().putUInt64(tooBig); fail("Added 2^64 (too big) as uint64 to buffer?"); } catch (IllegalArgumentException e) { // success } }
public byte[] toBytes() { Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); buf.putUInt32(mask); if (has(Flag.SIZE)) buf.putUInt64(size); if (has(Flag.UIDGID)) { buf.putUInt32(uid); buf.putUInt32(gid); } if (has(Flag.MODE)) buf.putUInt32(mode.getMask()); if (has(Flag.ACMODTIME)) { buf.putUInt32(atime); buf.putUInt32(mtime); } if (has(Flag.EXTENDED)) { buf.putUInt32(ext.size()); for (Entry<String, String> entry : ext.entrySet()) { buf.putString(entry.getKey()); buf.putString(entry.getValue()); } } return buf.getCompactData(); }
public byte[] toBytes() { Buffer.PlainBuffer buf = new Buffer.PlainBuffer(); buf.putUInt32(mask); if (has(Flag.SIZE)) buf.putUInt64(size); if (has(Flag.UIDGID)) { buf.putUInt32(uid); buf.putUInt32(gid); } if (has(Flag.MODE)) buf.putUInt32(mode.getMask()); if (has(Flag.ACMODTIME)) { buf.putUInt32(atime); buf.putUInt32(mtime); } if (has(Flag.EXTENDED)) { buf.putUInt32(ext.size()); for (Entry<String, String> entry : ext.entrySet()) { buf.putString(entry.getKey()); buf.putString(entry.getValue()); } } return buf.getCompactData(); }
@Test public void shouldThrowOnPutNegativeLongUInt64() { try { new PlainBuffer().putUInt64(-1l); fail("Added negative uint64 to buffer?"); } catch (IllegalArgumentException e) { // success } }
@Test public void shouldHaveSameUInt64EncodingForBigIntegerAndLong() { long[] values = { 0l, 1l, 232634978082517765l, Long.MAX_VALUE - 1, Long.MAX_VALUE }; for (long value : values) { byte[] bytesBigInt = new PlainBuffer().putUInt64(BigInteger.valueOf(value)).getCompactData(); byte[] bytesLong = new PlainBuffer().putUInt64(value).getCompactData(); assertArrayEquals("Value: " + value, bytesLong, bytesBigInt); } }
@Test public void shouldThrowOnPutNegativeBigIntegerUInt64() { try { new PlainBuffer().putUInt64(new BigInteger("-1")); fail("Added negative uint64 to buffer?"); } catch (IllegalArgumentException e) { // success } }