* @param privateData the private data.
* @throws XMPPException if setting the private data fails.
*/
public void setPrivateData(final PrivateData privateData) throws XMPPException {
// Create an IQ packet to set the private data.
IQ privateDataSet = new IQ() {
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<query xmlns=\"jabber:iq:private\">");
buf.append(privateData.toXML());
buf.append("</query>");
return buf.toString();
}
};
privateDataSet.setType(IQ.Type.SET);
// Address the packet to the other account if user has been set.
if (user != null) {
privateDataSet.setTo(user);
}
// Setup a listener for the reply to the set operation.
String packetID = privateDataSet.getPacketID();
PacketCollector collector = connection.createPacketCollector(new PacketIDFilter(packetID));
// Send the private data.
connection.sendPacket(privateDataSet);
// Wait up to five seconds for a response from the server.
IQ response = (IQ)collector.nextResult(5000);
// Stop queuing results
collector.cancel();
if (response == null) {
throw new XMPPException("No response from the server.");
}
// If the server replied with an error, throw an exception.
else if (response.getType() == IQ.Type.ERROR) {
throw new XMPPException(response.getError());
}
}