List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:de.rub.syssec.saaf.analysis.steps.extract.ApkUnzipper.java
/** * Copies the given file into the given destination directory * /*from w w w .j a v a 2 s . c o m*/ * @param archive * - the file to copy * @param dest * - the destination directory * @throws IOException */ public static void copyApk(File archive, File dest) throws IOException { File destination = new File(dest, archive.getName()); FileUtils.copyFile(archive, destination); }
From source file:cat.calidos.morfeu.webapp.DocumentSaveUITest.java
@Before public void setup() throws Exception { String contentPath = "test-resources/documents/document1.xml"; String fullContentPath = testAwareFullPathFrom(contentPath); contentFile = new File(new URL(fullContentPath).getFile()); String tmpPath = setupTempDirectory() + "/document1.xml.backup"; backupFile = new File(tmpPath); // System.err.println("\t"+contentFile+" ->"+backupFile); FileUtils.copyFile(contentFile, backupFile); }
From source file:com.zapprx.testing.end2endtests.automation.utils.TakeScreenshot.java
public void takeScreenshot() { screenshotPath = (getProperty("screenshot-path") != null) ? getProperty("screenshot-path") : screenshotPath; DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss_ms"); Date date = new Date(); String date_time = dateFormat.format(date); File file = new File(System.getProperty("user.dir") + File.separator + screenshotPath + File.separator + this.testname + File.separator + date_time); boolean exists = file.exists(); if (!exists) { new File(System.getProperty("user.dir") + File.separator + screenshotPath + File.separator + this.testname + File.separator + date_time).mkdir(); }//from w w w.ja va 2 s .c om File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); try { String saveImgFile = System.getProperty("user.dir") + File.separator + screenshotPath + File.separator + this.testname + File.separator + date_time + File.separator + "screenshot.png"; Reporter.log("Save Image File Path : " + saveImgFile, true); FileUtils.copyFile(scrFile, new File(saveImgFile)); } catch (IOException e) { e.printStackTrace(); } }
From source file:net.sourceforge.atunes.utils.TempFolder.java
@Override public File addFile(final File srcFile, final String name) { File destFile = new File(StringUtils.getString(this.osManager.getTempFolder(), this.osManager.getFileSeparator(), name, ".", FilenameUtils.getExtension(srcFile.getName()))); try {/* w ww . j a v a2 s .c o m*/ FileUtils.copyFile(srcFile, destFile); } catch (IOException e) { return null; } return destFile; }
From source file:com.digitalgeneralists.assurance.model.merge.BidirectionalMergeEngine.java
@Override public void mergeResult(ComparisonResult result, IProgressMonitor monitor) { File sourceFile = result.getSource().getFile(); File targetFile = result.getTarget().getFile(); if (monitor != null) { StringBuilder message = new StringBuilder(512); monitor.publish(message.append("Merging ").append(targetFile.toString()).append(" to ") .append(sourceFile.toString()).toString()); message.setLength(0);/*from w w w . j a v a2s. c om*/ message = null; } if (sourceFile.exists()) { try { if (sourceFile.isDirectory()) { FileUtils.copyDirectory(sourceFile, targetFile); } else { FileUtils.copyFile(sourceFile, targetFile); } result.setResolution(AssuranceResultResolution.REPLACE_TARGET); } catch (IOException e) { logger.error("An error occurred when replacing the target with the source."); result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } } else { if (targetFile.exists()) { try { if (targetFile.isDirectory()) { FileUtils.copyDirectory(targetFile, sourceFile); } else { FileUtils.copyFile(targetFile, sourceFile); } result.setResolution(AssuranceResultResolution.REPLACE_SOURCE); } catch (IOException e) { logger.error("An error occurred when replacing the source with the target."); result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } } } sourceFile = null; targetFile = null; }
From source file:hu.bme.mit.trainbenchmark.generator.rdf.RDFGenerator.java
@Override public void initModel() throws IOException { // source file (DDL operations) final String srcFilePath = generatorConfig.getWorkspacePath() + "/hu.bme.mit.trainbenchmark.rdf/src/main/resources/metamodel/header.ttl"; final File srcFile = new File(srcFilePath); // destination file final String destFilePath = generatorConfig.getModelPathNameWithoutExtension() + ".ttl"; final File destFile = new File(destFilePath); // this overwrites the destination file if it exists FileUtils.copyFile(srcFile, destFile); file = new BufferedWriter(new FileWriter(destFile, true)); }
From source file:FileTransferPackage.ConfigFileUpload.java
public String uploadRootCACredentials() { String path = getServletRequest().getSession().getServletContext().getRealPath("/"); File certFile = new File(path + "Security/Certificates/Root_CA/root_cert.pem"); File publicFile = new File(path + "Security/Keystore/Root_CA/publicKey.key"); File privateFile = new File(path + "Security/Keystore/Root_CA/privateKey.key"); if (certFile.exists()) { certFile.delete();// w ww. ja v a 2 s. c o m } if (publicFile.exists()) { publicFile.delete(); } if (privateFile.exists()) { privateFile.delete(); } try { FileUtils.copyFile(getRootCertFile(), certFile); FileUtils.copyFile(getRootPubFile(), publicFile); FileUtils.copyFile(getRootPrivFile(), privateFile); } catch (IOException ex) { Logger.getLogger(ConfigFileUpload.class.getName()).log(Level.SEVERE, null, ex); } return SUCCESS; }
From source file:controllers.UploadImages.java
/** * Upload une image sur le serveur//from w ww . j a v a 2 s. c o m * @param filePart : l'image uploader * @param reponse : une rponse laquelle appartient l'image qu'on uploade * @return VRAI si cela s'est droul avec succs, FAUX sinon */ static boolean upload(FilePart filePart, Reponse reponse) { if (isImage(filePart)) { File image = filePart.getFile(); String fileName = filePart.getFilename(); Image i = new Image(fileName); File destinationFile = new File( play.Play.application().path().getAbsolutePath() + "/img/" + i.fileName); System.out.println(play.Play.application().path().getAbsolutePath()); System.out.println(image.getAbsolutePath()); try { FileUtils.copyFile(image, destinationFile); i.addImage(reponse); System.out.println("Image uploade avec succs !"); return true; } catch (IOException e) { e.printStackTrace(); System.out.println("Impossible de copier l'image sur le serveur..."); return false; } } else { System.out.println("Le fichier upload n'est pas image ou son format n'est pas support !"); return false; } }
From source file:hudson.plugins.git.converter.ObjectIdConverterTest.java
@Before public void setUp() throws URISyntaxException, IOException { sourceConfigFile = new File(this.getClass().getResource("build.xml").toURI()); //Create target config file in order to perform marshall operation targetConfigFile = new File(sourceConfigFile.getParent(), "target_build.xml"); FileUtils.copyFile(sourceConfigFile, targetConfigFile); }
From source file:$.MarkdownMojoTest.java
@Test public void testInitializationWithUnfilteredInternalAndExternalFilesUsingRegularExtensions() throws MojoExecutionException, IOException { MarkdownMojo mojo = new MarkdownMojo(); mojo.basedir = basedir;//from w w w. jav a 2s .com mojo.buildDirectory = new File(mojo.basedir, "target"); FileUtils.copyFile(new File("src/test/resources/hello.md"), new File(basedir, "src/main/resources/assets/doc/hello.md")); FileUtils.copyFile(new File("src/test/resources/hello.md"), new File(basedir, "src/main/assets/doc/hello.md")); mojo.execute(); final File internal = new File(mojo.getInternalAssetOutputDirectory(), "doc/hello.html"); final File external = new File(mojo.getExternalAssetsOutputDirectory(), "doc/hello.html"); assertThat(internal).isFile(); assertThat(external).isFile(); assertThat(FileUtils.readFileToString(internal)).contains("<h1>Hello, " + "Wisdom!</h1>") .contains("href=\"http://perdu.com\""); assertThat(FileUtils.readFileToString(external)).contains("<h1>Hello, " + "Wisdom!</h1>") .contains("href=\"http://perdu.com\""); }