272273274275276277278279280281282
buf.limit(buf.limit() - matchCount); try { writeText(session, buf.getString(ctx.getDecoder()), out); } finally { buf.clear(); } } else { int overflowPosition = ctx.getOverflowPosition(); ctx.reset(); throw new RecoverableProtocolDecoderException(
329330331332333334335336337338339
8687888990919293949596
IoBuffer data = IoBuffer.allocate(1); for (byte i = 0; i < 20; i++) { data.put((byte) (0x30 + i)); data.flip(); sess.write(data); data.clear(); } // Add one more byte to overflow the final buffer data.put((byte) 0); data.flip();
153154155156157158159160161162163
buf.fill(7); buf.compact(); assertEquals(8, buf.capacity()); assertEquals(1, buf.position()); assertEquals(8, buf.limit()); buf.clear(); assertEquals(1, buf.get()); // Expand the buffer. buf.capacity(32).clear(); assertEquals(32, buf.capacity());
167168169170171172173174175176177
buf.fill(24); buf.compact(); assertEquals(16, buf.capacity()); assertEquals(8, buf.position()); assertEquals(16, buf.limit()); buf.clear(); for (int i = 0; i < 8; i ++) { assertEquals(1, buf.get()); } // Expand the buffer.
183184185186187188189190191192193
buf.fill(28); buf.compact(); assertEquals(8, buf.capacity()); assertEquals(4, buf.position()); assertEquals(8, buf.limit()); buf.clear(); for (int i = 0; i < 4; i ++) { assertEquals(1, buf.get()); } // Expand the buffer.
210211212213214215216217218219220
buf.fill(23); buf.compact(); assertEquals(32, buf.capacity()); assertEquals(9, buf.position()); assertEquals(32, buf.limit()); buf.clear(); for (int i = 0; i < 9; i ++) { assertEquals(1, buf.get()); } }
222223224225226227228229230231232
public void testGetString() throws Exception { IoBuffer buf = IoBuffer.allocate(16); CharsetDecoder decoder; Charset charset = Charset.forName("UTF-8"); buf.clear(); buf.putString("hello", charset.newEncoder()); buf.put((byte) 0); buf.flip(); assertEquals("hello", buf.getString(charset.newDecoder()));
228229230231232233234235236237238
buf.putString("hello", charset.newEncoder()); buf.put((byte) 0); buf.flip(); assertEquals("hello", buf.getString(charset.newDecoder())); buf.clear(); buf.putString("hello", charset.newEncoder()); buf.flip(); assertEquals("hello", buf.getString(charset.newDecoder())); decoder = Charset.forName("ISO-8859-1").newDecoder();
234235236237238239240241242243244
buf.putString("hello", charset.newEncoder()); buf.flip(); assertEquals("hello", buf.getString(charset.newDecoder())); decoder = Charset.forName("ISO-8859-1").newDecoder(); buf.clear(); buf.put((byte) 'A'); buf.put((byte) 'B'); buf.put((byte) 'C'); buf.put((byte) 0);