aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/mammoth/tests/docx/InMemoryFileReader.java
blob: bce456860d97da783581c513250f0121e331c16b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package org.zwobble.mammoth.tests.docx;

import org.zwobble.mammoth.internal.docx.FileReader;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import static org.zwobble.mammoth.internal.util.Maps.lookup;

public class InMemoryFileReader implements FileReader {
    private final Map<String, String> entries;

    public InMemoryFileReader(Map<String, String> entries) {
        this.entries = entries;
    }

    @Override
    public InputStream getInputStream(String name) throws IOException {
        String value = lookup(entries, name).get();
        return new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8));
    }
}