mqttTopicMap.put(message.getJMSDestination(), topicName);
}
}
result.topicName(topicName);
ByteSequence byteSequence = message.getContent();
if (message.isCompressed()) {
Inflater inflater = new Inflater();
inflater.setInput(byteSequence.data, byteSequence.offset, byteSequence.length);
byte[] data = new byte[4096];
int read;
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
while ((read = inflater.inflate(data, 0, data.length)) != 0) {
bytesOut.write(data, 0, read);
}
byteSequence = bytesOut.toByteSequence();
}
if (message.getDataStructureType() == ActiveMQTextMessage.DATA_STRUCTURE_TYPE) {
if (byteSequence.getLength() > 4) {
byte[] content = new byte[byteSequence.getLength() - 4];
System.arraycopy(byteSequence.data, 4, content, 0, content.length);
result.payload(new Buffer(content));
} else {
ActiveMQTextMessage msg = (ActiveMQTextMessage) message.copy();
String messageText = msg.getText();
if (messageText != null) {
result.payload(new Buffer(msg.getText().getBytes("UTF-8")));
}
}
} else if (message.getDataStructureType() == ActiveMQBytesMessage.DATA_STRUCTURE_TYPE) {
ActiveMQBytesMessage msg = (ActiveMQBytesMessage) message.copy();
msg.setReadOnlyBody(true);
byte[] data = new byte[(int) msg.getBodyLength()];
msg.readBytes(data);
result.payload(new Buffer(data));
} else {
if (byteSequence != null && byteSequence.getLength() > 0) {
result.payload(new Buffer(byteSequence.data, byteSequence.offset, byteSequence.length));
}
}
return result;
}