View Javadoc
1   package com.atlassian.plugin.util;
2   
3   import com.atlassian.plugin.util.zip.UrlUnzipper;
4   import org.slf4j.Logger;
5   import org.slf4j.LoggerFactory;
6   
7   import java.io.File;
8   import java.io.IOException;
9   import java.net.URL;
10  
11  public class FileUtils {
12      private static final Logger log = LoggerFactory.getLogger(FileUtils.class);
13  
14      /**
15       * Extract the zip from the URL into the destination directory, but only if the contents haven't already been
16       * unzipped. If the directory contains different contents than the zip, the directory is cleaned out
17       * and the files are unzipped.
18       *
19       * @param zipUrl  The zip url
20       * @param destDir The destination directory for the zip contents
21       */
22      public static void conditionallyExtractZipFile(URL zipUrl, File destDir) {
23          try {
24              UrlUnzipper unzipper = new UrlUnzipper(zipUrl, destDir);
25              unzipper.conditionalUnzip();
26          } catch (IOException e) {
27              log.error("Found {}, but failed to read file", zipUrl, e);
28          }
29      }
30  }