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