StreamStamper.java

1
package pro.verron.officestamper.api;
2
3
import org.docx4j.openpackaging.packages.OpcPackage;
4
5
import java.io.InputStream;
6
import java.io.OutputStream;
7
import java.util.function.Function;
8
9
/// This class implements the functionality of an OfficeStamper meant for dealing with streams of data. It delegates the executing
10
/// of the stamp operation to an OfficeStamper instance while providing the necessary mechanisms to work with streams.
11
///
12
/// @param <T> The type of the template that can be stamped. This type must extend OpcPackage.
13
/// @author Joseph Verron
14
/// @version ${version}
15
/// @since 1.6.4
16
public class StreamStamper<T extends OpcPackage> {
17
    /// Holds a reference to a function that takes in an InputStream and produces an instance of type T.
18
    private final Function<InputStream, T> loader;
19
    /// Holds a reference to an OfficeStamper used to execute the stamp operation.
20
    private final OfficeStamper<T> stamper;
21
22
    /// Constructs a new StreamStamper with the provided loader and stamper.
23
    ///
24
    /// @param loader  A Function that takes in an InputStream and produces an instance of type T.
25
    /// @param stamper An OfficeStamper used to execute the stamp operation.
26
    public StreamStamper(
27
            Function<InputStream, T> loader,
28
            OfficeStamper<T> stamper
29
    ) {
30
        this.loader = loader;
31
        this.stamper = stamper;
32
    }
33
34
    /// Stamps the template present in the given InputStream with the context given
35
    /// and writes the result to the provided OutputStream.
36
    /// This method first uses the loader to load the template from the
37
    /// InputStream into a type T instance,
38
    /// then uses the stamper
39
    /// to perform the stamp operation using the template and context,
40
    /// writing the result out to the OutputStream.
41
    ///
42
    /// @param inputStream  template to stamp
43
    /// @param context      context to use for stamping
44
    /// @param outputStream output stream to write the result to
45
    /// @throws OfficeStamperException if the stamping fails for any reason
46
    public void stamp(
47
            InputStream inputStream,
48
            Object context,
49
            OutputStream outputStream
50
    ) throws OfficeStamperException {
51
        T mlPackage = loader.apply(inputStream);
52 1 1. stamp : removed call to pro/verron/officestamper/api/OfficeStamper::stamp → KILLED
        stamper.stamp(mlPackage, context, outputStream);
53
    }
54
}

Mutations

52

1.1
Location : stamp
Killed by : pro.verron.officestamper.test.ResolutionTest.[engine:junit-jupiter]/[class:pro.verron.officestamper.test.ResolutionTest]/[test-template:testCustomResolution(java.lang.String, boolean, boolean, boolean, boolean, boolean, java.lang.String, boolean, java.lang.String)]/[test-template-invocation:#22]
removed call to pro/verron/officestamper/api/OfficeStamper::stamp → KILLED

Active mutators

Tests examined


Report generated by PIT 1.21.0