1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-22 20:32:05 +01:00

Fix SOP armor command

This commit is contained in:
Paul Schaub 2021-07-01 18:44:57 +02:00
parent c234e38ae2
commit b76172f97a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -51,12 +51,17 @@ public class Armor implements Runnable {
@Override @Override
public void run() { public void run() {
try (PushbackInputStream pbIn = new PushbackInputStream(System.in); try (PushbackInputStream pbIn = new PushbackInputStream(System.in, BEGIN_ARMOR.length);
ArmoredOutputStream armoredOutputStream = ArmoredOutputStreamFactory.get(System.out)) { ArmoredOutputStream armoredOutputStream = ArmoredOutputStreamFactory.get(System.out)) {
byte[] start = new byte[14];
int read = pbIn.read(start); // take a peek
pbIn.unread(read); byte[] firstBytes = new byte[BEGIN_ARMOR.length];
if (Arrays.equals(BEGIN_ARMOR, start) && !allowNested) { int readByteCount = pbIn.read(firstBytes);
if (readByteCount != -1) {
pbIn.unread(firstBytes, 0, readByteCount);
}
if (Arrays.equals(BEGIN_ARMOR, firstBytes) && !allowNested) {
Streams.pipeAll(pbIn, System.out); Streams.pipeAll(pbIn, System.out);
} else { } else {
Streams.pipeAll(pbIn, armoredOutputStream); Streams.pipeAll(pbIn, armoredOutputStream);