/** * Copies a file to a new location preserving the file date. This method copies the contents of the specified source file to the specified destination * file. The directory holding the destination file is created if it does not exist. If the destination file exists, then this method will overwrite it. * * @param srcFile an existing file to copy, must not be <code>null</code> * @param destFile the new file, must not be <code>null</code> * @throws Fabric3Exception if an IO error occurs during copying */ public static void copyFile(File srcFile, File destFile) throws Fabric3Exception { copyFile(srcFile, destFile, true); }
@SuppressWarnings("ResultOfMethodCallIgnored") private void createDirectories() throws FabricException { // clear out the tmp directory if (tempDirectory.exists()) { FileHelper.cleanDirectory(tempDirectory); } tempDirectory.mkdirs(); extensionsDirectory.mkdirs(); dataDirectory.mkdirs(); }
/** * Recursively schedule directory for deletion on JVM exit. * * @param directory directory to delete, must not be <code>null</code> * @throws NullPointerException if the directory is <code>null</code> * @throws Fabric3Exception in case deletion is unsuccessful */ private static void deleteDirectoryOnExit(File directory) throws Fabric3Exception { if (!directory.exists()) { return; } cleanDirectoryOnExit(directory); directory.deleteOnExit(); }
/** * Creates a new read-write runtime directory * * @param sourceConfigDir the configuration directory to use as a template * @param targetDir the target runtime directory */ public static void cloneRuntimeImage(File sourceConfigDir, File targetDir) { File targetConfigDir = new File(targetDir, "config"); FileHelper.forceMkdir(targetConfigDir); FileHelper.copyDirectory(sourceConfigDir, targetConfigDir); FileHelper.forceMkdir(new File(targetDir, "data")); File targetDeployDir = new File(targetDir, "deploy"); FileHelper.forceMkdir(targetDeployDir); File sourceDeployDir = new File(targetConfigDir.getParent(), "deploy"); FileHelper.copyDirectory(sourceDeployDir, targetDeployDir); File repository = new File(targetDir, "repository"); FileHelper.forceMkdir(repository); FileHelper.forceMkdir(new File(repository, "runtime")); FileHelper.forceMkdir(new File(repository, "user")); FileHelper.forceMkdir(new File(targetDir, "tmp")); }
public Fabric stop() throws FabricException { if (state != State.RUNNING && state != State.STARTED) { throw new IllegalStateException("Not in started or running state: " + state); } coordinator.shutdown(); state = State.UNINITIALIZED; if (tempDirectory.exists()) { try { FileHelper.cleanDirectory(tempDirectory); } catch (Fabric3Exception e) { //noinspection StatementWithEmptyBody if (e.getCause() instanceof IOException) { // Classloader on Windows does not release locks on JAR files, ignore } if (tempDirectory.exists()) { FileHelper.forceDeleteOnExit(tempDirectory); } } } return this; }
@Init public void init() throws IOException { if (tempDir.exists()) { FileHelper.deleteDirectory(tempDir); } tempDir.mkdirs(); }
for (File file : files) { try { forceDeleteOnExit(file); } catch (Fabric3Exception ioe) { exception = ioe;
/** * Copies a whole directory to a new location preserving the file dates. This method copies the specified directory and all its child directories and files * to the specified destination. The destination is the new location and name of the directory. The destination directory is created if it does not exist. * If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence. * * @param srcDir an existing directory to copy, must not be <code>null</code> * @param destDir the new directory, must not be <code>null</code> * @throws Fabric3Exception if an IO error occurs during copying * @since Commons IO 1.1 */ public static void copyDirectory(File srcDir, File destDir) throws Fabric3Exception { copyDirectory(srcDir, destDir, true); }
/** * Copies a file to a directory preserving the file date. This method copies the contents of the specified source file to a file of the same name in the * specified destination directory. The destination directory is created if it does not exist. If the destination file exists, then this method will * overwrite it. * * @param srcFile an existing file to copy, must not be <code>null</code> * @param destDir the directory to place the copy in, must not be <code>null</code> * @throws Fabric3Exception if an IO error occurs during copying */ public static void copyFileToDirectory(File srcFile, File destDir) throws Fabric3Exception { copyFileToDirectory(srcFile, destDir, true); }
/** * Delete a file. If file is a directory, delete it and all sub-directories. * * @param file file or directory to delete, not null * @throws Fabric3Exception in case deletion is unsuccessful */ public static void forceDelete(File file) throws Fabric3Exception { if (file.isDirectory()) { deleteDirectory(file); } else { if (!file.exists()) { throw new Fabric3Exception("File does not exist: " + file); } if (!file.delete()) { String message = "Unable to delete file: " + file; throw new Fabric3Exception(message); } } }
/** * Copies a directory to within another directory preserving the file dates. This method copies the source directory and all its contents to a directory of * the same name in the specified destination directory. The destination directory is created if it does not exist. If the destination directory did exist, * then this method merges the source with the destination, with the source taking precedence. * * @param srcDir an existing directory to copy, must not be <code>null</code> * @param destDir the directory to place the copy in, must not be <code>null</code> * @throws Fabric3Exception if an IO error occurs during copying */ public static void copyDirectoryToDirectory(File srcDir, File destDir) throws Fabric3Exception { if (srcDir == null) { throw new NullPointerException("Source must not be null"); } if (!(srcDir.exists() && srcDir.isDirectory())) { throw new IllegalArgumentException("Source '" + destDir + "' is not a directory"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!(destDir.exists() && destDir.isDirectory())) { throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory"); } copyDirectory(srcDir, new File(destDir, srcDir.getName()), true); }
public void archive(File file, File archiveDirectory) throws IOException { File destFile = new File(archiveDirectory, file.getName()); FileHelper.copyFile(file, destFile); file.delete(); } }
/** * Recursively delete a directory. * * @param directory directory to delete * @throws Fabric3Exception in case deletion is unsuccessful */ public static void deleteDirectory(File directory) throws Fabric3Exception { if (!directory.exists()) { return; } cleanDirectory(directory); if (!directory.delete()) { String message = "Unable to delete directory " + directory + "."; throw new Fabric3Exception(message); } }
public void error(File file, File errorDirectory, Exception e) throws IOException { FileHelper.copyFile(file, new File(errorDirectory, file.getName())); file.delete(); }
/** * Copies a file to a directory optionally preserving the file date. This method copies the contents of the specified source file to a file of the same * name in the specified destination directory. The destination directory is created if it does not exist. If the destination file exists, then this method * will overwrite it. * * @param srcFile an existing file to copy, must not be <code>null</code> * @param destDir the directory to place the copy in, must not be <code>null</code> * @param preserveFileDate true if the file date of the copy should be the same as the original * @throws Fabric3Exception if an IO error occurs during copying * @since Commons IO 1.3 */ public static void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate) throws Fabric3Exception { if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!(destDir.exists() && destDir.isDirectory())) { throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory"); } copyFile(srcFile, new File(destDir, srcFile.getName()), preserveFileDate); }
@SuppressWarnings("ResultOfMethodCallIgnored") private void roll() throws IOException { if (strategy.checkRoll(file)) { stream.close(); File backup = strategy.getBackup(file); FileHelper.copyFile(file, backup); file.delete(); initializeChannel(); } }
@SuppressWarnings("ResultOfMethodCallIgnored") private void roll() throws IOException { if (strategy.checkRoll(file)) { stream.close(); File backup = strategy.getBackup(file); FileHelper.copyFile(file, backup); file.delete(); initializeChannel(); } }