From 157a7fd18b24148e77a6a3bb050399f8e5bc8976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20T=C3=A2che?= Date: Mon, 17 Aug 2020 17:10:55 +0200 Subject: [PATCH] GH-46 Saves dav without using temp file --- .../org/icepdf/ri/common/SwingController.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/SwingController.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/SwingController.java index 94968b9b7..deec997a4 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/SwingController.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/SwingController.java @@ -3582,15 +3582,15 @@ public void saveFile() { if (document.getStateManager().hasChangedSince(savedChanges)) { if (pdfClient != null) { try { - //TODO no choice but to dump file to append changes as long as IncrementalUpdater is obfuscated - File tmp = Files.createTempFile(pdfClient.getName(), "." + FileExtensionUtils.pdf).toFile(); - try (final OutputStream out = new BufferedOutputStream(new FileOutputStream(tmp))) { - document.saveToOutputStream(out); - } - try (final InputStream pdfIn = new BufferedInputStream(new FileInputStream(tmp))) { - pdfClient.save(pdfIn); - } - tmp.delete(); + final PipedInputStream in = new PipedInputStream(); + new Thread(() -> { + try (final PipedOutputStream out = new PipedOutputStream(in)) { + document.saveToOutputStream(out); + } catch (final IOException e) { + logger.log(Level.WARNING, e, () -> "Error writing to output"); + } + }).start(); + pdfClient.save(in); savedChanges = document.getStateManager().getChanges(); } catch (IOException e) { logger.log(Level.FINE, "IOException while saving dav", e);