Kotlin conversion: DearmorExternal

This commit is contained in:
Paul Schaub 2023-11-15 16:45:32 +01:00
parent d149aac56c
commit da2b299f4d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 20 additions and 37 deletions

View file

@ -1,37 +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.exception.SOPGPException;
import sop.external.ExternalSOP;
import sop.operation.Dearmor;
import javax.annotation.Nonnull;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
/**
* Implementation of the {@link Dearmor} operation using an external SOP binary.
*/
public class DearmorExternal implements Dearmor {
private final List<String> commandList = new ArrayList<>();
private final List<String> envList;
public DearmorExternal(String binary, Properties environment) {
commandList.add(binary);
commandList.add("dearmor");
envList = ExternalSOP.propertiesToEnv(environment);
}
@Override
@Nonnull
public Ready data(@Nonnull InputStream data) throws SOPGPException.BadData {
return ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, data);
}
}

View file

@ -0,0 +1,20 @@
// 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.external.ExternalSOP
import sop.operation.Dearmor
/** Implementation of the [Dearmor] operation using an external SOP binary. */
class DearmorExternal(binary: String, environment: Properties) : Dearmor {
private val commandList = listOf(binary, "dearmor")
private val envList = ExternalSOP.propertiesToEnv(environment)
override fun data(data: InputStream): Ready =
ExternalSOP.executeTransformingOperation(Runtime.getRuntime(), commandList, envList, data)
}