@Test public void testRepeatitiveDecode() throws Exception { for (int i = 0; i < 4; i++) { buf.putInt(i); } buf.flip(); decoder.decode(session, buf, session.getDecoderOutput()); assertEquals(4, session.getDecoderOutputQueue().size()); assertEquals(buf.limit(), buf.position()); List<Object> expected = new ArrayList<>(); for (int i = 0; i < 4; i++) { expected.add(i); } assertEquals(expected, session.getDecoderOutputQueue()); }
public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { if (!session.getTransportMetadata().hasFragmentation()) { while (in.hasRemaining()) { if (!doDecode(session, in, out)) { break; } } return; } boolean usingSessionBuffer = true; IoBuffer buf = (IoBuffer) session.getAttribute(BUFFER); if (buf != null) { boolean appended = false; if (buf.isAutoExpand()) { try { buf.put(in); appended = true; } catch (IllegalStateException e) { } catch (IndexOutOfBoundsException e) { } } if (appended) { buf.flip(); } else { buf.flip(); IoBuffer newBuf = IoBuffer.allocate( buf.remaining() + in.remaining()).setAutoExpand(true); newBuf.order(buf.order()); newBuf.put(buf); newBuf.put(in); newBuf.flip(); buf = newBuf; session.setAttribute(BUFFER, buf); } } else { buf = in; usingSessionBuffer = false; } for (;;) { int oldPos = buf.position(); boolean decoded = doDecode(session, buf, out); if (decoded) { if (buf.position() == oldPos) { throw new IllegalStateException( "doDecode() can't return true when buffer is not consumed."); } if (!buf.hasRemaining()) { break; } } else { break; } } if (buf.hasRemaining()) { if (usingSessionBuffer && buf.isAutoExpand()) { buf.compact(); } else { storeRemainingInSession(buf, session); } } else { if (usingSessionBuffer) { removeSessionBuffer(session); } } }
CumulativeProtocolDecoder extends ProtocolDecoderAdapter { public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { if (!session.getTransportMetadata().hasFragmentation()) { while (in.hasRemaining()) { if (!doDecode(session, in, out)) { break; } } return; } boolean usingSessionBuffer = true; IoBuffer buf = (IoBuffer) session.getAttribute(BUFFER); if (buf != null) { boolean appended = false; if (buf.isAutoExpand()) { try { buf.put(in); appended = true; } catch (IllegalStateException e) { } catch (IndexOutOfBoundsException e) { } } if (appended) { buf.flip(); } else { buf.flip(); IoBuffer newBuf = IoBuffer.allocate( buf.remaining() + in.remaining()).setAutoExpand(true); newBuf.order(buf.order()); newBuf.put(buf); newBuf.put(in); newBuf.flip(); buf = newBuf; session.setAttribute(BUFFER, buf); } } else { buf = in; usingSessionBuffer = false; } for (;;) { int oldPos = buf.position(); boolean decoded = doDecode(session, buf, out); if (decoded) { if (buf.position() == oldPos) { throw new IllegalStateException( "doDecode() can't return true when buffer is not consumed."); } if (!buf.hasRemaining()) { break; } } else { break; } } if (buf.hasRemaining()) { if (usingSessionBuffer && buf.isAutoExpand()) { buf.compact(); } else { storeRemainingInSession(buf, session); } } else { if (usingSessionBuffer) { removeSessionBuffer(session); } } } }
CumulativeProtocolDecoder extends ProtocolDecoderAdapter { public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { if (!session.getTransportMetadata().hasFragmentation()) { while (in.hasRemaining()) { if (!doDecode(session, in, out)) { break; } } return; } boolean usingSessionBuffer = true; IoBuffer buf = (IoBuffer) session.getAttribute(BUFFER); if (buf != null) { boolean appended = false; if (buf.isAutoExpand()) { try { buf.put(in); appended = true; } catch (IllegalStateException e) { } catch (IndexOutOfBoundsException e) { } } if (appended) { buf.flip(); } else { buf.flip(); IoBuffer newBuf = IoBuffer.allocate( buf.remaining() + in.remaining()).setAutoExpand(true); newBuf.order(buf.order()); newBuf.put(buf); newBuf.put(in); newBuf.flip(); buf = newBuf; session.setAttribute(BUFFER, buf); } } else { buf = in; usingSessionBuffer = false; } for (;;) { int oldPos = buf.position(); boolean decoded = doDecode(session, buf, out); if (decoded) { if (buf.position() == oldPos) { throw new IllegalStateException( "doDecode() can't return true when buffer is not consumed."); } if (!buf.hasRemaining()) { break; } } else { break; } } if (buf.hasRemaining()) { if (usingSessionBuffer && buf.isAutoExpand()) { buf.compact(); } else { storeRemainingInSession(buf, session); } } else { if (usingSessionBuffer) { removeSessionBuffer(session); } } } protected  CumulativeProtocolDecoder(); }
CumulativeProtocolDecoder extends ProtocolDecoderAdapter { public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { if (!session.getTransportMetadata().hasFragmentation()) { while (in.hasRemaining()) { if (!doDecode(session, in, out)) { break; } } return; } boolean usingSessionBuffer = true; IoBuffer buf = (IoBuffer) session.getAttribute(BUFFER); if (buf != null) { boolean appended = false; if (buf.isAutoExpand()) { try { buf.put(in); appended = true; } catch (IllegalStateException e) { } catch (IndexOutOfBoundsException e) { } } if (appended) { buf.flip(); } else { buf.flip(); IoBuffer newBuf = IoBuffer.allocate( buf.remaining() + in.remaining()).setAutoExpand(true); newBuf.order(buf.order()); newBuf.put(buf); newBuf.put(in); newBuf.flip(); buf = newBuf; session.setAttribute(BUFFER, buf); } } else { buf = in; usingSessionBuffer = false; } for (;;) { int oldPos = buf.position(); boolean decoded = doDecode(session, buf, out); if (decoded) { if (buf.position() == oldPos) { throw new IllegalStateException( "doDecode() can't return true when buffer is not consumed."); } if (!buf.hasRemaining()) { break; } } else { break; } } if (buf.hasRemaining()) { if (usingSessionBuffer && buf.isAutoExpand()) { buf.compact(); } else { storeRemainingInSession(buf, session); } } else { if (usingSessionBuffer) { removeSessionBuffer(session); } } } protected  CumulativeProtocolDecoder(); void decode(IoSession session, IoBuffer in,
            ProtocolDecoderOutput out); @Override void dispose(IoSession session); }
CumulativeProtocolDecoder extends ProtocolDecoderAdapter { public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception { if (!session.getTransportMetadata().hasFragmentation()) { while (in.hasRemaining()) { if (!doDecode(session, in, out)) { break; } } return; } boolean usingSessionBuffer = true; IoBuffer buf = (IoBuffer) session.getAttribute(BUFFER); if (buf != null) { boolean appended = false; if (buf.isAutoExpand()) { try { buf.put(in); appended = true; } catch (IllegalStateException e) { } catch (IndexOutOfBoundsException e) { } } if (appended) { buf.flip(); } else { buf.flip(); IoBuffer newBuf = IoBuffer.allocate( buf.remaining() + in.remaining()).setAutoExpand(true); newBuf.order(buf.order()); newBuf.put(buf); newBuf.put(in); newBuf.flip(); buf = newBuf; session.setAttribute(BUFFER, buf); } } else { buf = in; usingSessionBuffer = false; } for (;;) { int oldPos = buf.position(); boolean decoded = doDecode(session, buf, out); if (decoded) { if (buf.position() == oldPos) { throw new IllegalStateException( "doDecode() can't return true when buffer is not consumed."); } if (!buf.hasRemaining()) { break; } } else { break; } } if (buf.hasRemaining()) { if (usingSessionBuffer && buf.isAutoExpand()) { buf.compact(); } else { storeRemainingInSession(buf, session); } } else { if (usingSessionBuffer) { removeSessionBuffer(session); } } } protected  CumulativeProtocolDecoder(); void decode(IoSession session, IoBuffer in,
            ProtocolDecoderOutput out); @Override void dispose(IoSession session);  }