Class 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 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 Detail

      • XmppStreamDecoder

        public XmppStreamDecoder​(Function<Locale,​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.

        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: ReaderInterceptor
        Processes
        Specified by:
        process in interface ReaderInterceptor
        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.