From b62754e52ccb1c52bff10e055cc06660e489cdab Mon Sep 17 00:00:00 2001 From: Bengt Martensson Date: Sat, 4 Nov 2023 12:21:00 +0100 Subject: [PATCH] Export signal: check savefile for null-ness. Resolves #506. --- .../exporter/DynamicRemoteSetExportFormat.java | 3 ++- .../irscrutinizer/exporter/Exporter.java | 3 ++- .../irscrutinizer/exporter/TextExporter.java | 13 +++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/harctoolbox/irscrutinizer/exporter/DynamicRemoteSetExportFormat.java b/src/main/java/org/harctoolbox/irscrutinizer/exporter/DynamicRemoteSetExportFormat.java index 378d9993..829d9404 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/exporter/DynamicRemoteSetExportFormat.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/exporter/DynamicRemoteSetExportFormat.java @@ -203,7 +203,8 @@ protected void possiblyMakeExecutable(File file) { @Override public void export(RemoteSet remoteSet, String title, File saveFile, String encoding) throws IOException, TransformerException { - export(remoteSet, title, saveFile.getCanonicalPath(), encoding); + if (saveFile != null) + export(remoteSet, title, saveFile.getCanonicalPath(), encoding); } private void export(RemoteSet remoteSet, String title, String fileName, String encoding) throws IOException, TransformerException { diff --git a/src/main/java/org/harctoolbox/irscrutinizer/exporter/Exporter.java b/src/main/java/org/harctoolbox/irscrutinizer/exporter/Exporter.java index bfa020e4..329ad034 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/exporter/Exporter.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/exporter/Exporter.java @@ -201,7 +201,8 @@ public boolean considersRepetitions() { } public void export(Document document, File file, String charsetName) throws FileNotFoundException, UnsupportedEncodingException { - XmlUtils.printDOM(file, document, charsetName, null); + if (file != null) + XmlUtils.printDOM(file, document, charsetName, null); } public void export(String payload, File file, String charsetName) throws FileNotFoundException, UnsupportedEncodingException { diff --git a/src/main/java/org/harctoolbox/irscrutinizer/exporter/TextExporter.java b/src/main/java/org/harctoolbox/irscrutinizer/exporter/TextExporter.java index 20264822..4501e58c 100644 --- a/src/main/java/org/harctoolbox/irscrutinizer/exporter/TextExporter.java +++ b/src/main/java/org/harctoolbox/irscrutinizer/exporter/TextExporter.java @@ -78,12 +78,13 @@ public boolean supportsEmbeddedFormats() { @Override public void export(RemoteSet remoteSet, String title, File file, String charsetName) throws IOException, GirrException, IrCoreException, IrpException { - try (PrintStream printStream = new PrintStream(file, charsetName)) { - for (Remote remote : remoteSet) - for (CommandSet commandSet : remote) - for (Command command : commandSet) - printStream.println(formatCommand(command, 1)); - } + if (file != null) + try (PrintStream printStream = new PrintStream(file, charsetName)) { + for (Remote remote : remoteSet) + for (CommandSet commandSet : remote) + for (Command command : commandSet) + printStream.println(formatCommand(command, 1)); + } } private String formatCommand(Command command, int count) throws GirrException, IrpException, IrCoreException {