/** * Copies a file or a directory's contents to another file or directory, which can have a * different name. The target file/directory is replaced if it already exists. * * <p>The source file/directory must exist and must not reside in, contain, or be identical to * the target file/directory. */ private static void copyFileOrDirectory(@NonNull File from, @NonNull File to) throws IOException { Preconditions.checkArgument( from.exists(), "Source path " + from.getAbsolutePath() + " does not exists."); Preconditions.checkArgument(!FileUtils.isFileInDirectory(from, to)); Preconditions.checkArgument(!FileUtils.isFileInDirectory(to, from)); Preconditions.checkArgument(!from.getCanonicalFile().equals(to.getCanonicalFile())); if (from.isFile()) { Files.createParentDirs(to); FileUtils.copyFile(from, to); } else if (from.isDirectory()) { FileUtils.deletePath(to); FileUtils.copyDirectory(from, to); } }
throws ExecutionException, IOException { Preconditions.checkArgument( !FileUtils.isFileInDirectory(outputFile, mCacheDirectory), String.format( "Output file/directory '%1$s' must not be located" outputFile.getAbsolutePath(), mCacheDirectory.getAbsolutePath())); Preconditions.checkArgument( !FileUtils.isFileInDirectory(mCacheDirectory, outputFile), String.format( "Output directory '%1$s' must not contain the cache directory '%2$s'",