1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-10-31 17:45:58 +01:00

Fix performance issue of encrypt and sign operations by buffering

This commit is contained in:
Paul Schaub 2022-06-15 23:13:53 +02:00
parent c967cbb9f0
commit 57fbb469ea
2 changed files with 12 additions and 1 deletions

View file

@ -46,4 +46,10 @@ public class CRLFGeneratorStream extends OutputStream {
}
crlfOut.close();
}
@Override
public void flush() throws IOException {
super.flush();
crlfOut.flush();
}
}

View file

@ -4,6 +4,7 @@
package org.pgpainless.encryption_signing;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
@ -182,7 +183,11 @@ public final class EncryptionStream extends OutputStream {
}
public void prepareInputEncoding() {
CRLFGeneratorStream crlfGeneratorStream = new CRLFGeneratorStream(outermostStream,
// By buffering here, we drastically improve performance
// Reason is that CRLFGeneratorStream only implements write(int), so we need BufferedOutputStream to
// "convert" to write(buf) calls again
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outermostStream);
CRLFGeneratorStream crlfGeneratorStream = new CRLFGeneratorStream(bufferedOutputStream,
options.isApplyCRLFEncoding() ? StreamEncoding.UTF8 : StreamEncoding.BINARY);
outermostStream = crlfGeneratorStream;
}