org.pgpainless.util.PGPUtilWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pgpainless-core Show documentation
Show all versions of pgpainless-core Show documentation
Simple to use OpenPGP API for Java based on Bouncycastle
// SPDX-FileCopyrightText: 2021 Paul Schaub
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.util;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.bouncycastle.openpgp.PGPUtil;
public final class PGPUtilWrapper {
private PGPUtilWrapper() {
}
/**
* {@link PGPUtil#getDecoderStream(InputStream)} sometimes mistakens non-base64 data for base64 encoded data.
*
* This method expects a {@link BufferedInputStream} which is being reset in case an {@link IOException} is encountered.
* Therefore, we can properly handle non-base64 encoded data.
*
* @param buf buffered input stream
* @return input stream
* @throws IOException in case of an io error which is unrelated to base64 encoding
*/
public static InputStream getDecoderStream(BufferedInputStream buf) throws IOException {
buf.mark(512);
try {
return PGPUtil.getDecoderStream(buf);
} catch (IOException e) {
if (e.getMessage().contains("invalid characters encountered at end of base64 data")) {
buf.reset();
return buf;
}
throw e;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy