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
|
|
|
public abstract class Ready {
|
2021-01-18 18:31:50 +01:00
|
|
|
|
2021-08-18 18:27:22 +02:00
|
|
|
/**
|
|
|
|
* Write the data to the provided output stream.
|
|
|
|
*
|
|
|
|
* @param outputStream output stream
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public abstract void writeTo(OutputStream outputStream) throws IOException;
|
|
|
|
|
2021-08-18 18:27:22 +02:00
|
|
|
/**
|
|
|
|
* Return the data as a byte array by writing it to a {@link ByteArrayOutputStream} first and then returning
|
|
|
|
* the array.
|
|
|
|
*
|
|
|
|
* @return data as byte array
|
|
|
|
* @throws IOException in case of an IO error
|
|
|
|
*/
|
2021-07-15 16:55:13 +02:00
|
|
|
public byte[] getBytes() throws IOException {
|
|
|
|
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
|
|
|
writeTo(bytes);
|
|
|
|
return bytes.toByteArray();
|
2021-01-18 18:31:50 +01:00
|
|
|
}
|
|
|
|
}
|