View Javadoc

1   package com.atlassian.plugin.util;
2   
3   import com.atlassian.plugin.util.zip.UrlUnzipper;
4   import org.apache.commons.logging.Log;
5   import org.apache.commons.logging.LogFactory;
6   
7   import java.io.File;
8   import java.io.IOException;
9   import java.net.URL;
10  
11  public class FileUtils
12  {
13      private static final Log log = LogFactory.getLog(FileUtils.class);
14  
15      /**
16       * Extract the zip from the URL into the destination directory, but only if the contents haven't already been
17       * unzipped.  If the directory contains different contents than the zip, the directory is cleaned out
18       * and the files are unzipped.
19       *
20       * @param zipUrl The zip url
21       * @param destDir The destination directory for the zip contents
22       */
23      public static void conditionallyExtractZipFile(URL zipUrl, File destDir)
24      {
25          try
26          {
27              UrlUnzipper unzipper = new UrlUnzipper(zipUrl, destDir);
28              unzipper.conditionalUnzip();
29          }
30          catch (IOException e)
31          {
32              log.error("Found " + zipUrl + ", but failed to read file", e);
33          }
34      }
35  
36      /**
37       * @deprecated Since 2.0.0
38       */
39      public static void deleteDir(File directory)
40      {
41          try
42          {
43              org.apache.commons.io.FileUtils.deleteDirectory(directory);
44          } catch (IOException e)
45          {
46              log.error("Unable to delete directory: "+directory.getAbsolutePath(), e);
47          }
48      }
49  
50  }