public final class XmppUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static InputStream |
createBranchedInputStream(InputStream source,
OutputStream target)
Creates an branched
InputStream, which means that everything read by the source stream is written to the target OutputStream. |
static OutputStream |
createBranchedOutputStream(OutputStream out,
OutputStream branch)
Creates a branched
OutputStream, which means that everything written to the original stream is also written to the branched stream. |
static ThreadFactory |
createNamedThreadFactory(String threadName)
Creates a thread factory which creates named daemon threads.
|
static XMLStreamWriter |
createXmppStreamWriter(XMLStreamWriter xmlStreamWriter)
Creates a
XMLStreamWriter instance, which writes XML without namespace prefixes. |
static XMLStreamWriter |
createXmppStreamWriter(XMLStreamWriter xmlStreamWriter,
String contentNamespace)
Creates a
XMLStreamWriter instance, which writes XML without namespace prefixes. |
static XMLStreamWriter |
createXmppStreamWriter(XMLStreamWriter xmlStreamWriter,
String contentNamespace,
boolean writeStreamNamepace)
Creates a
XMLStreamWriter instance, which writes XML without namespace prefixes. |
static String |
hash(byte[] bytes)
Creates a hex encoded SHA-1 hash.
|
static <T extends EventObject> |
notifyEventListeners(Iterable<Consumer<T>> eventListeners,
T e)
Invokes listeners in a fail-safe way.
|
public static XMLStreamWriter createXmppStreamWriter(XMLStreamWriter xmlStreamWriter, String contentNamespace, boolean writeStreamNamepace)
XMLStreamWriter instance, which writes XML without namespace prefixes.
Sample usage:
Writer writer = new StringWriter();
XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newFactory().createXMLStreamWriter(writer);
XMLStreamWriter xmppStreamWriter = XmppUtils.createXmppStreamWriter(xmlStreamWriter, true);
JAXBContext jaxbContext = JAXBContext.newInstance(Message.class, Sent.class);
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
Message forwardedMessage = new Message(Jid.of("romeo@example.net"), Message.Type.CHAT, "Hi!!");
Message message = new Message(Jid.of("juliet@example.net"));
message.addExtension(new Sent(new Forwarded(forwardedMessage)));
marshaller.marshal(message, xmppStreamWriter);
xmppStreamWriter.flush();
System.out.println(writer.toString());
The output of this is:
<message to="juliet@example.net">
<sent xmlns="urn:xmpp:carbons:2">
<forwarded xmlns="urn:xmpp:forward:0">
<message xmlns="jabber:client" to="romeo@example.net" type="chat">
<body>Hi!!</body>
</message>
</forwarded>
</sent>
</message>
xmlStreamWriter - The underlying XML stream writer.contentNamespace - The content namspace, e.g. "jabber:client".writeStreamNamepace - If the stream namespace ('http://etherx.jabber.org/streams') should be written to the root element. This is usually only the case when writing the initial BOSH response with stream features.public static XMLStreamWriter createXmppStreamWriter(XMLStreamWriter xmlStreamWriter, String contentNamespace)
XMLStreamWriter instance, which writes XML without namespace prefixes.xmlStreamWriter - The underlying XML stream writer.contentNamespace - The content namspace, e.g. "jabber:client".createXmppStreamWriter(XMLStreamWriter, String, boolean)public static XMLStreamWriter createXmppStreamWriter(XMLStreamWriter xmlStreamWriter)
XMLStreamWriter instance, which writes XML without namespace prefixes.
The content namespace is "jabber:client".
xmlStreamWriter - The underlying XML stream writer.createXmppStreamWriter(XMLStreamWriter, String, boolean)public static InputStream createBranchedInputStream(InputStream source, OutputStream target)
InputStream, which means that everything read by the source stream is written to the target OutputStream.
This is useful for reading the XMPP stream and writing the inbound XMPP traffic to an OutputStream.
source - The source stream.target - The target stream.public static OutputStream createBranchedOutputStream(OutputStream out, OutputStream branch)
OutputStream, which means that everything written to the original stream is also written to the branched stream.
This is useful for writing the outbound XMPP traffic to another stream.
out - The original stream.branch - The branched stream.public static String hash(byte[] bytes)
bytes - The data.public static ThreadFactory createNamedThreadFactory(String threadName)
threadName - The thread name.public static <T extends EventObject> void notifyEventListeners(Iterable<Consumer<T>> eventListeners, T e)
T - The event object type.eventListeners - The event listeners.e - The event object.Copyright © 2014–2016 XMPP.rocks. All rights reserved.