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,
boolean isClientNamespace)
Creates a
XMLStreamWriter instance, which writes XML without namespace prefixes. |
static String |
hash(byte[] bytes)
Creates a hex encoded SHA-1 hash.
|
public static XMLStreamWriter createXmppStreamWriter(XMLStreamWriter xmlStreamWriter, boolean isClientNamespace) throws XMLStreamException
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.valueOf("romeo@example.net"), Message.Type.CHAT, "Hi!!");
Message message = new Message(Jid.valueOf("juliet@example.net"));
message.getExtensions().add(new Sent(new Forwarded(forwardedMessage)));
marshaller.marshal(message, xmppStreamWriter);
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.isClientNamespace - True, if the content namespace is "jabber:client"; false, if it is "jabber:server".XMLStreamException - Thrown by XMLStreamWriter.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.Copyright © 2014–2015 XMPP.rocks. All rights reserved.