diff --git a/mqtt-spy/src/main/java/pl/baczkowicz/mqttspy/ui/messagelog/MqttMessageAuditUtils.java b/mqtt-spy/src/main/java/pl/baczkowicz/mqttspy/ui/messagelog/MqttMessageAuditUtils.java index 49fd6c72..c7ce18f8 100644 --- a/mqtt-spy/src/main/java/pl/baczkowicz/mqttspy/ui/messagelog/MqttMessageAuditUtils.java +++ b/mqtt-spy/src/main/java/pl/baczkowicz/mqttspy/ui/messagelog/MqttMessageAuditUtils.java @@ -32,22 +32,24 @@ public class MqttMessageAuditUtils implements MessageAuditUtils { - public String getCurrentMessageAsMessageLog(final BasicMessageStoreWithSummary store, final int messageIndex) + public String getCurrentMessageAsMessageLog(final BasicMessageStoreWithSummary store, final int messageIndex, final boolean encode) { final FormattedMessage message = store.getMessages().get(messageIndex); + final MessageLogEnum format = encode ? MessageLogEnum.XML_WITH_ENCODED_PAYLOAD : MessageLogEnum.XML_WITH_PLAIN_PAYLOAD; if (message instanceof FormattedMqttMessage) { return SimpleMqttMessageLogComposer.createReceivedMessageLog((FormattedMqttMessage) message, - new MessageLog(MessageLogEnum.XML_WITH_PLAIN_PAYLOAD, "", true, true, false, false, false)); + new MessageLog(format, "", true, true, false, false, false)); } return null; } - public String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary store) + public String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary store, final boolean encode) { final StringBuffer messagesAsString = new StringBuffer(); + final MessageLogEnum format = encode ? MessageLogEnum.XML_WITH_ENCODED_PAYLOAD : MessageLogEnum.XML_WITH_PLAIN_PAYLOAD; final List messages = store.getMessages(); for (int i = messages.size() - 1; i >= 0; i--) @@ -57,7 +59,7 @@ public String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary 0) { - UiUtils.copyToClipboard(messageAuditUtils.getCurrentMessageAsMessageLog(store, getSelectedMessageIndex() - 1)); + UiUtils.copyToClipboard(messageAuditUtils.getCurrentMessageAsMessageLog(store, getSelectedMessageIndex() - 1, false)); } } public void copyMessagesToClipboard() { - UiUtils.copyToClipboard(messageAuditUtils.getAllMessagesAsMessageLog(store)); + UiUtils.copyToClipboard(messageAuditUtils.getAllMessagesAsMessageLog(store, false)); } @@ -518,7 +518,7 @@ public void copyMessageToFile() if (selectedFile != null) { - FileUtils.writeToFile(selectedFile, messageAuditUtils.getCurrentMessageAsMessageLog(store, getSelectedMessageIndex() - 1)); + FileUtils.writeToFile(selectedFile, messageAuditUtils.getCurrentMessageAsMessageLog(store, getSelectedMessageIndex() - 1, true)); } } } @@ -552,7 +552,7 @@ public void copyMessagesToFile() if (selectedFile != null) { - FileUtils.writeToFile(selectedFile, messageAuditUtils.getAllMessagesAsMessageLog(store)); + FileUtils.writeToFile(selectedFile, messageAuditUtils.getAllMessagesAsMessageLog(store, true)); } } diff --git a/spy-common-ui/src/main/java/pl/baczkowicz/spy/ui/storage/MessageAuditUtils.java b/spy-common-ui/src/main/java/pl/baczkowicz/spy/ui/storage/MessageAuditUtils.java index af32f108..9f5a626e 100644 --- a/spy-common-ui/src/main/java/pl/baczkowicz/spy/ui/storage/MessageAuditUtils.java +++ b/spy-common-ui/src/main/java/pl/baczkowicz/spy/ui/storage/MessageAuditUtils.java @@ -24,7 +24,7 @@ public interface MessageAuditUtils { - String getCurrentMessageAsMessageLog(final BasicMessageStoreWithSummary store, final int messageIndex); + String getCurrentMessageAsMessageLog(final BasicMessageStoreWithSummary store, final int messageIndex, final boolean encode); - String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary store); + String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary store, final boolean encode); }