diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-11-13 20:11:50 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-11-13 20:11:50 +0000 |
| commit | 6f87042576150fd65db52144417d8a788f2441f4 (patch) | |
| tree | 87282928b2f0047363df867bc73a66d7929f662d /src/main/java/org/zwobble/mammoth/internal/archives/ZippedArchive.java | |
| parent | 38e6e7e0a0c214a17b251cea8c767655dfaecc67 (diff) | |
Move archive classes into their own package
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/internal/archives/ZippedArchive.java')
| -rw-r--r-- | src/main/java/org/zwobble/mammoth/internal/archives/ZippedArchive.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/mammoth/internal/archives/ZippedArchive.java b/src/main/java/org/zwobble/mammoth/internal/archives/ZippedArchive.java new file mode 100644 index 0000000..32b8894 --- /dev/null +++ b/src/main/java/org/zwobble/mammoth/internal/archives/ZippedArchive.java @@ -0,0 +1,37 @@ +package org.zwobble.mammoth.internal.archives; + +import org.zwobble.mammoth.internal.archives.Archive; + +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(); + } +} |
