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

Mutations

64

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:#17]
removed call to pro/verron/officestamper/api/OfficeStamper::stamp → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0