List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:com.github.licanhua.test.framework.AbstractWebDriverProvider.java
public void takesScreenshot(WebDriverContext webDriverContext) { if (!webDriverContext.isAutoSnapshot()) { logger.debug("autoSnapshot is disabled. skip the snapshot"); return;/*from w w w .j a va 2 s . co m*/ } String path = TEST_OUT + driverTimeStamp + "/" + testName + "/" + snapCount++; logger.info("Snapshot to : " + path); WebDriver webDriver = webDriverContext.getWebDriver(); File screenshotAs = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE); try { FileUtils.copyFile(screenshotAs, new File(path + "-screenshot.png")); FileUtils.writeStringToFile(new File(path + "-source.html"), webDriver.getPageSource(), Charset.defaultCharset(), false); } catch (IOException e) { logger.error("Fail to save snapshot", e); } }
From source file:com.orange.ocara.model.export.docx.AuditDocxExporter.java
private void copyAuditObjectIcon(AuditObject auditObject, File iconDir) throws IOException { File from = new File(auditObject.getObjectDescription().getIcon()); String extension = FilenameUtils.getExtension(from.getPath()); File to = new File(iconDir, String.format("%s.%s", auditObject.getObjectDescriptionId(), extension)); FileUtils.copyFile(from, to); }
From source file:jfix.db4o.engine.PersistenceEngineXStream.java
public void backup() { try {/* w ww. j a v a 2 s.c om*/ String backupFilename = filename + new SimpleDateFormat("-yyyyMMdd").format(new Date()); FileUtils.copyFile(new File(filename), new File(backupFilename)); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.googlecode.promnetpp.translation.templates.Template.java
public void copyStaticFiles() throws IOException { for (String fileName : staticFileNames) { String fileLocation = MessageFormat.format("{0}/templates/{1}/{2}", System.getProperty("promnetpp.home"), name, fileName); FileUtils.copyFile(new File(fileLocation), new File(Options.outputDirectory + "/" + fileName)); }//w w w. ja v a 2 s .c o m }
From source file:de.cismet.cids.custom.utils.vermessungsunterlagen.tasks.VermUntTaskPNR.java
@Override protected void performTask() throws VermessungsunterlagenTaskException { if (vermessungsstelle == null) { final File src = new File( VermessungsunterlagenHelper.getInstance().getProperties().getAbsPathPdfPnrVermstelle()); final File dst = new File(getPath() + "/" + src.getName()); if (!dst.exists()) { try { FileUtils.copyFile(src, dst); } catch (final Exception ex) { final String message = "Beim Kopieren des PNR-Informations-PDFs kam es zu einem unerwarteten Fehler."; throw new VermessungsunterlagenTaskException(getType(), message, ex); }//from w ww . j a va2 s . com } } else { if (punktnummernreservierungBeans != null) { final Collection reservations = getReservations(); boolean first = (reservations == null) || reservations.isEmpty(); for (final VermessungsunterlagenAnfrageBean.PunktnummernreservierungBean bean : punktnummernreservierungBeans) { if (bean.getAnzahlPunktnummern() > 0) { try { final PointNumberReservationRequest result = doReservation(bean, !first); if (result != null) { final String protokoll = getProtokoll(result); final String filename = getPath() + "/" + auftragsnummer + "_" + bean.getUtmKilometerQuadrat() + ".txt"; FileUtils.writeStringToFile(new File(filename), protokoll, "ISO-8859-1"); } first = false; } catch (final Exception ex) { final String message = "Beim Herunterladen des Punktnummernreservierungsprotokolls kam es zu einem unerwarteten Fehler."; throw new VermessungsunterlagenTaskException(getType(), message, ex); } } } } } }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.FileCopier.java
/** * Copy the given source file or directory to the given destination, keeping the same creation date as the source. * * @param sourceFileOrDirectory the source file or directory * @param destinationFileOrDirectory the destination file or directory * @throws IOException if an IO error occurs during the copy *//*from w w w.j a va2 s .c o m*/ public static void copyFileOrDirectory(final File sourceFileOrDirectory, final File destinationFileOrDirectory) throws IOException { final File parentDirectory = destinationFileOrDirectory.getParentFile(); if (!parentDirectory.exists()) { boolean success = parentDirectory.mkdirs(); if (!success) { throw new IOException("Directory '" + parentDirectory + "' was not successfully created."); } } if (sourceFileOrDirectory.isDirectory()) { FileUtils.copyDirectory(sourceFileOrDirectory, destinationFileOrDirectory); } else { FileUtils.copyFile(sourceFileOrDirectory, destinationFileOrDirectory); } }
From source file:com.aniruddhc.acemusic.player.AsyncTasks.AsyncCopyMoveTask.java
@Override protected Boolean doInBackground(String... params) { try {/* w ww. j av a2 s. c om*/ if (mSourceFile.getCanonicalPath() == mDestinationFile.getCanonicalPath()) { Toast.makeText(mContext, R.string.source_target_same, Toast.LENGTH_LONG).show(); return false; } } catch (Exception e) { return false; } if (mSourceFile.isDirectory()) { try { if (mShouldMove) FileUtils.moveDirectoryToDirectory(mSourceFile, mDestinationFile, true); else FileUtils.copyDirectoryToDirectory(mSourceFile, mDestinationFile); } catch (Exception e) { return false; } } else { try { if (mShouldMove) FileUtils.moveFileToDirectory(mSourceFile, mDestinationFile, true); else FileUtils.copyFile(mSourceFile, mDestinationFile); } catch (Exception e) { return false; } } return true; }
From source file:com.alta189.cyborg.api.plugin.CommonPluginManager.java
public synchronized Plugin loadPlugin(File paramFile, boolean ignoresoftdepends) throws InvalidPluginException, InvalidDescriptionFileException, UnknownDependencyException { File update = null;//from w ww . j a va 2s . c om if (updateDir != null && updateDir.isDirectory()) { update = new File(updateDir, paramFile.getName()); if (update.exists() && update.isFile()) { try { FileUtils.copyFile(update, paramFile); } catch (IOException e) { CyborgLogger.getLogger().log(Level.SEVERE, new StringBuilder().append("Error copying file '").append(update.getPath()) .append("' to its new destination at '").append(paramFile.getPath()) .append("': ").append(e.getMessage()).toString(), e); } update.delete(); } } Set<Pattern> patterns = loaders.keySet(); Plugin result = null; for (Pattern pattern : patterns) { String name = paramFile.getName(); Matcher m = pattern.matcher(name); if (m.find()) { PluginLoader loader = loaders.get(pattern); result = loader.loadPlugin(paramFile, ignoresoftdepends); if (result != null) { break; } } } if (result != null) { plugins.add(result); names.put(result.getDescription().getName(), result); } return result; }
From source file:net.ontopia.topicmaps.db2tm.DB2TMRescanTestCase.java
@Test public void testFile() throws IOException { TestFileUtils.verifyDirectory(base, "out"); String name = filename.substring(0, filename.length() - ".xml".length()); // Path to the config file. File cfg = TestFileUtils.getTransferredTestInputFile(testdataDirectory, "in/rescan", filename); // Path to the topic map seed. String in = TestFileUtils.getTestInputFile(testdataDirectory, "in/rescan", name + ".ltm"); // Path to the cxtm version of the output topic map. File cxtm = TestFileUtils.getTestOutputFile(testdataDirectory, "out", "rescan-" + name + ".cxtm"); // Path to the baseline. String baseline = TestFileUtils.getTestInputFile(testdataDirectory, "baseline", "rescan-" + name + ".cxtm"); // Import the topic map seed. TopicMapIF topicmap = ImportExportUtils.getReader(in).read(); LocatorIF baseloc = topicmap.getStore().getBaseAddress(); // Run DB2TM processes RelationMapping mapping = RelationMapping.read(cfg); // Prepare files File target = TestFileUtils.getTestOutputFile(testdataDirectory, "in", "rescan", name + ".csv"); File before = TestFileUtils.getTestOutputFile(testdataDirectory, "in", "rescan", name + "-before.csv"); File after = TestFileUtils.getTestOutputFile(testdataDirectory, "in", "rescan", name + "-after.csv"); // Copy before-file FileUtils.copyFile(before, target); // Add relations topic topicmap Processor.addRelations(mapping, null, topicmap, baseloc); // Copy after-file FileUtils.copyFile(after, target);//from w ww .ja v a2 s .c o m // Rescan relations Processor.synchronizeRelations(mapping, null, topicmap, baseloc); // Get rid of temporary target file FileUtils.forceDelete(after); // Export the result topic map to ltm, for manual inspection purposes. if (DEBUG_LTM) { File ltm = TestFileUtils.getTestOutputFile(testdataDirectory, "out", "rescan-" + name + ".ltm"); new LTMTopicMapWriter(ltm).write(topicmap); } // Export the result topic map to cxtm new CanonicalXTMWriter(cxtm).write(topicmap); // Check that the cxtm output matches the baseline. Assert.assertTrue("The canonicalized conversion from " + filename + " does not match the baseline: " + cxtm + " " + baseline, TestFileUtils.compareFileToResource(cxtm, baseline)); }
From source file:generate.MapGenerateAction.java
@Override public String execute() { String file_path = "/home/chanakya/NetBeansProjects/Concepto/UploadedFiles"; try {/*www . j a v a 2 s.c om*/ File fileToCreate = new File(file_path, concept_map.getUploadedFileFileName()); FileUtils.copyFile(concept_map.getUploadedFile(), fileToCreate); } catch (Throwable t) { System.out.println("E1: " + t.getMessage()); return ERROR; } try { List<String> temp_text = FileUtils.readLines(concept_map.getUploadedFile()); StringBuilder text = new StringBuilder(); for (String s : temp_text) { text.append(s); } concept_map.setInput_text(text.toString()); } catch (IOException e) { //e.printStackTrace(); System.out.println("E2: " + e.getMessage()); return ERROR; } String temp_filename = concept_map.getUploadedFileFileName().split("\\.(?=[^\\.]+$)")[0]; temp_filename = temp_filename.trim(); try { String temp = "java -jar /home/chanakya/NetBeansProjects/Concepto/src/java/generate/MajorCore.jar " + file_path + " " + temp_filename; System.out.println(temp); File jarfile = new File("/home/chanakya/NetBeansProjects/Concepto/src/java/generate/MajorCore.jar"); JarFile jar = new JarFile(jarfile); Manifest manifest = jar.getManifest(); Attributes attrs = manifest.getMainAttributes(); String mainClassName = attrs.getValue(Attributes.Name.MAIN_CLASS); System.out.println(mainClassName); URL url = new URL("file", null, jarfile.getAbsolutePath()); ClassLoader cl = new URLClassLoader(new URL[] { url }); Class mainClass = cl.loadClass(mainClassName); Method mainMethod = mainClass.getMethod("main", new Class[] { String[].class }); String[] args = new String[2]; args[0] = file_path; args[1] = temp_filename; System.out.println(args[0]); System.out.println(args[1]); try { mainMethod.invoke(mainClass, new Object[] { args }); } catch (InvocationTargetException e) { System.out.println("This is the exception: " + e.getTargetException().toString()); } } catch (IllegalArgumentException | IllegalAccessException | NoSuchMethodException | ClassNotFoundException | IOException e) { System.out.println("E3: " + e.getMessage()); return ERROR; } try { String temp2 = "java -jar /home/chanakya/NetBeansProjects/Concepto/src/java/generate/MajorCoreII.jar " + file_path + " " + temp_filename; System.out.println(temp2); File jarfile = new File("/home/chanakya/NetBeansProjects/Concepto/src/java/generate/MajorCoreII.jar"); JarFile jar = new JarFile(jarfile); Manifest manifest = jar.getManifest(); Attributes attrs = manifest.getMainAttributes(); String mainClassName = attrs.getValue(Attributes.Name.MAIN_CLASS); System.out.println(mainClassName); URL url = new URL("file", null, jarfile.getAbsolutePath()); ClassLoader cl = new URLClassLoader(new URL[] { url }); Class mainClass = cl.loadClass(mainClassName); Method mainMethod = mainClass.getMethod("main", new Class[] { String[].class }); String[] args = new String[2]; args[0] = file_path; args[1] = temp_filename; mainMethod.invoke(mainClass, new Object[] { args }); } catch (InvocationTargetException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException | ClassNotFoundException | IOException e) { System.out.println("E4: " + e.getMessage()); return ERROR; } String cmd = "python /home/chanakya/NetBeansProjects/Concepto/src/java/generate/add_to_graph.py \"/home/chanakya/NetBeansProjects/Concepto/UploadedFiles/" + temp_filename + "_OllieOutput.txt\""; String[] finalCommand; finalCommand = new String[3]; finalCommand[0] = "/bin/sh"; finalCommand[1] = "-c"; finalCommand[2] = cmd; System.out.println("CMD: " + cmd); try { //ProcessBuilder builder = new ProcessBuilder(finalCommand); //builder.redirectErrorStream(true); //Process process = builder.start(); Process process = Runtime.getRuntime().exec(finalCommand); int exitVal = process.waitFor(); System.out.println("Process exitValue2: " + exitVal); } catch (Throwable t) { System.out.println("E5: " + t.getMessage()); return ERROR; } cmd = "python /home/chanakya/NetBeansProjects/Concepto/src/java/generate/json_correct.py"; finalCommand = new String[3]; finalCommand[0] = "/bin/sh"; finalCommand[1] = "-c"; finalCommand[2] = cmd; try { //Process process = Runtime.getRuntime().exec(finalCommand); ProcessBuilder builder = new ProcessBuilder(finalCommand); // builder.redirectErrorStream(true); Process process = builder.start(); int exitVal = process.waitFor(); System.out.println("Process exitValue3: " + exitVal); } catch (Throwable t) { System.out.println("E6: " + t.getMessage()); return ERROR; } try { List<String> temp_text_1 = FileUtils .readLines(FileUtils.getFile("/home/chanakya/NetBeansProjects/Concepto/web", "new_graph.json")); StringBuilder text_1 = new StringBuilder(); for (String s : temp_text_1) { text_1.append(s); } concept_map.setOutput_text(text_1.toString()); } catch (IOException e) { System.out.println("E7: " + e.getMessage()); return ERROR; } Random rand = new Random(); int unique_id = rand.nextInt(99999999); System.out.println("Going In DB"); try { MongoClient mongo = new MongoClient(); DB db = mongo.getDB("Major"); DBCollection collection = db.getCollection("ConceptMap"); BasicDBObject document = new BasicDBObject(); document.append("InputText", concept_map.getInput_text()); document.append("OutputText", concept_map.getOutput_text()); document.append("ChapterName", concept_map.getChapter_name()); document.append("ChapterNumber", concept_map.getChapter_number()); document.append("SectionName", concept_map.getSection_name()); document.append("SectionNumber", concept_map.getSection_number()); document.append("UniqueID", Integer.toString(unique_id)); collection.insert(document); //collection.save(document); } catch (MongoException e) { System.out.println("E8: " + e.getMessage()); return ERROR; } catch (UnknownHostException ex) { Logger.getLogger(MapGenerateAction.class.getName()).log(Level.SEVERE, null, ex); System.out.println("E9"); return ERROR; } System.out.println("Out DB"); return SUCCESS; }