List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:ch.unibas.fittingwizard.presentation.MoleculeListPage.java
private File copyFilesToMoleculesDir(File selectedDir, File xyzFile) { boolean isAlreadyInMoleculeDir = moleculeDir.contains(selectedDir); if (!isAlreadyInMoleculeDir) { logger.info("Molecule files are not in molecules directory. Copying files to directory."); try {/*from ww w . ja v a 2s. c o m*/ FileUtils.copyDirectoryToDirectory(selectedDir, moleculeDir.getDirectory()); FileUtils.copyFileToDirectory(xyzFile, moleculeDir.getDirectory()); } catch (IOException e) { throw new RuntimeException("Could not copy files to molecule directory."); } } return xyzFile; }
From source file:dk.nsi.sdm4.dosering.parser.DoseringParserIntegrationTest.java
public void runImporter() throws Exception { File datasetDir = tmpDir.newFolder(); FileUtils.copyFileToDirectory(versionFile, datasetDir); FileUtils.copyFileToDirectory(drugsFile, datasetDir); FileUtils.copyFileToDirectory(dosageStructureFile, datasetDir); FileUtils.copyFileToDirectory(unitsFile, datasetDir); FileUtils.copyFileToDirectory(relationFile, datasetDir); parser.process(datasetDir, ""); }
From source file:com.cprassoc.solr.auth.SolrAuthActionController.java
public static String doPushConfigToSolrAction(SecurityJson json) { String result = ""; try {/*from w w w. jav a2 s . c om*/ String mime = "sh"; if (Utils.isWindows()) { mime = "bat"; } String pathToScript = System.getProperty("user.dir") + File.separator + "solrAuth." + mime; String jsonstr = json.export(); String filePath = SolrAuthManager.getProperties().getProperty("solr.install.path") + File.separator + "security.json"; File backup = new File("backup"); if (!backup.exists()) { backup.mkdirs(); } File file = new File(filePath); if (file.exists()) { // String newFilePath = SolrAuthManager.getProperties().getProperty("solr.install.path") + File.separator + System.currentTimeMillis() + "_security.json"; // File newFile = new File(newFilePath); // file.renameTo(newFile); FileUtils.copyFileToDirectory(file, backup); } FileUtils.writeByteArrayToFile(file, jsonstr.getBytes()); Thread.sleep(500); ProcessBuilder pb = new ProcessBuilder(pathToScript); Log.log("Run PUSH command"); Process process = pb.start(); if (process.waitFor() == 0) { result = ""; } else { result = Utils.streamToString(process.getErrorStream()); result += "\n" + Utils.streamToString(process.getInputStream()); Log.log(result); } } catch (Exception e) { e.printStackTrace(); result = e.getLocalizedMessage(); } return result; }
From source file:fm.last.commons.io.LastFileUtilsTest.java
@Test(expected = FileNotFoundException.class) public void testMoveFileToDirectorySafely_NoCreateDir() throws IOException { // first copy file from data folder to temp folder so it can be moved safely File originalFile = dataFolder.getFile("3805bytes.log"); FileUtils.copyFileToDirectory(originalFile, tempFolder.getRoot()); File inputFile = new File(tempFolder.getRoot(), originalFile.getName()); assertTrue(inputFile.getAbsolutePath() + " not found", inputFile.exists()); // now do the actual moving File newDir = new File(tempFolder.getRoot(), "FileUtilsTest"); assertFalse(newDir.exists()); // dir must not exist // copy file over to newdir, NOT creating dir if it doesn't exist LastFileUtils.moveFileToDirectorySafely(inputFile, newDir, false); }
From source file:it.greenvulcano.util.file.FileManager.java
/** * Copy the file/directory to a new one.<br> * The filePattern may be a regular expression: in this case, all the filenames * matching the pattern will be copied to the target directory.<br> * If a file, whose name matches the <code>filePattern</code> pattern, already * exists in the same target directory, it will be overwritten.<br> * * @param sourcePath/*w w w . j av a 2 s . c om*/ * Absolute pathname of the source file/directory. * @param targetPath * Absolute pathname of the target file/directory. * @param filePattern * A regular expression defining the name of the files to be copied. Used only if * srcPath identify a directory. Null or "" disable file filtering. * @throws Exception */ public static void cp(String sourcePath, String targetPath, String filePattern) throws Exception { File src = new File(sourcePath); if (!src.isAbsolute()) { throw new IllegalArgumentException("The pathname of the source file is NOT absolute: " + sourcePath); } File target = new File(targetPath); if (!target.isAbsolute()) { throw new IllegalArgumentException("The pathname of the target file is NOT absolute: " + targetPath); } if (src.isDirectory()) { if ((filePattern == null) || filePattern.equals("") || filePattern.equals(".*")) { logger.debug( "Copying directory " + src.getAbsolutePath() + " to directory " + target.getAbsolutePath()); FileUtils.copyDirectory(src, new File(targetPath)); } else { Set<FileProperties> files = ls(sourcePath, filePattern); for (FileProperties file : files) { logger.debug("Copying file " + file.getName() + " from directory " + src.getAbsolutePath() + " to directory " + target.getAbsolutePath()); if (file.isDirectory()) { FileUtils.copyDirectoryToDirectory(new File(src, file.getName()), target); } else { FileUtils.copyFileToDirectory(new File(src, file.getName()), target); } } } } else { if (target.isDirectory()) { logger.debug("Copying file " + src.getAbsolutePath() + " to directory " + target.getAbsolutePath()); FileUtils.copyFileToDirectory(src, target); } else { logger.debug("Copying file " + src.getAbsolutePath() + " to " + target.getAbsolutePath()); FileUtils.copyFile(src, target); } } }
From source file:ml.shifu.shifu.core.processor.ManageModelProcessor.java
/** * save model to back_models folder//w ww . ja va 2 s . c om * * @param modelName * @throws IOException */ private void saveModel(String modelName) throws IOException { if (modelName == null) { modelName = getCurrentModelName(); } else { //tell shifu switch to modelName File file = new File("./.HEAD"); BufferedWriter writer = null; try { FileUtils.deleteQuietly(file); writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(file), Constants.DEFAULT_CHARSET)); writer.write(modelName); } catch (IOException e) { log.info("Fail to rewrite HEAD file"); } finally { if (writer != null) { writer.close(); } } } log.info("The current model will be saved to {} folder", modelName); File configFolder = new File(Constants.BACKUPNAME + File.separator + modelName); try { if (configFolder.exists()) { log.info("The model {} folder exists, it will be replaced by current model", modelName); FileUtils.deleteDirectory(configFolder); } } catch (IOException e) { log.error("Fail to delete historical folder, please manually delete it : {}", configFolder.getAbsolutePath()); } FileUtils.forceMkdir(configFolder); // copy configs File modelFile = new File("./ModelConfig.json"); File columnFile = new File("./ColumnConfig.json"); try { FileUtils.copyFileToDirectory(modelFile, configFolder); if (columnFile.exists()) { FileUtils.copyFileToDirectory(columnFile, configFolder); } } catch (IOException e) { log.error("Fail in copy config file"); } // copy models File modelFolder = new File(Constants.BACKUPNAME + File.separator + modelName + File.separator + "models"); FileUtils.forceMkdir(modelFolder); File currentModelFoler = new File("models"); if (currentModelFoler.isDirectory()) { File[] files = currentModelFoler.listFiles(new FileFilter() { @Override public boolean accept(File file) { return file.isFile() && file.getName().startsWith("model"); } }); if (files != null) { for (File model : files) { try { FileUtils.copyFileToDirectory(model, modelFolder); } catch (IOException e) { log.error("Fail in copy model file, source: {}", model.getAbsolutePath()); } } } else { throw new IOException( String.format("Failed to list files in %s", currentModelFoler.getAbsolutePath())); } log.info("Save model: {} successfully", modelName); } else { log.error("Save model: {} failed", modelName); log.error("{} does not exist or not a directory!", currentModelFoler.getAbsolutePath()); } }
From source file:net.cliseau.composer.javatarget.InstrumentationException.java
/** * Copy a list of files to a given directory. * * This method is used internally to copy the dependencies to the directory * of the encapsulated target.//from w ww . ja v a 2s .c o m * * @param fileNames Array of files to copy. * @param destDir Destination directory. */ private static void copyFiles(Collection<String> fileNames, File destDir) throws IOException { for (final String f : fileNames) { FileUtils.copyFileToDirectory(new File(f), destDir); } }
From source file:es.urjc.mctwp.image.management.ImageCollectionManager.java
/** * This function knows how to retrieve all files of any image and * puts all together under a temporal directory. It reproduces * subdirectories when necessary.//from w w w . j a va2 s. com * * @param directory * @param image * @throws IOException */ private void copyToDirectory(File directory, Image image) throws IOException { if (image instanceof SingleImage) { FileUtils.copyFileToDirectory(((SingleImage) image).getContent(), directory); } else { //Create temp directory where put all file content of Image File tmpDir = new File(FilenameUtils.concat(directory.getAbsolutePath(), image.getId())); if (tmpDir.exists()) tmpDir.mkdir(); //Copy required files in case of Series Images if (image instanceof SeriesImage) { List<Image> images = ((SeriesImage) image).getImages(); if (images != null && !images.isEmpty()) for (Image img : images) copyToDirectory(tmpDir, img); //Copy required files in case of Complex Images } else if (image instanceof ComplexImage) { List<File> aux = ((ComplexImage) image).getContent(); if (aux != null) for (File file : aux) copyToDirectory(tmpDir, file); } } }
From source file:com.k_joseph.apps.multisearch.solr.AddCustomFieldsToSchema.java
/** * Overwrites the previous schema file with the newly generated * /* w w w . ja va2 s . com*/ * @param previousSchema currently used schema file * @param newSchema to be used instead of the previous */ private static void copyNewSchemaFileToPreviouslyUsed(String previousSchema, String newSchema) { File previousSchemaFile = new File(previousSchema); File newSchemaFile = new File(newSchema); if (previousSchemaFile.exists() && newSchemaFile.exists()) { String chartSearchBackUpPath = System.getProperty("user.home") + File.separator + ".multiSearch" + File.separator + "backup"; File chartSearchBackUp = new File(chartSearchBackUpPath); if (!chartSearchBackUp.exists()) { chartSearchBackUp.mkdir(); } previousSchemaFile.delete(); newSchemaFile.renameTo(previousSchemaFile); try { //Backing up the new schema file for easy retrieval after restarting or upgrading the module //TODO support an option clickat the UI where by the user can Reload the solrserver, //this would mean updating the schema file with back-up before the Reloading is done FileUtils.copyFileToDirectory(newSchemaFile, chartSearchBackUp); } catch (IOException e) { System.out.println("Error generated" + e); } } }
From source file:com.mortardata.project.EmbeddedMortarProject.java
String syncEmbeddedProjectWithMirror(Git gitMirror, CredentialsProvider cp, String targetBranch, String committer) throws GitAPIException, IOException { // checkout the target branch gitUtil.checkout(gitMirror, targetBranch); // clear out the mirror directory contents (except .git and .gitkeep) File localBackingGitRepoPath = gitMirror.getRepository().getWorkTree(); for (File f : FileUtils.listFilesAndDirs(localBackingGitRepoPath, FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".gitkeep")), FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter(".git")))) { if (!f.equals(localBackingGitRepoPath)) { logger.debug("Deleting existing mirror file" + f.getAbsolutePath()); FileUtils.deleteQuietly(f);// w w w . j ava 2s . co m } } // copy everything from the embedded project List<File> manifestFiles = getFilesAndDirsInManifest(); for (File fileToCopy : manifestFiles) { if (!fileToCopy.exists()) { logger.warn("Can't find file or directory " + fileToCopy.getCanonicalPath() + " referenced in manifest file. Ignoring."); } else if (fileToCopy.isDirectory()) { FileUtils.copyDirectoryToDirectory(fileToCopy, localBackingGitRepoPath); } else { FileUtils.copyFileToDirectory(fileToCopy, localBackingGitRepoPath); } } // add everything logger.debug("git add ."); gitMirror.add().addFilepattern(".").call(); // remove missing files (deletes) logger.debug("git add -u ."); gitMirror.add().setUpdate(true).addFilepattern(".").call(); // commit it logger.debug("git commit"); RevCommit revCommit = gitMirror.commit().setCommitter(committer, committer) .setMessage("mortar development snapshot commit").call(); return ObjectId.toString(revCommit); }