639640641642643644645646647648649
buf.clear(); assertEquals(0xdeadbeef, buf.getInt()); assertEquals(4, buf.position()); assertEquals(4, buf.limit()); buf.sweep((byte) 0x45); assertEquals(0, buf.position()); assertEquals(4, buf.limit()); assertEquals(0x45454545, buf.getInt()); }
144145146147148149150151152153154
public void testAutoShrink() throws Exception { IoBuffer buf = IoBuffer.allocate(8).setAutoShrink(true); // Make sure the buffer doesn't shrink too much (less than the initial // capacity.) buf.sweep((byte) 1); buf.fill(7); buf.compact(); assertEquals(8, buf.capacity()); assertEquals(1, buf.position()); assertEquals(8, buf.limit());
158159160161162163164165166167168
// Expand the buffer. buf.capacity(32).clear(); assertEquals(32, buf.capacity()); // Make sure the buffer shrinks when only 1/4 is being used. buf.sweep((byte) 1); buf.fill(24); buf.compact(); assertEquals(16, buf.capacity()); assertEquals(8, buf.position()); assertEquals(16, buf.limit());
174175176177178179180181182183184
// Expand the buffer. buf.capacity(32).clear(); assertEquals(32, buf.capacity()); // Make sure the buffer shrinks when only 1/8 is being used. buf.sweep((byte) 1); buf.fill(28); buf.compact(); assertEquals(8, buf.capacity()); assertEquals(4, buf.position()); assertEquals(8, buf.limit());
201202203204205206207208209210211
// Expand the buffer. buf.capacity(32).clear(); assertEquals(32, buf.capacity()); // Make sure the buffer doesn't shrink when more than 1/4 is being used. buf.sweep((byte) 1); buf.fill(23); buf.compact(); assertEquals(32, buf.capacity()); assertEquals(9, buf.position()); assertEquals(32, buf.limit());