Esempio n. 1
0
  /**
   * Copy the contents of fromDir into toDir (if the latter is missing it will be created)
   *
   * @param fromDir
   * @param toDir
   * @throws IOException
   */
  public static void deepCopy(File fromDir, File toDir) throws IOException {
    if (!fromDir.isDirectory() || !fromDir.exists())
      throw new IllegalArgumentException(
          "Invalid source directory " + "(it's either not a directory, or does not exist");
    if (toDir.exists() && toDir.isFile())
      throw new IllegalArgumentException(
          "Invalid destination directory, " + "it happens to be a file instead");

    // create destination if not available
    if (!toDir.exists()) if (!toDir.mkdir()) throw new IOException("Could not create " + toDir);

    File[] files = fromDir.listFiles();
    for (File file : files) {
      File destination = new File(toDir, file.getName());
      if (file.isDirectory()) deepCopy(file, destination);
      else copy(file, destination);
    }
  }
Esempio n. 2
0
 /**
  * Deeps copy the dataDirSourceDirectory provided in the constructor into a temporary directory.
  * Subclasses may override it in order to add extra behavior (like setting up an external
  * database)
  */
 public void setUp() throws Exception {
   data = IOUtils.createRandomDirectory("./target", "live", "data");
   IOUtils.deepCopy(source, data);
 }