List of usage examples for org.apache.commons.io FileUtils moveFile
public static void moveFile(File srcFile, File destFile) throws IOException
From source file:mase.MaseEvolve.java
public static void main(String[] args) throws Exception { File outDir = getOutDir(args); boolean force = Arrays.asList(args).contains(FORCE); if (!outDir.exists()) { outDir.mkdirs();// w ww.ja v a 2 s .c o m } else if (!force) { System.out.println("Folder already exists: " + outDir.getAbsolutePath() + ". Waiting 5 sec."); try { Thread.sleep(5000); } catch (InterruptedException ex) { } } // Get config file Map<String, String> pars = readParams(args); // Copy config to outdir try { File rawConfig = writeConfig(args, pars, outDir, false); File destiny = new File(outDir, DEFAULT_CONFIG); destiny.delete(); FileUtils.moveFile(rawConfig, new File(outDir, DEFAULT_CONFIG)); } catch (Exception ex) { ex.printStackTrace(); } // JBOT INTEGRATION: copy jbot config file to the outdir // Does nothing when jbot is not used if (pars.containsKey("problem.jbot-config")) { File jbot = new File(pars.get("problem.jbot-config")); FileUtils.copyFile(jbot, new File(outDir, jbot.getName())); } // Write config to system temp file File config = writeConfig(args, pars, outDir, true); // Launch launchExperiment(config); }
From source file:edu.cornell.med.icb.goby.util.RenameWeights.java
public static void main(final String[] args) throws IOException { final File directory = new File("."); final String[] list = directory.list(new FilenameFilter() { public boolean accept(final File directory, final String filename) { final String extension = FilenameUtils.getExtension(filename); return (extension.equals("entries")); }//from www . j a v a 2 s .com }); for (final String filename : args) { final String extension = FilenameUtils.getExtension(filename); final String basename = FilenameUtils.removeExtension(filename); for (final String alignFilename : list) { final String alignBasename = FilenameUtils.removeExtension(alignFilename); if (alignBasename.endsWith(basename)) { System.out.println("move " + filename + " to " + alignBasename + "." + extension); final File destination = new File(alignBasename + "." + extension); FileUtils.deleteQuietly(destination); FileUtils.moveFile(new File(filename), destination); } } } }
From source file:alluxio.master.backcompat.BackwardsCompatibilityJournalGenerator.java
/** * Generates journal files to be used by the backwards compatibility test. The files are named * based on the current version defined in ProjectConstants.VERSION. Run this with each release, * and commit the created journal and snapshot into the git repository. * * @param args no args expected// w w w .ja v a 2 s . c o m */ public static void main(String[] args) throws Exception { BackwardsCompatibilityJournalGenerator generator = new BackwardsCompatibilityJournalGenerator(); new JCommander(generator, args); if (!LoginUser.get().getName().equals("root")) { System.err.printf("Journals must be generated as root so that they can be replayed by root%n"); System.exit(-1); } File journalDst = new File(generator.getOutputDirectory(), String.format("journal-%s", ProjectConstants.VERSION)); if (journalDst.exists()) { System.err.printf("%s already exists, delete it first%n", journalDst.getAbsolutePath()); System.exit(-1); } File backupDst = new File(generator.getOutputDirectory(), String.format("backup-%s", ProjectConstants.VERSION)); if (backupDst.exists()) { System.err.printf("%s already exists, delete it first%n", backupDst.getAbsolutePath()); System.exit(-1); } MultiProcessCluster cluster = MultiProcessCluster.newBuilder(PortCoordination.BACKWARDS_COMPATIBILITY) .setClusterName("BackwardsCompatibility").setNumMasters(1).setNumWorkers(1).build(); try { cluster.start(); cluster.notifySuccess(); cluster.waitForAllNodesRegistered(10 * Constants.SECOND_MS); for (TestOp op : OPS) { op.apply(cluster.getClients()); } AlluxioURI backup = cluster.getMetaMasterClient() .backup(new File(generator.getOutputDirectory()).getAbsolutePath(), true).getBackupUri(); FileUtils.moveFile(new File(backup.getPath()), backupDst); cluster.stopMasters(); FileUtils.copyDirectory(new File(cluster.getJournalDir()), journalDst); } catch (Throwable t) { t.printStackTrace(); } finally { cluster.destroy(); } System.out.printf("Artifacts successfully generated at %s and %s%n", journalDst.getAbsolutePath(), backupDst.getAbsolutePath()); }
From source file:jhc.redsniff.generation.PackageScanningGenerator.java
public static void main(String[] args) throws Exception { if (args.length != 5) { System.err.println("Args: source-dir package-class-filter parent-class generated-class output-dir"); System.err.println(""); System.err.println(" source-dir : Path to Java source containing matchers to generate sugar for."); System.err.println(" May contain multiple paths, separated by commas."); System.err.println(" e.g. src/java,src/more-java"); System.err.println(/* w w w.j av a 2 s. co m*/ " package-class-filter : base of package to look for classes with methods, eg jhc.selenium.matchers"); System.err.println(""); System.err.println( "parent-class : Full name of parent class type to examine - eg org.hamcrest.Matcher, jhc.selenium.seeker.Seeker"); System.err.println(" e.g. org.myproject.MyMatchers"); System.err.println("generated-class : Full name of class to generate."); System.err.println(" e.g. org.myproject.MyMatchers"); System.err.println(""); System.err.println(" output-dir : Where to output generated code (package subdirs will be"); System.err.println(" automatically created)."); System.err.println(" e.g. build/generated-code"); System.exit(-1); } String srcDirs = args[0]; String package_name_prefix = args[1]; String parentClassName = args[2]; String fullClassName = args[3]; File outputDir = new File(args[4]); String fileName = fullClassName.replace('.', File.separatorChar) + ".java"; int dotIndex = fullClassName.lastIndexOf("."); String packageName = dotIndex == -1 ? "" : fullClassName.substring(0, dotIndex); String shortClassName = fullClassName.substring(dotIndex + 1); if (!outputDir.isDirectory()) { System.err.println("Output directory not found : " + outputDir.getAbsolutePath()); System.exit(-1); } Class<?> parentClass = Class.forName(parentClassName); File outputFile = new File(outputDir, fileName); outputFile.getParentFile().mkdirs(); File tmpFile = new File(outputDir, fileName + ".tmp"); SugarGenerator sugarGenerator = new SugarGenerator(); try { sugarGenerator .addWriter(new SeleniumFactoryWriter(packageName, shortClassName, new FileWriter(tmpFile))); sugarGenerator.addWriter(new QuickReferenceWriter(System.out)); PackageScanningGenerator pkgScanningGenerator = new PackageScanningGenerator(sugarGenerator, PackageScanningGenerator.class.getClassLoader(), parentClass); if (srcDirs.trim().length() > 0) { for (String srcDir : srcDirs.split(",")) { pkgScanningGenerator.addSourceDir(new File(srcDir)); } } // could add use of xml just to list filter expressions // pkgScanningGenerator.load(new InputSource(configFile)); pkgScanningGenerator.addClasses(package_name_prefix); System.out.println("Generating " + fullClassName); sugarGenerator.generate(); sugarGenerator.close(); outputFile.delete(); FileUtils.moveFile(tmpFile, outputFile); } finally { tmpFile.delete(); sugarGenerator.close(); } }
From source file:functional.testing.customerclient.util.ScreenCapturer.java
public static void takeAShot(WebDriver driver, String filename) { File passwordChecked = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); File failureImageFile = new File("target/" + filename); try {//from w ww. j a va 2 s . co m FileUtils.moveFile(passwordChecked, failureImageFile); } catch (IOException ex) { Logger.getLogger(RegisterTest.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.adguard.compiler.PackageUtils.java
public static File createZip(String makeZipSh, File file) throws Exception { execute(makeZipSh, file.getAbsolutePath()); File zipFile = new File(file, file.getName() + ".zip"); File destZipFile = new File(file.getParentFile(), zipFile.getName()); FileUtils.deleteQuietly(destZipFile); FileUtils.moveFile(zipFile, destZipFile); return destZipFile; }
From source file:com.liferay.maven.plugins.util.FileUtil.java
public static boolean move(File source, File destination) { if (!source.exists()) { return false; }//from www . j av a 2 s.c o m destination.delete(); try { if (source.isDirectory()) { FileUtils.moveDirectory(source, destination); } else { FileUtils.moveFile(source, destination); } } catch (IOException ioe) { return false; } return true; }
From source file:com.adguard.compiler.PackageUtils.java
public static File createCrx(String makeCrxSh, File file, File certificate) throws Exception { execute(makeCrxSh, file.getAbsolutePath(), certificate.getAbsolutePath()); File crxFile = new File(file, file.getName() + ".crx"); File destCrxFile = new File(file.getParentFile(), crxFile.getName()); FileUtils.deleteQuietly(destCrxFile); FileUtils.moveFile(crxFile, destCrxFile); return destCrxFile; }
From source file:net.chris54721.infinitycubed.Updater.java
private static void downloadUpdate(String version) { try {/*from w w w . j a va 2 s . c om*/ // TODO Trigger splashscreen progressbar (run downloadable w/custom ProgressListener) File executable = new File(URLDecoder.decode( (Launcher.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()), "UTF-8")); String extension = FilenameUtils.getExtension(executable.getName()); File updateTemp = new File(Reference.DEFAULT_FOLDER, "update." + extension); Downloadable update = new Downloadable( new URL(Reference.UPDATE_URL + extension + "/infinitycubed-" + version + "." + extension), updateTemp); if (update.download()) { executable.delete(); FileUtils.moveFile(updateTemp, executable); Utils.restart(); } else LogHelper.warn("Failed downloading launcher update: file size not matching."); } catch (Exception e) { LogHelper.error("Failed downloading launcher update", e); } }
From source file:com.adguard.compiler.PackageUtils.java
public static File createXpi(String makeXpiSh, File file, String xpiName) throws Exception { execute(makeXpiSh, file.getAbsolutePath()); File xpiFile = new File(file, xpiName + ".xpi"); File destXpiFile = new File(file.getParentFile(), file.getName() + ".xpi"); if (destXpiFile.exists()) { FileUtils.deleteQuietly(destXpiFile); }/*from ww w . jav a 2 s .com*/ FileUtils.moveFile(xpiFile, destXpiFile); FileUtils.deleteQuietly(file); return destXpiFile; }