@Test public void partialMessage() { encodeApplicationMessage(buffer, 0, messages[messageCount - 1]); buffer.limit(buffer.position() - 1); buffer.flip(); spliterator = new MessageLengthFrameSpliterator(buffer); assertFalse(spliterator.tryAdvance(new Consumer<ByteBuffer>() { public void accept(ByteBuffer message) { } })); }
@Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + MessageLengthFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } frameDecoder.wrap(buffer); frameDecoder.decodeFrameHeader(); final int messageLength = frameDecoder.getMessageLength(); int messageLimit = offset + MessageLengthFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); offset = messageLimit; buffer.position(messageLimit); return true; }
MessageLengthFrameSpliterator implements FrameSpliterator { @Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + MessageLengthFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } frameDecoder.wrap(buffer); frameDecoder.decodeFrameHeader(); final int messageLength = frameDecoder.getMessageLength(); int messageLimit = offset + MessageLengthFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); offset = messageLimit; buffer.position(messageLimit); return true; } }
MessageLengthFrameSpliterator implements FrameSpliterator { @Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + MessageLengthFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } frameDecoder.wrap(buffer); frameDecoder.decodeFrameHeader(); final int messageLength = frameDecoder.getMessageLength(); int messageLimit = offset + MessageLengthFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); offset = messageLimit; buffer.position(messageLimit); return true; } MessageLengthFrameSpliterator();  MessageLengthFrameSpliterator(ByteBuffer buffer); }
MessageLengthFrameSpliterator implements FrameSpliterator { @Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + MessageLengthFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } frameDecoder.wrap(buffer); frameDecoder.decodeFrameHeader(); final int messageLength = frameDecoder.getMessageLength(); int messageLimit = offset + MessageLengthFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); offset = messageLimit; buffer.position(messageLimit); return true; } MessageLengthFrameSpliterator();  MessageLengthFrameSpliterator(ByteBuffer buffer); @Override int characteristics(); @Override long estimateSize(); boolean hasRemaining(); @Override boolean tryAdvance(Consumer<? super ByteBuffer> action); @Override Spliterator<ByteBuffer> trySplit(); void wrap(ByteBuffer buffer); }
MessageLengthFrameSpliterator implements FrameSpliterator { @Override public boolean tryAdvance(Consumer<? super ByteBuffer> action) { Objects.requireNonNull(action); int messageOffset = offset + MessageLengthFrameDecoder.HEADER_LENGTH; if (messageOffset > buffer.limit()) { return false; } frameDecoder.wrap(buffer); frameDecoder.decodeFrameHeader(); final int messageLength = frameDecoder.getMessageLength(); int messageLimit = offset + MessageLengthFrameDecoder.HEADER_LENGTH + messageLength; if (messageLength <= 0 || (messageLimit > buffer.limit())) { return false; } ByteBuffer message = buffer.duplicate(); message.order(originalByteOrder); message.limit(messageLimit); action.accept(message); offset = messageLimit; buffer.position(messageLimit); return true; } MessageLengthFrameSpliterator();  MessageLengthFrameSpliterator(ByteBuffer buffer); @Override int characteristics(); @Override long estimateSize(); boolean hasRemaining(); @Override boolean tryAdvance(Consumer<? super ByteBuffer> action); @Override Spliterator<ByteBuffer> trySplit(); void wrap(ByteBuffer buffer);  }