public final class XmppStreamDecoder
extends java.lang.Object
Decodes a stream of byte buffers to XMPP elements.
Decoding is thread-safe, as long as the supplied Unmarshaller
is not shared by another thread, e.g. if a thread-local Unmarshaller
is supplied.
Stream restarts can be achieved by using the restart()
methods. Decoding and restarts are thread-safe, i.e. can be called by different threads.
Constructor and Description |
---|
XmppStreamDecoder(java.util.function.Supplier<javax.xml.bind.Unmarshaller> unmarshaller)
Creates the XMPP decoder.
|
Modifier and Type | Method and Description |
---|---|
void |
decode(java.nio.ByteBuffer in,
java.util.function.BiConsumer<java.lang.String,StreamElement> out)
Decodes a stream of byte buffers to XMPP elements.
|
void |
restart()
Restarts the stream, i.e. a new reader will be created.
|
public XmppStreamDecoder(java.util.function.Supplier<javax.xml.bind.Unmarshaller> unmarshaller)
Creates the XMPP decoder.
Because Unmarshaller
is not thread-safe, it is recommended to pass a ThreadLocal<Unmarshaller>
to this constructor, which ensures thread-safety during unmarshalling.
unmarshaller
- Supplies the unmarshaller which will convert XML to objects.public final void decode(java.nio.ByteBuffer in, java.util.function.BiConsumer<java.lang.String,StreamElement> out) throws StreamErrorException
Decodes a stream of byte buffers to XMPP elements.
in
- The byte buffer which was read from the channel. It must be ready to read, i.e. flipped.out
- Consumes any decoded elements as string and as unmarshalled object.StreamErrorException
- If parsing XML fails or any other stream error occurred (e.g. invalid XML).public final void restart()
Restarts the stream, i.e. a new reader will be created.
Copyright © 2014–2019 XMPP.rocks. All rights reserved.