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 aMessageDecoder
instance that will buffer messages internally as they are decoded.MessageDecoder(Consumer<Message> messageConsumer)
Creates aMessageDecoder
instance that will publish messages incrementally to the suppliedmessageConsumer
as they are decoded.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
feed(byte[] bytes)
void
feed(byte[] bytes, int offset, int length)
MessageDecoder
feed(ByteBuffer byteBuffer)
Feed the contents of the givenByteBuffer
into this decoder.List<Message>
getDecodedMessages()
ReturnsMessage
instances that have been decoded since this method was last invoked.
-
-
-
Constructor Detail
-
MessageDecoder
public MessageDecoder()
Creates aMessageDecoder
instance that will buffer messages internally as they are decoded. Decoded messages can be obtained by callinggetDecodedMessages()
.
-
MessageDecoder
public MessageDecoder(Consumer<Message> messageConsumer)
Creates aMessageDecoder
instance that will publish messages incrementally to the suppliedmessageConsumer
as 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 consumesMessage
instances
-
-
Method Detail
-
getDecodedMessages
public List<Message> getDecodedMessages()
ReturnsMessage
instances 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 givenByteBuffer
into this decoder. Messages will be incrementally decoded and buffered or published to the message consumer (depending on configuration).- Parameters:
byteBuffer
- aByteBuffer
whose entire contents will be read into the decoder's internal buffer- Returns:
- this
MessageDecoder
instance
-
-