diff options
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/internal/docx/ZippedArchive.java')
| -rw-r--r-- | src/main/java/org/zwobble/mammoth/internal/docx/ZippedArchive.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/mammoth/internal/docx/ZippedArchive.java b/src/main/java/org/zwobble/mammoth/internal/docx/ZippedArchive.java new file mode 100644 index 0000000..27e7fa4 --- /dev/null +++ b/src/main/java/org/zwobble/mammoth/internal/docx/ZippedArchive.java @@ -0,0 +1,35 @@ +package org.zwobble.mammoth.internal.docx; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Optional; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +public class ZippedArchive implements Archive { + private final ZipFile zipFile; + + public ZippedArchive(ZipFile zipFile) { + this.zipFile = zipFile; + } + + public ZippedArchive(File file) throws IOException { + this(new ZipFile(file)); + } + + @Override + public Optional<InputStream> tryGetInputStream(String name) throws IOException { + ZipEntry entry = zipFile.getEntry(name); + if (entry == null) { + return Optional.empty(); + } else { + return Optional.of(zipFile.getInputStream(entry)); + } + } + + @Override + public void close() throws IOException { + zipFile.close(); + } +} |
