From fe03197f3e6b0c0758aab7f0dc74cf263315e3f5 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 16 Dec 2020 18:45:13 +0100 Subject: [PATCH] Use NullOutputStream in verifier to safe resources --- .../org/pgpainless/sop/commands/Verify.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/Verify.java b/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/Verify.java index 9cb08135..0ec64eae 100644 --- a/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/Verify.java +++ b/pgpainless-sop/src/main/java/org/pgpainless/sop/commands/Verify.java @@ -10,14 +10,18 @@ import org.pgpainless.decryption_verification.OpenPgpMetadata; import org.pgpainless.key.OpenPgpV4Fingerprint; import picocli.CommandLine; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.OutputStream; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.TimeZone; @CommandLine.Command(name = "verify", description = "Verify a detached signature.\nThe signed data is being read from standard input.") public class Verify implements Runnable { @@ -66,7 +70,7 @@ public class Verify implements Runnable { .ignoreMissingPublicKeys() .build(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); + OutputStream out = new NullOutputStream(); Streams.pipeAll(verifier, out); verifier.close(); @@ -141,4 +145,12 @@ public class Verify implements Runnable { return null; } } + + private static class NullOutputStream extends OutputStream { + + @Override + public void write(int b) throws IOException { + // Nope + } + } }