From 9cdea63ec4227017cb9ae89a94e03ba40d6330f7 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 15 Jun 2022 23:14:09 +0200 Subject: [PATCH] Fix performance issues of sop armor and dearmor operations --- .../src/main/java/org/pgpainless/sop/ArmorImpl.java | 6 +++++- .../src/main/java/org/pgpainless/sop/DearmorImpl.java | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pgpainless-sop/src/main/java/org/pgpainless/sop/ArmorImpl.java b/pgpainless-sop/src/main/java/org/pgpainless/sop/ArmorImpl.java index 5c92f9b9..71bc3e6b 100644 --- a/pgpainless-sop/src/main/java/org/pgpainless/sop/ArmorImpl.java +++ b/pgpainless-sop/src/main/java/org/pgpainless/sop/ArmorImpl.java @@ -4,6 +4,7 @@ package org.pgpainless.sop; +import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -28,8 +29,11 @@ public class ArmorImpl implements Armor { return new Ready() { @Override public void writeTo(OutputStream outputStream) throws IOException { - ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(outputStream); + // By buffering the output stream, we can improve performance drastically + BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream); + ArmoredOutputStream armor = ArmoredOutputStreamFactory.get(bufferedOutputStream); Streams.pipeAll(data, armor); + bufferedOutputStream.flush(); armor.close(); } }; diff --git a/pgpainless-sop/src/main/java/org/pgpainless/sop/DearmorImpl.java b/pgpainless-sop/src/main/java/org/pgpainless/sop/DearmorImpl.java index 73bd65d5..1cebec6e 100644 --- a/pgpainless-sop/src/main/java/org/pgpainless/sop/DearmorImpl.java +++ b/pgpainless-sop/src/main/java/org/pgpainless/sop/DearmorImpl.java @@ -4,6 +4,7 @@ package org.pgpainless.sop; +import java.io.BufferedOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -22,7 +23,9 @@ public class DearmorImpl implements Dearmor { @Override public void writeTo(OutputStream outputStream) throws IOException { - Streams.pipeAll(decoder, outputStream); + BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream); + Streams.pipeAll(decoder, bufferedOutputStream); + bufferedOutputStream.flush(); decoder.close(); } };