Package rocks.xmpp.nio.codec
Class XmppStreamDecoder
- java.lang.Object
-
- rocks.xmpp.nio.codec.XmppStreamDecoder
-
- All Implemented Interfaces:
ReaderInterceptor
public final class XmppStreamDecoder extends Object implements ReaderInterceptor
Decodes a stream of byte buffers to XMPP elements.Decoding is thread-safe, as long as the supplied
Unmarshalleris not shared by another thread, e.g. if a thread-localUnmarshalleris 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 Summary
Constructors Constructor Description XmppStreamDecoder(Function<Locale,javax.xml.bind.Unmarshaller> unmarshaller)Creates the XMPP decoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddecode(ByteBuffer in, BiConsumer<String,StreamElement> out)Decodes a stream of byte buffers to XMPP elements.voidprocess(Reader reader, Consumer<StreamElement> streamElementListener, ReaderInterceptorChain chain)Processesvoidrestart()Restarts the stream, i.e. a new reader will be created.
-
-
-
Constructor Detail
-
XmppStreamDecoder
public XmppStreamDecoder(Function<Locale,javax.xml.bind.Unmarshaller> unmarshaller)
Creates the XMPP decoder.Because
Unmarshalleris not thread-safe, it is recommended to pass aThreadLocal<Unmarshaller>to this constructor, which ensures thread-safety during unmarshalling.- Parameters:
unmarshaller- Supplies the unmarshaller which will convert XML to objects.
-
-
Method Detail
-
decode
public final void decode(ByteBuffer in, BiConsumer<String,StreamElement> out) throws StreamErrorException
Decodes a stream of byte buffers to XMPP elements.- Parameters:
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.- Throws:
StreamErrorException- If parsing XML fails or any other stream error occurred (e.g. invalid XML).
-
restart
public final void restart()
Restarts the stream, i.e. a new reader will be created.
-
process
public final void process(Reader reader, Consumer<StreamElement> streamElementListener, ReaderInterceptorChain chain) throws Exception
Description copied from interface:ReaderInterceptorProcesses- Specified by:
processin interfaceReaderInterceptor- Parameters:
reader- The reader from which the stream is read.streamElementListener- Listens for stream elements being read from the reader.chain- The reader chain, which allows to proceed to the next interceptor.- Throws:
Exception- Any exception happening during interception.
-
-