Class MessageDecoder
java.lang.Object
software.amazon.awssdk.eventstream.MessageDecoder
A simple decoder that accumulates chunks of bytes and emits eventstream
messages. Instances of this class are not thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates aMessageDecoderinstance that will buffer messages internally as they are decoded.MessageDecoder(Consumer<Message> messageConsumer) Creates aMessageDecoderinstance that will publish messages incrementally to the suppliedmessageConsumeras they are decoded. -
Method Summary
Modifier and TypeMethodDescriptionvoidfeed(byte[] bytes) voidfeed(byte[] bytes, int offset, int length) feed(ByteBuffer byteBuffer) Feed the contents of the givenByteBufferinto this decoder.ReturnsMessageinstances that have been decoded since this method was last invoked.
-
Constructor Details
-
MessageDecoder
public MessageDecoder()Creates aMessageDecoderinstance that will buffer messages internally as they are decoded. Decoded messages can be obtained by callinggetDecodedMessages(). -
MessageDecoder
Creates aMessageDecoderinstance that will publish messages incrementally to the suppliedmessageConsumeras they are decoded. The resulting instance does not support thegetDecodedMessages()operation, and will throw an exception if it is invoked.- Parameters:
messageConsumer- a function that consumesMessageinstances
-
-
Method Details
-
getDecodedMessages
ReturnsMessageinstances that have been decoded since this method was last invoked. Note that this method is only supported if this decoder was not configured to use a custom message consumer.- Returns:
- all messages decoded since the last invocation of this method
-
feed
public void feed(byte[] bytes) -
feed
public void feed(byte[] bytes, int offset, int length) -
feed
Feed the contents of the givenByteBufferinto this decoder. Messages will be incrementally decoded and buffered or published to the message consumer (depending on configuration).- Parameters:
byteBuffer- aByteBufferwhose entire contents will be read into the decoder's internal buffer- Returns:
- this
MessageDecoderinstance
-