@Test public void testTryAdvance() { int offset = 0; for (int i = 0; i < messageCount; ++i) { offset += encodeApplicationMessage(buffer, offset, messages[i]); } buffer.flip(); spliterator = new SofhFrameSpliterator(buffer); count = 0; buffer.rewind(); while (spliterator.tryAdvance(new Consumer<ByteBuffer>() { public void accept(ByteBuffer message) { int messageLength = message.remaining(); assertEquals(count + 1, messageLength); count++; } })); assertEquals(messageCount, count); }
@Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + SofhFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } decoder.wrap(buffer); decoder.decodeFrameHeader(); final int messageLength = decoder.getMessageLength(); int messageLimit = offset + SofhFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); buffer.position(messageLimit); offset = messageLimit; buffer.order(originalByteOrder); return true; }
SofhFrameSpliterator implements FrameSpliterator { @Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + SofhFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } decoder.wrap(buffer); decoder.decodeFrameHeader(); final int messageLength = decoder.getMessageLength(); int messageLimit = offset + SofhFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); buffer.position(messageLimit); offset = messageLimit; buffer.order(originalByteOrder); return true; } }
SofhFrameSpliterator implements FrameSpliterator { @Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + SofhFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } decoder.wrap(buffer); decoder.decodeFrameHeader(); final int messageLength = decoder.getMessageLength(); int messageLimit = offset + SofhFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); buffer.position(messageLimit); offset = messageLimit; buffer.order(originalByteOrder); return true; } SofhFrameSpliterator();  SofhFrameSpliterator(ByteBuffer buffer); }
SofhFrameSpliterator implements FrameSpliterator { @Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + SofhFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } decoder.wrap(buffer); decoder.decodeFrameHeader(); final int messageLength = decoder.getMessageLength(); int messageLimit = offset + SofhFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); buffer.position(messageLimit); offset = messageLimit; buffer.order(originalByteOrder); return true; } SofhFrameSpliterator();  SofhFrameSpliterator(ByteBuffer buffer); @Override int characteristics(); @Override long estimateSize(); @Override boolean hasRemaining(); @Override boolean tryAdvance(Consumer<? super ByteBuffer> action); @Override Spliterator<ByteBuffer> trySplit(); @Override void wrap(ByteBuffer buffer); }
SofhFrameSpliterator implements FrameSpliterator { @Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + SofhFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } decoder.wrap(buffer); decoder.decodeFrameHeader(); final int messageLength = decoder.getMessageLength(); int messageLimit = offset + SofhFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); buffer.position(messageLimit); offset = messageLimit; buffer.order(originalByteOrder); return true; } SofhFrameSpliterator();  SofhFrameSpliterator(ByteBuffer buffer); @Override int characteristics(); @Override long estimateSize(); @Override boolean hasRemaining(); @Override boolean tryAdvance(Consumer<? super ByteBuffer> action); @Override Spliterator<ByteBuffer> trySplit(); @Override void wrap(ByteBuffer buffer);  }