2021-10-07 15:48:52 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2021-07-15 16:55:13 +02:00
|
|
|
package sop;
|
2021-01-18 18:31:50 +01:00
|
|
|
|
2021-07-15 16:55:13 +02:00
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
2021-01-18 18:31:50 +01:00
|
|
|
|
2021-07-15 16:55:13 +02:00
|
|
|
import sop.exception.SOPGPException;
|
2021-01-18 18:31:50 +01:00
|
|
|
|
2021-07-15 16:55:13 +02:00
|
|
|
public abstract class ReadyWithResult<T> {
|
|
|
|
|
2021-08-18 18:27:22 +02:00
|
|
|
/**
|
|
|
|
* Write the data eg. decrypted plaintext to the provided output stream and return the result of the
|
|
|
|
* processing operation.
|
|
|
|
*
|
|
|
|
* @param outputStream output stream
|
|
|
|
* @return result, eg. signatures
|
|
|
|
*
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
* @throws SOPGPException.NoSignature
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public abstract T writeTo(OutputStream outputStream) throws IOException, SOPGPException.NoSignature;
|
|
|
|
|
|
|
|
public ByteArrayAndResult<T> toBytes() throws IOException, SOPGPException.NoSignature {
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
T result = writeTo(bytes);
|
|
|
|
return new ByteArrayAndResult<>(bytes.toByteArray(), result);
|
2021-01-18 18:31:50 +01:00
|
|
|
}
|
|
|
|
}
|