mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2024-12-22 04:57:56 +01:00
Kotlin conversion: ArmorExternal
This commit is contained in:
parent
1c0666b4e1
commit
6771952618
2 changed files with 26 additions and 46 deletions
|
@ -1,46 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external.operation;
|
||||
|
||||
import sop.Ready;
|
||||
import sop.enums.ArmorLabel;
|
||||
import sop.exception.SOPGPException;
|
||||
import sop.external.ExternalSOP;
|
||||
import sop.operation.Armor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Implementation of the {@link Armor} operation using an external SOP binary.
|
||||
*/
|
||||
public class ArmorExternal implements Armor {
|
||||
|
||||
private final List<String> commandList = new ArrayList<>();
|
||||
private final List<String> envList;
|
||||
|
||||
public ArmorExternal(String binary, Properties environment) {
|
||||
commandList.add(binary);
|
||||
commandList.add("armor");
|
||||
envList = ExternalSOP.propertiesToEnv(environment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
@Nonnull
|
||||
public Armor label(@Nonnull ArmorLabel label) throws SOPGPException.UnsupportedOption {
|
||||
commandList.add("--label=" + label);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public Ready data(@Nonnull InputStream data) throws SOPGPException.BadData {
|
||||
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, data);
|
||||
}
|
||||
}
|
26
external-sop/src/main/kotlin/sop/external/operation/ArmorExternal.kt
vendored
Normal file
26
external-sop/src/main/kotlin/sop/external/operation/ArmorExternal.kt
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.external.operation
|
||||
|
||||
import java.io.InputStream
|
||||
import java.util.Properties
|
||||
import sop.Ready
|
||||
import sop.enums.ArmorLabel
|
||||
import sop.exception.SOPGPException
|
||||
import sop.external.ExternalSOP
|
||||
import sop.operation.Armor
|
||||
|
||||
/** Implementation of the [Armor] operation using an external SOP binary. */
|
||||
class ArmorExternal(binary: String, environment: Properties) : Armor {
|
||||
|
||||
private val commandList: MutableList<String> = mutableListOf(binary, "armor")
|
||||
private val envList: List<String> = ExternalSOP.propertiesToEnv(environment)
|
||||
|
||||
override fun label(label: ArmorLabel): Armor = apply { commandList.add("--label=$label") }
|
||||
|
||||
@Throws(SOPGPException.BadData::class)
|
||||
override fun data(data: InputStream): Ready =
|
||||
ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, data)
|
||||
}
|
Loading…
Reference in a new issue