diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-02-24 08:16:16 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-02-24 08:16:16 +0000 |
| commit | 3e2786a004eddf968a5fa7d5a92dff5b1b5f7734 (patch) | |
| tree | 7fa1bcc1e484cd0ef782f64baf504ee83333d397 /src/main/java/org/zwobble/mammoth/docx/InMemoryDocxFile.java | |
| parent | 0dc3a12affc2e46c1a0df2899cf51a1ae3fdbd61 (diff) | |
Create internal package
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/docx/InMemoryDocxFile.java')
| -rw-r--r-- | src/main/java/org/zwobble/mammoth/docx/InMemoryDocxFile.java | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/src/main/java/org/zwobble/mammoth/docx/InMemoryDocxFile.java b/src/main/java/org/zwobble/mammoth/docx/InMemoryDocxFile.java deleted file mode 100644 index 3c6d4b4..0000000 --- a/src/main/java/org/zwobble/mammoth/docx/InMemoryDocxFile.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.zwobble.mammoth.docx; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.google.common.io.ByteStreams; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.Map; -import java.util.Optional; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -public class InMemoryDocxFile implements DocxFile { - public static DocxFile fromStream(InputStream stream) throws IOException { - ZipInputStream zipStream = new ZipInputStream(stream); - ImmutableMap.Builder<String, byte[]> entries = ImmutableMap.builder(); - ZipEntry entry; - while ((entry = zipStream.getNextEntry()) != null) { - entries.put(entry.getName(), ByteStreams.toByteArray(zipStream)); - } - return new InMemoryDocxFile(entries.build()); - } - - public static DocxFile fromStrings(Map<String, String> entries) { - return new InMemoryDocxFile(Maps.transformValues(entries, value -> value.getBytes(StandardCharsets.UTF_8))); - } - - private final Map<String, byte[]> entries; - - public InMemoryDocxFile(Map<String, byte[]> entries) { - this.entries = entries; - } - - @Override - public Optional<InputStream> tryGetInputStream(String name) throws IOException { - return Optional.ofNullable(entries.get(name)) - .map(ByteArrayInputStream::new); - } - - @Override - public void close() throws IOException { - } -} |
