1
2
3
4
5 package com.atlassian.plugin.util.zip;
6
7 import org.apache.commons.lang.StringUtils;
8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory;
10
11 import java.io.BufferedInputStream;
12 import java.io.File;
13 import java.io.FileInputStream;
14 import java.io.FileNotFoundException;
15 import java.io.IOException;
16 import java.util.zip.ZipEntry;
17
18 public class FileUnzipper extends AbstractUnzipper {
19 private static final Logger log = LoggerFactory.getLogger(FileUnzipper.class);
20
21 private File zipFile;
22 private File destDir;
23
24 public FileUnzipper(File zipFile, File destDir) {
25 this.zipFile = zipFile;
26 this.destDir = destDir;
27 }
28
29
30
31
32
33
34 public void unzip() throws IOException {
35 if ((zipFile == null) || !zipFile.isFile())
36 return;
37
38 getStreamUnzipper().unzip();
39 }
40
41 public ZipEntry[] entries() throws IOException {
42 return getStreamUnzipper().entries();
43 }
44
45
46
47
48
49
50 public File unzipFileInArchive(String fileName) throws IOException {
51 File result = null;
52
53 if ((zipFile == null) || !zipFile.isFile() || !StringUtils.isNotEmpty(fileName))
54 return result;
55
56 result = getStreamUnzipper().unzipFileInArchive(fileName);
57
58 if (result == null)
59 log.error("The file: " + fileName + " could not be found in the archive: " + zipFile.getAbsolutePath());
60
61 return result;
62 }
63
64 private StreamUnzipper getStreamUnzipper() throws FileNotFoundException {
65 return new StreamUnzipper(new BufferedInputStream(new FileInputStream(zipFile)), destDir);
66 }
67
68 }