Skip to main content

compression of message

2 replies [Last post]
Joined: 2007-08-10

Hi all,

Anyone knows how to compress the message. i mean the whole message which includes not only my load but also jxta router information. There are too high overhead in transmission
And,another question is how to transmit message in binary mode?
Thanks in advance.

Message was edited by: benus_ying

Message was edited by: benus_ying

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2007-01-31

Ariel's example is how SRDI messages are compressed before exchange, too. Regarding route information, it cannot be compressed at this stage, though this is a going concern in the community.

The JXTA protocols define a binary format v2, but it has not been implemented yet. See

Joined: 2009-12-28


I don't know exactly if this is what you are after but, according to the code examples taken from jxse tutorials 2.5 here is a method that pretty much does it:

* Adds an byte array to a message
* @param message The message to add to
* @param nameSpace The namespace of the element to add. a null value assumes default namespace.
* @param elemName Name of the Element.
* @param data the byte array
* @param compress indicates whether to use GZIP compression
* @throws IOException if an io error occurs
public static void addByteArrayToMessage(Message message, String nameSpace, String elemName, byte[] data, boolean compress) throws IOException {
byte[] buffer = data;
MimeMediaType mimeType = MimeMediaType.AOS;

if (compress) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
GZIPOutputStream gos = new GZIPOutputStream(outStream);

gos.write(data, 0, data.length);
buffer = outStream.toByteArray();
message.addMessageElement(nameSpace, new ByteArrayMessageElement(elemName, mimeType, buffer, null));

Hope it helps!