001
014
015 package com.liferay.portal.kernel.zip;
016
017 import com.liferay.portal.kernel.io.unsync.UnsyncFilterInputStream;
018
019 import java.io.File;
020 import java.io.IOException;
021 import java.io.InputStream;
022
023 import java.util.zip.ZipFile;
024
025
028 public class ZipFileUtil {
029
030 public static InputStream openInputStream(File file, String entryName)
031 throws IOException {
032
033 ZipFile zipFile = new ZipFile(file);
034
035 return new ZipFileInputStream(
036 zipFile.getInputStream(zipFile.getEntry(entryName)), zipFile);
037 }
038
039 private static class ZipFileInputStream extends UnsyncFilterInputStream {
040
041 @Override
042 public void close() throws IOException {
043 try {
044 inputStream.close();
045 }
046 finally {
047 _zipFile.close();
048 }
049 }
050
051 private ZipFileInputStream(InputStream inputStream, ZipFile zipFile) {
052 super(inputStream);
053
054 _zipFile = zipFile;
055 }
056
057 private final ZipFile _zipFile;
058
059 }
060
061 }