mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-10 10:49:39 +02:00
Kotlin conversion: ArmoredInputStreamFactory
This commit is contained in:
parent
6b397a0d56
commit
e16376ca68
2 changed files with 36 additions and 43 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue