List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:com.googlecode.promnetpp.research.main.CompareOutputMain.java
private static void doSeedRun(int seed) throws IOException, InterruptedException { System.out.println("Running with seed " + seed); String pattern = "int random = <INSERT_SEED_HERE>;"; int start = sourceCode.indexOf(pattern); int end = start + pattern.length(); String line = sourceCode.substring(start, end); line = line.replace("<INSERT_SEED_HERE>", Integer.toString(seed)); String sourceCodeWithSeed = sourceCode.replace(pattern, line); File tempFile = new File("temp.pml"); FileUtils.writeStringToFile(tempFile, sourceCodeWithSeed); //Create a "project" folder String fileNameWithoutExtension = fileName.split("[.]")[0]; File folder = new File("test1-" + fileNameWithoutExtension); if (folder.exists()) { FileUtils.deleteDirectory(folder); }//from ww w. ja v a 2s . c o m folder.mkdir(); //Copy temp.pml to our new folder FileUtils.copyFileToDirectory(tempFile, folder); //Simulate the model using Spin List<String> spinCommand = new ArrayList<String>(); spinCommand.add(GeneralData.spinHome + "/spin"); spinCommand.add("-u1000000"); spinCommand.add("temp.pml"); ProcessBuilder processBuilder = new ProcessBuilder(spinCommand); processBuilder.directory(folder); processBuilder.redirectOutput(new File(folder, "spin-" + seed + ".txt")); Process process = processBuilder.start(); process.waitFor(); //Translate via PROMNeT++ List<String> PROMNeTppCommand = new ArrayList<String>(); PROMNeTppCommand.add("java"); PROMNeTppCommand.add("-enableassertions"); PROMNeTppCommand.add("-jar"); PROMNeTppCommand.add("\"" + GeneralData.getJARFilePath() + "\""); PROMNeTppCommand.add("temp.pml"); processBuilder = new ProcessBuilder(PROMNeTppCommand); processBuilder.directory(folder); processBuilder.environment().put("PROMNETPP_HOME", GeneralData.PROMNeTppHome); process = processBuilder.start(); process.waitFor(); //Run opp_makemake FileUtils.copyFileToDirectory(new File("opp_makemake.bat"), folder); List<String> makemakeCommand = new ArrayList<String>(); if (Utilities.operatingSystemType.equals("windows")) { makemakeCommand.add("cmd"); makemakeCommand.add("/c"); makemakeCommand.add("opp_makemake.bat"); } else { throw new RuntimeException("Support for Linux/OS X not implemented" + " here yet."); } processBuilder = new ProcessBuilder(makemakeCommand); processBuilder.directory(folder); process = processBuilder.start(); process.waitFor(); //Run make FileUtils.copyFileToDirectory(new File("opp_make.bat"), folder); List<String> makeCommand = new ArrayList<String>(); if (Utilities.operatingSystemType.equals("windows")) { makeCommand.add("cmd"); makeCommand.add("/c"); makeCommand.add("opp_make.bat"); } else { throw new RuntimeException("Support for Linux/OS X not implemented" + " here yet."); } processBuilder = new ProcessBuilder(makeCommand); processBuilder.directory(folder); process = processBuilder.start(); process.waitFor(); System.out.println(Utilities.getStreamAsString(process.getInputStream())); System.exit(1); }
From source file:com.ifeng.computing.batch.job.tasklet.ArchiveLogDataImportFileTasklet.java
@Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { // Make our destination directory and copy our input file to it File archiveDir = new File("archive"); FileUtils.forceMkdir(archiveDir);/* ww w . j a va2 s .c o m*/ FileUtils.copyFileToDirectory(new File(inputFile), archiveDir); // We're done... return RepeatStatus.FINISHED; }
From source file:com.thoughtworks.go.agent.DevelopmentAgent.java
private static void copyActivatorJarToClassPath() throws IOException { File activatorJarFromTarget = new File( "../plugin-infra/go-plugin-activator/target/go-plugin-activator.jar"); File activatorJarFromMaven = new File(System.getProperty("user.home") + "/.m2/repository/com/thoughtworks/go/go-plugin-activator/1.0/go-plugin-activator-1.0.jar"); File activatorJar = activatorJarFromTarget.exists() ? activatorJarFromTarget : activatorJarFromMaven; SystemEnvironment systemEnvironment = new SystemEnvironment(); systemEnvironment.set(SystemEnvironment.PLUGIN_ACTIVATOR_JAR_PATH, activatorJar.getName()); systemEnvironment.set(SystemEnvironment.PLUGIN_LOCATION_MONITOR_INTERVAL_IN_SECONDS, 5); if (activatorJar.exists()) { FileUtils.copyFileToDirectory(activatorJar, classpath()); } else {/*from w w w . j a v a 2s . c o m*/ System.err.println("Could not find plugin activator jar, Plugin framework will not be loaded."); } }
From source file:dao.FilesDao.java
/** * Gets the source path of the file and copies it to the destination path. * If the destination path doesn't exist it creates it automatically. * @param source source path of the file. * @param dest destination path of the file. * @throws EntryException if the file doesn't exist. */// ww w .j a v a 2s . c om public void copyFile(File source, File dest) throws EntryException { boolean exists = createFilePath(dest.toString()); if (exists) try { FileUtils.copyFileToDirectory(source, dest); } catch (IOException ex) { throw new EntryException(); } else { createFilePath(dest.toString()); copyFile(source, dest); } }
From source file:com.litt.core.security.license.gui.Gui.java
/** * Create the application.// w w w .j av a2 s. c o m */ public Gui() { try { Properties props = PropertiesUtils.loadProperties(ResourceUtils.getFile("classpath:init.properties")); HOME_PATH = props.getProperty("HOME_PATH"); File configFile = new File(Gui.HOME_PATH, "config.xml"); if (!configFile.exists()) { FileUtils.copyFileToDirectory(ResourceUtils.getFile("classpath:config.xml"), new File(Gui.HOME_PATH)); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } initialize(); }
From source file:io.github.bunnyblue.droidfix.classcomputer.proguard.DiffClassUtil.java
public static void copyDiffClasses(ArrayList<ClassObject> diffClasses, String rootPath) { File rootDir = new File(rootPath); try {//from w w w . j a v a 2 s .c om FileUtils.deleteDirectory(rootDir); } catch (IOException e1) { e1.printStackTrace(); } rootDir.mkdirs(); for (ClassObject classObject : diffClasses) { classObject.getClassName().replaceAll(".", File.separator); String subPath = classObject.getClassName().replaceAll("\\.", File.separator); if (subPath.lastIndexOf(File.separator) != -1) { subPath = subPath.substring(0, subPath.lastIndexOf(File.separator)); subPath = rootPath + File.separator + subPath; File subDir = new File(subPath); subDir.mkdirs(); File localClass = new File(classObject.getLocalPath()); try { FileUtils.copyFileToDirectory(localClass, subDir); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.err.println("Copy diff class " + localClass.getAbsolutePath()); } else { File localClass = new File(classObject.getLocalPath()); try { FileUtils.copyFileToDirectory(localClass, rootDir); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.err.println("Copy diff class " + localClass.getAbsolutePath()); } } }
From source file:massbank.svn.MSDBUpdateUtil.java
/** * *//* w ww . j ava 2 s . co m*/ public static boolean updateFiles(File srcDir, File destDir, String[] extensions) { boolean isUpdated = false; if (!srcDir.exists()) { return false; } if (!destDir.exists()) { destDir.mkdirs(); } try { List<File> srcFileList = (List<File>) FileUtils.listFiles(srcDir, extensions, false); List<File> destFileList = (List<File>) FileUtils.listFiles(destDir, extensions, false); FileDifference diff = new FileDifference(srcFileList, destFileList); String[] addFilePaths = diff.getAddFilePaths(); String[] delFileNames = diff.getDeleteFileNames(); if (addFilePaths.length > 0) { isUpdated = true; for (String path : addFilePaths) { FileUtils.copyFileToDirectory(new File(path), destDir); } } if (delFileNames.length > 0) { isUpdated = true; for (String name : delFileNames) { String path = destDir.getPath() + File.separator + name; FileUtils.deleteQuietly(new File(path)); } } } catch (Exception e) { e.printStackTrace(); return false; } return isUpdated; }
From source file:com.dexels.navajo.tipi.dev.server.appmanager.impl.UnsignJarTask.java
public static void downloadDepencency(Dependency d, File repoDir, File destinationFolder, List<String> extraHeaders) throws IOException { String assembledName = d.getFileNameWithVersion(); String tmpAssembledFile = "tmp_" + assembledName; String tmpAssembled = d.getArtifactId() + "_" + d.getVersion(); File dest = new File(destinationFolder, tmpAssembledFile); FileOutputStream fos = new FileOutputStream(dest); File ff = d.getFilePathForDependency(repoDir); File parent = ff.getParentFile(); if (!parent.exists()) { parent.mkdirs();/* w ww .j a v a 2 s. c o m*/ } logger.info("Downloading: " + ff.getAbsolutePath()); ZipUtils.copyResource(fos, d.getUrl().openStream()); File tmpDir = new File(destinationFolder, tmpAssembled); tmpDir.mkdirs(); ZipUtils.unzip(dest, tmpDir); cleanSigningData(tmpDir, extraHeaders); File destinationZip = new File(destinationFolder, assembledName); ZipUtils.zipAll(tmpDir, destinationZip); FileUtils.copyFileToDirectory(destinationZip, parent); FileUtils.deleteDirectory(tmpDir); dest.delete(); }
From source file:com.maxl.java.aips2xml.Aips2Xml.java
public static void main(String[] args) { Options options = new Options(); addOption(options, "help", "print this message", false, false); addOption(options, "version", "print the version information and exit", false, false); addOption(options, "quiet", "be extra quiet", false, false); addOption(options, "verbose", "be extra verbose", false, false); addOption(options, "zip", "generate zip file", false, false); addOption(options, "lang", "use given language", true, false); addOption(options, "alpha", "only include titles which start with option value", true, false); addOption(options, "nodown", "no download, parse only", false, false); commandLineParse(options, args);//from w w w . j a v a 2 s.c om // Download all files and save them in appropriate directories if (DOWNLOAD_ALL) { System.out.println(""); allDown(); } DateFormat df = new SimpleDateFormat("ddMMyy"); String date_str = df.format(new Date()); System.out.println(""); if (!DB_LANGUAGE.isEmpty()) { extractPackageInfo(); List<MedicalInformations.MedicalInformation> med_list = readAipsFile(); if (SHOW_LOGS) { System.out.println(""); System.out.println("- Generating xml and html files ... "); } long startTime = System.currentTimeMillis(); int counter = 0; String fi_complete_xml = ""; for (MedicalInformations.MedicalInformation m : med_list) { if (m.getLang().equals(DB_LANGUAGE) && m.getType().equals("fi")) { if (m.getTitle().startsWith(MED_TITLE)) { if (SHOW_LOGS) System.out.println(++counter + ": " + m.getTitle()); String[] html_str = extractHtmlSection(m); // html_str[0] -> registration numbers // html_str[1] -> content string String xml_str = convertHtmlToXml(m.getTitle(), html_str[1], html_str[0]); if (DB_LANGUAGE.equals("de")) { if (!html_str[0].isEmpty()) { String name = m.getTitle(); // Replace all "Sonderzeichen" name = name.replaceAll("[/%:]", "_"); writeToFile(html_str[1], "./fis/fi_de_html/", name + "_fi_de.html"); writeToFile(xml_str, "./fis/fi_de_xml/", name + "_fi_de.xml"); fi_complete_xml += (xml_str + "\n"); } } else if (DB_LANGUAGE.equals("fr")) { if (!html_str[0].isEmpty()) { String name = m.getTitle(); // Replace all "Sonderzeichen" name = name.replaceAll("[/%:]", "_"); writeToFile(html_str[1], "./fis/fi_fr_html/", name + "_fi_fr.html"); writeToFile(xml_str, "./fis/fi_fr_xml/", name + "_fi_fr.xml"); fi_complete_xml += (xml_str + "\n"); } } } } } // Add header to huge xml fi_complete_xml = addHeaderToXml(fi_complete_xml); // Dump to file if (DB_LANGUAGE.equals("de")) { writeToFile(fi_complete_xml, "./fis/", "fi_de.xml"); if (ZIP_XML) zipToFile("./fis/", "fi_de.xml"); } else if (DB_LANGUAGE.equals("fr")) { writeToFile(fi_complete_xml, "./fis/", "fi_fr.xml"); if (ZIP_XML) zipToFile("./fis/", "fi_fr.xml"); } // Move stylesheet file to ./fis/ folders try { File src = new File("./css/amiko_stylesheet.css"); File dst_de = new File("./fis/fi_de_html/"); File dst_fr = new File("./fis/fi_fr_html/"); if (src.exists()) { if (dst_de.exists()) FileUtils.copyFileToDirectory(src, dst_de); if (dst_fr.exists()) FileUtils.copyFileToDirectory(src, dst_fr); } } catch (IOException e) { // Unhandled! } if (SHOW_LOGS) { long stopTime = System.currentTimeMillis(); System.out.println("- Generated " + counter + " xml and html files in " + (stopTime - startTime) / 1000.0f + " sec"); } } System.exit(0); }
From source file:dao.NewEntryVideoDaoTest.java
@Before public void setUp() { File file = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users" + fSeparator + "Panagiwtis Georgiadis" + fSeparator + "Entries" + fSeparator + "Texnologia2" + fSeparator + "Videos"); file.mkdirs();//from ww w. j a v a 2 s .c o m File videoEntry = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users" + fSeparator + "Panagiwtis Georgiadis" + fSeparator + "Entries" + fSeparator + "videoEntry" + fSeparator + "Videos"); videoEntry.mkdirs(); try { FileUtils.copyFileToDirectory(videoFile, videoEntry); } catch (IOException ex) { Logger.getLogger(NewEntryVideoDaoTest.class.getName()).log(Level.SEVERE, null, ex); } Login.username = "Panagiwtis Georgiadis"; }