public final class XmppStreamEncoder
extends java.lang.Object
Encodes XMPP elements to binary data. This class is capable to encode elements to either an OutputStream or to a ByteBuffer.
Encoding is thread-safe, as long as the supplied Marshaller is not shared by another thread, e.g. if a thread-local Marshaller is supplied.
| Constructor and Description |
|---|
XmppStreamEncoder(javax.xml.stream.XMLOutputFactory outputFactory,
java.util.function.Supplier<javax.xml.bind.Marshaller> marshaller,
java.util.function.Function<StreamElement,StreamElement> stanzaMapper)
Creates the XMPP encoder.
|
| Modifier and Type | Method and Description |
|---|---|
java.nio.ByteBuffer |
encode(StreamElement streamElement)
Encodes an XMPP element to a byte buffer.
|
void |
encode(StreamElement streamElement,
java.io.OutputStream outputStream)
Encodes an XMPP element to an
OutputStream. |
public XmppStreamEncoder(javax.xml.stream.XMLOutputFactory outputFactory,
java.util.function.Supplier<javax.xml.bind.Marshaller> marshaller,
java.util.function.Function<StreamElement,StreamElement> stanzaMapper)
Creates the XMPP encoder.
Because Marshaller is not thread-safe, it is recommended to pass a ThreadLocal<Marshaller> to this constructor, which ensures thread-safety during marshalling.
outputFactory - The XML output factory.marshaller - Supplies the marshaller which will convert objects to XML.stanzaMapper - Maps stanzas to a specific type, which is required for correct marshalling.public final java.nio.ByteBuffer encode(StreamElement streamElement) throws StreamErrorException
Encodes an XMPP element to a byte buffer. The returned ByteBuffer is ready to be read, i.e. its position is 0.
streamElement - The stream element.StreamErrorException - If the element could not be marshalled.public final void encode(StreamElement streamElement, java.io.OutputStream outputStream) throws StreamErrorException
Encodes an XMPP element to an OutputStream.
streamElement - The stream element.outputStream - The output stream to write to.StreamErrorException - If the element could not be marshalled.Copyright © 2014–2019 XMPP.rocks. All rights reserved.