Package software.amazon.eventstream
Class MessageDecoder
- java.lang.Object
-
- software.amazon.eventstream.MessageDecoder
-
public final class MessageDecoder extends Object
A simple decoder that accumulates chunks of bytes and emits eventstream messages. Instances of this class are not thread-safe.
-
-
Constructor Summary
Constructors Constructor Description MessageDecoder()Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfeed(byte[] bytes)voidfeed(byte[] bytes, int offset, int length)MessageDecoderfeed(ByteBuffer byteBuffer)Feed the contents of the givenByteBufferinto this decoder.List<Message>getDecodedMessages()ReturnsMessageinstances that have been decoded since this method was last invoked.
-
-
-
Constructor Detail
-
MessageDecoder
public MessageDecoder()
Creates aMessageDecoderinstance that will buffer messages internally as they are decoded. Decoded messages can be obtained by callinggetDecodedMessages().
-
MessageDecoder
public MessageDecoder(Consumer<Message> messageConsumer)
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 Detail
-
getDecodedMessages
public List<Message> 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
public MessageDecoder feed(ByteBuffer byteBuffer)
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
-
-