001// SPDX-FileCopyrightText: 2021 Paul Schaub <vanitasvitae@fsfe.org>
002//
003// SPDX-License-Identifier: Apache-2.0
004
005package sop;
006
007import java.io.ByteArrayInputStream;
008import java.io.InputStream;
009
010/**
011 * Tuple of a byte array and associated result object.
012 * @param <T> type of result
013 */
014public class ByteArrayAndResult<T> {
015
016    private final byte[] bytes;
017    private final T result;
018
019    public ByteArrayAndResult(byte[] bytes, T result) {
020        this.bytes = bytes;
021        this.result = result;
022    }
023
024    /**
025     * Return the byte array part.
026     *
027     * @return bytes
028     */
029    public byte[] getBytes() {
030        return bytes;
031    }
032
033    /**
034     * Return the result part.
035     *
036     * @return result
037     */
038    public T getResult() {
039        return result;
040    }
041
042    /**
043     * Return the byte array part as an {@link InputStream}.
044     *
045     * @return input stream
046     */
047    public InputStream getInputStream() {
048        return new ByteArrayInputStream(getBytes());
049    }
050}