mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-19 02:42:05 +01:00
Kotlin conversion: ArmoredInputStreamFactory
This commit is contained in:
parent
6b397a0d56
commit
e16376ca68
2 changed files with 36 additions and 43 deletions
|
@ -1,43 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.bouncycastle.bcpg.ArmoredInputStream;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Factory class for instantiating preconfigured {@link ArmoredInputStream ArmoredInputStreams}.
|
||||
* {@link #get(InputStream)} will return an {@link ArmoredInputStream} that is set up to properly detect CRC errors.
|
||||
*/
|
||||
public final class ArmoredInputStreamFactory {
|
||||
|
||||
private ArmoredInputStreamFactory() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of {@link ArmoredInputStream} which will detect CRC errors.
|
||||
*
|
||||
* @param inputStream input stream
|
||||
* @return armored input stream
|
||||
* @throws IOException in case of an IO error
|
||||
*/
|
||||
@Nonnull
|
||||
public static ArmoredInputStream get(@Nonnull InputStream inputStream) throws IOException {
|
||||
if (inputStream instanceof CRCingArmoredInputStreamWrapper) {
|
||||
return (ArmoredInputStream) inputStream;
|
||||
}
|
||||
if (inputStream instanceof ArmoredInputStream) {
|
||||
return new CRCingArmoredInputStreamWrapper((ArmoredInputStream) inputStream);
|
||||
}
|
||||
|
||||
ArmoredInputStream armorIn = new ArmoredInputStream(inputStream);
|
||||
return new CRCingArmoredInputStreamWrapper(armorIn);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package org.pgpainless.util
|
||||
|
||||
import org.bouncycastle.bcpg.ArmoredInputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* Factory class for instantiating preconfigured [ArmoredInputStream] instances.
|
||||
* [get] will return an [ArmoredInputStream] that is set up to properly detect CRC errors v4 style.
|
||||
*/
|
||||
class ArmoredInputStreamFactory {
|
||||
|
||||
companion object {
|
||||
|
||||
/**
|
||||
* Return an instance of [ArmoredInputStream] which will detect CRC errors.
|
||||
*
|
||||
* @param inputStream input stream
|
||||
* @return armored input stream
|
||||
* @throws IOException in case of an IO error
|
||||
*/
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
fun get(inputStream: InputStream): ArmoredInputStream {
|
||||
return when (inputStream) {
|
||||
is CRCingArmoredInputStreamWrapper -> inputStream
|
||||
is ArmoredInputStream -> CRCingArmoredInputStreamWrapper(inputStream)
|
||||
else -> CRCingArmoredInputStreamWrapper(ArmoredInputStream(inputStream))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue