1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2025-12-10 22:31:09 +01:00

Revert introduction of StreamUtil

This commit is contained in:
Paul Schaub 2021-07-31 20:40:31 +02:00
parent b8f719d3eb
commit 311c842196
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
27 changed files with 78 additions and 137 deletions

View file

@ -35,10 +35,10 @@ import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.openpgp.PGPUtil;
import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
import org.bouncycastle.util.io.Streams;
import org.pgpainless.implementation.ImplementationFactory;
import org.pgpainless.key.collection.PGPKeyRingCollection;
import org.pgpainless.util.ArmoredInputStreamFactory;
import org.pgpainless.util.StreamUtil;
public class KeyRingReader {
@ -176,7 +176,7 @@ public class KeyRingReader {
continue;
}
if (next instanceof PGPSecretKeyRing) {
StreamUtil.drain(decoderStream);
Streams.drain(decoderStream);
return (PGPSecretKeyRing) next;
}
} while (true);

View file

@ -32,6 +32,7 @@ import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
import org.bouncycastle.util.io.Streams;
import org.pgpainless.algorithm.HashAlgorithm;
import org.pgpainless.key.OpenPgpV4Fingerprint;
@ -142,7 +143,7 @@ public class ArmorUtils {
public static String toAsciiArmoredString(InputStream inputStream, MultiMap<String, String> additionalHeaderValues) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream armor = toAsciiArmoredStream(out, additionalHeaderValues);
StreamUtil.pipeAll(inputStream, armor);
Streams.pipeAll(inputStream, armor);
armor.close();
return out.toString();

View file

@ -1,60 +0,0 @@
/*
* Copyright 2021 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class StreamUtil {
/**
* Pipe all data from the given {@link InputStream} to the given {@link OutputStream}.
*
* This utility method is required, since {@link org.bouncycastle.util.io.Streams#pipeAll(InputStream, OutputStream)}
* internally uses {@link InputStream#read(byte[], int, int)} which silently swallows {@link IOException IOExceptions}.
*
* @see <a href="https://github.com/pgpainless/pgpainless/issues/159#issuecomment-886694555">Explanation</a>
* @see <a href="https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/share/classes/java/io/InputStream.java#L286">
* InputStream swallowing IOExceptions</a>
*
* @param inputStream input stream
* @param outputStream output stream
* @throws IOException io exceptions
*/
public static void pipeAll(InputStream inputStream, OutputStream outputStream) throws IOException {
do {
int i = inputStream.read();
if (i == -1) {
break;
}
outputStream.write(i);
} while (true);
}
/**
* Drain an {@link InputStream} without calling {@link InputStream#read(byte[], int, int)}.
*
* @param inputStream input stream
* @throws IOException io exception
*/
public static void drain(InputStream inputStream) throws IOException {
int i;
do {
i = inputStream.read();
} while (i != -1);
}
}