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.hotmart.hot.uploader.model.FileMetaInfo.java
@JsonIgnore public StreamingOutput getFileStream() throws IOException { StreamingOutput stream = new StreamingOutput() { @Override/*from w w w. j ava 2s .c o m*/ public void write(OutputStream output) throws IOException, WebApplicationException { for (ChunkMetaInfo chunk : chunks) { FileUtils.copyFile(chunk.getFile(), output); } } }; return stream; }
From source file:groovesquid.Main.java
public static Config loadConfig() { configDir = new File(Utils.dataDirectory() + File.separator + ".groovesquid"); if (!configDir.exists()) { configDir.mkdir();// w w w .j a va 2s . c om } File oldConfigFile = new File("config.json"); File configFile = new File(configDir + File.separator + "config.json"); if (oldConfigFile.exists() && !configFile.exists()) { try { FileUtils.copyFile(oldConfigFile, configFile); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } oldConfigFile.delete(); } if (configFile.exists()) { try { Config tempConfig = gson.fromJson(FileUtils.readFileToString(configFile), Config.class); if (tempConfig != null) { return tempConfig; } } catch (Exception ex) { configFile.delete(); Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } return new Config(); }
From source file:citibob.licensor.MakeLauncher.java
/** * /*from ww w .j a va 2 s. c o m*/ * @param version * @param configDir * @param outJar * @param spassword * @throws java.lang.Exception */ public static void makeLauncher(String version, File configDir, File outJar, String spassword) throws Exception { File oaDir = ClassPathUtils.getMavenProjectRoot(); File oalaunchDir = new File(oaDir, "../oalaunch"); File oasslDir = new File(oaDir, "../oassl"); File keyDir = new File(oasslDir, "keys/client"); File tmpDir = new File(".", "tmp"); FileUtils.deleteDirectory(tmpDir); tmpDir.mkdirs(); // Find the oalaunch JAR file File oalaunchJar = null; File[] files = new File(oalaunchDir, "target").listFiles(); for (File f : files) { if (f.getName().startsWith("oalaunch") && f.getName().endsWith(".jar")) { oalaunchJar = f; break; } } // Unjar the oalaunch.jar file into the temporary directory exec(tmpDir, "jar", "xvf", oalaunchJar.getAbsolutePath()); File tmpOalaunchDir = new File(tmpDir, "oalaunch"); File tmpConfigDir = new File(tmpOalaunchDir, "config"); // Read app.properties Properties props = new Properties(); InputStream in = new FileInputStream(new File(configDir, "app.properties")); props.load(in); in.close(); // Re-do the config dir FileUtils.deleteDirectory(tmpConfigDir); FileFilter ff = new FileFilter() { public boolean accept(File f) { if (f.getName().startsWith(".")) return false; if (f.getName().endsWith("~")) return false; return true; } }; FileUtils.copyDirectory(configDir, tmpConfigDir, ff); // Set up to encrypt char[] password = null; PBECrypt pbe = new PBECrypt(); if (spassword != null) password = spassword.toCharArray(); // Encrypt .properties files if needed if (password != null) { for (File fin : configDir.listFiles()) { if (fin.getName().endsWith(".properties") || fin.getName().endsWith(".jks")) { File fout = new File(tmpConfigDir, fin.getName()); pbe.encrypt(fin, fout, password); } } } // Copy the appropriate key and certificate files String dbUserName = props.getProperty("db.user", null); File[] jksFiles = new File[] { new File(keyDir, dbUserName + "-store.jks"), new File(keyDir, dbUserName + "-trust.jks") }; for (File fin : jksFiles) { if (!fin.exists()) { System.out.println("Missing jks file: " + fin.getName()); continue; } File fout = new File(tmpConfigDir, fin.getName()); if (password != null) { System.out.println("Encrypting " + fin.getName()); pbe.encrypt(fin, fout, password); } else { System.out.println("Copying " + fin.getName()); FileUtils.copyFile(fin, fout); } } // Use a downloaded JNLP file, not a static one. new File(tmpOalaunchDir, "offstagearts.jnlp").delete(); // Open properties file, which we will write to... File oalaunchProperties = new File(tmpDir, "oalaunch/oalaunch.properties"); Writer propertiesOut = new FileWriter(oalaunchProperties); propertiesOut.write( "jnlp.template.url = " + "http://offstagearts.org/releases/offstagearts/offstagearts_oalaunch-" + version + ".jnlp.template\n"); String configName = outJar.getName(); int dot = configName.lastIndexOf(".jar"); if (dot >= 0) configName = configName.substring(0, dot); propertiesOut.write("config.name = " + configName + "\n"); propertiesOut.close(); // Jar it back up exec(tmpDir, "jar", "cvfm", outJar.getAbsolutePath(), "META-INF/MANIFEST.MF", "."); // // Sign it // exec(null, "jarsigner", "-storepass", "keyst0re", outJar.getAbsolutePath(), // "offstagearts"); // Remove the tmp directory FileUtils.deleteDirectory(tmpDir); }
From source file:it.wingstech.csslesser.LessifyMojo.java
@Override public void execute() throws MojoExecutionException { srcFolderName = srcFolderName.replace('\\', File.separatorChar).replace('/', File.separatorChar); outputFolderName = outputFolderName.replace('\\', File.separatorChar).replace('/', File.separatorChar); if (lessResources == null || lessResources.length == 0) { lessResources = new Resource[1]; lessResources[0] = new Resource(); lessResources[0].setDirectory(srcFolderName); }/*from ww w . j av a 2s . co m*/ for (Resource resource : lessResources) { String[] resources = getIncludedFiles(resource); String directory = resource.getDirectory(); getLog().info("Copying resources..."); for (String path : resources) { try { FileUtils.copyFile( new File(project.getBasedir() + File.separator + directory + File.separator + path), new File(outputFolderName + File.separator + path)); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } } if (lessify) { getLog().info("Performing less transformation..."); LessEngine engine = new LessEngine(); for (String path : resources) { if (path.toUpperCase().endsWith(".LESS")) { try { File inputFile = new File(outputFolderName + File.separator + path); File outputFile = new File(outputFolderName + File.separator + path.substring(0, path.length() - 5) + ".css"); getLog().info("LESS processing file: " + path + " ..."); engine.compile(inputFile, outputFile); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } } } if (cssCompress) { getLog().info("Performing css compression..."); Collection<File> inputFiles = FileUtils.listFiles(new File(outputFolderName), new String[] { "css" }, true); for (File inputFile : inputFiles) { getLog().info("Compressing file: " + inputFile.getPath() + " ..."); compress(inputFile); } } if (cssInline) { getLog().info("Performing css inlining..."); Collection<File> inputFiles = FileUtils.listFiles(new File(outputFolderName), new String[] { "css" }, true); for (File inputFile : inputFiles) { getLog().info("Inlining file: " + inputFile.getPath() + " ..."); inline(inputFile, "."); } } } }
From source file:de.uzk.hki.da.convert.PublishVideoConversionStrategyTests.java
/** * Test.// w ww . j av a2s.c om * @throws IOException */ @Test public void test() throws IOException { Document dom = XPathUtils.parseDom(basePath + "premis.xml"); if (dom == null) { throw new RuntimeException("Error while parsing premis.xml"); } Object o = TESTHelper.setUpObject("1", new RelativePath(basePath)); PublicationRight right = new PublicationRight(); right.setAudience(Audience.PUBLIC); right.setVideoRestriction(new VideoRestriction()); right.getVideoRestriction().setHeight("360"); right.getVideoRestriction().setDuration(180); o.getRights().getPublicationRights().add(right); PublishVideoConversionStrategy s = new PublishVideoConversionStrategy(); s.setDom(dom); ConversionInstruction ci = new ConversionInstruction(); ci.setSource_file(new DAFile("a", "filename.avi")); ci.setTarget_folder("target/"); s.setObject(o); s.setProcessTimeout(250); File testFile = new File(basePath + "testfile.txt"); File pubFile = new File(basePath + "TEST/1/data/dip/public/target/filename.mp4"); File instFile = new File(basePath + "TEST/1/data/dip/institution/target/filename.mp4"); FileUtils.copyFile(testFile, pubFile); FileUtils.copyFile(testFile, instFile); s.convertFile(new WorkArea(n, o), ci); }
From source file:com.axatrikx.report.ExecutionListener.java
@Override public void onTestFailure(ITestResult tr) { super.onTestFailure(tr); WebDriver driver = WebDriverFactory.getInstance().getWebDriver(); if (!driver.toString().contains("(null)")) { File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); String screenShotPath = null; try {/*ww w . j ava 2 s. c o m*/ String screenShotFileName = tr.getName() + ".png"; screenShotPath = ExecutionController.getController().getExecutionFolder() + "/" + screenShotFileName; FileUtils.copyFile(scrFile, new File(screenShotPath)); screenShotPath = screenShotFileName; } catch (IOException e) { screenShotPath = null; } reporter.log("Result", "Test Failed", ExecutionStatus.FAIL, tr.getThrowable(), screenShotPath); } else { reporter.log("Result", "Test Failed", ExecutionStatus.FAIL, tr.getThrowable()); } reporter.endTest(); System.out.println(tr.getName() + " Failed"); }
From source file:com.mavict.plugin.ueditor.DefaultMultipartFile.java
public void transferTo(File dest) throws IOException, IllegalStateException { if (dest.exists() && !dest.delete()) { throw new IOException( "Destination file [" + dest.getAbsolutePath() + "] already exists and could not be deleted"); }/*from w w w .j a v a 2 s . co m*/ try { FileUtils.copyFile(dfosFile, dest); } catch (IOException ex) { throw ex; } catch (Exception ex) { throw new IOException("Could not transfer to file: " + ex.getMessage()); } }
From source file:net.jsign.PESignerTest.java
/** * Tests that a custom Timestamper implementation can be provided. * @throws Exception /*from w w w.j a v a2 s . c o m*/ */ public void testWithTimestamper() throws Exception { File sourceFile = new File("target/test-classes/wineyes.exe"); File targetFile = new File("target/test-classes/wineyes-timestamped-authenticode.exe"); FileUtils.copyFile(sourceFile, targetFile); PEFile peFile = new PEFile(targetFile); final HashSet<Boolean> called = new HashSet<Boolean>(); PESigner signer = new PESigner(getKeyStore(), ALIAS, PRIVATE_KEY_PASSWORD); signer.withDigestAlgorithm(DigestAlgorithm.SHA1); signer.withTimestamping(true); signer.withTimestamper(new AuthenticodeTimestamper() { @Override protected CMSSignedData timestamp(DigestAlgorithm algo, byte[] encryptedDigest) throws IOException, TimestampingException { called.add(true); return super.timestamp(algo, encryptedDigest); } }); signer.sign(peFile); peFile = new PEFile(targetFile); List<CMSSignedData> signatures = peFile.getSignatures(); assertNotNull(signatures); assertEquals(1, signatures.size()); CMSSignedData signature = signatures.get(0); assertNotNull(signature); assertTrue("expecting our Timestamper to be used", called.contains(true)); }
From source file:edu.synth.state.SyntHelperState.java
private boolean handleFileList(File wDir, FilenameFilter filter, File dest) { String path = ""; boolean done = false; String[] files = wDir.list(filter); int max = files.length; if (max > 0) { for (int i = 0; i < max; i++) { path = wDir + File.separator + files[i]; File src = new File(path); if (src.exists()) try { FileUtils.copyFile(src, dest); done = true;/*from ww w. j ava 2 s . co m*/ Messager.publish("SYNTHelperState - handleFileList", path + " to " + dest.getPath() + " has been copied successfuly..."); break; } catch (IOException e) { Messager.publish("SYNTHelperState - handleFileList", (Exception) e); } } } return done; }
From source file:de.akra.idocit.wsdl.services.WSDLGeneratorTest.java
/** * Tests the error documentation-flag is written to an WSDL-file correctly: * // w w w. jav a2s .c o m * <ol> * <li>Parse the file {@link Constants#FOLDER_SOURCE}/CustomerServiceErrorDocs.wsdl * <li>Check if the error documentation of ACTION is true. * <li>Set it to false. * <li>Write the changed interface to a file. * <li>Parse the written file. * <li>Check if the flag is set to false. * <li>Set it to true. * <li>Write it again into the file. * <li>Parse it again and check if its still true. * </ol> * * @throws WSDLException * If the file CustomerServiceErrorDocs.wsdl contains a syntactical error * @throws IOException * If the temporary files could not be read or written */ @Test public void testParseAndWriteWsdlWithErrorDocs() throws WSDLException, IOException { WSDLParserMock parser = new WSDLParserMock(); InterfaceArtifact customerServiceWsdl = parser .parse(new File(Constants.FOLDER_SOURCE + "CustomerServiceErrorDocs.wsdl")); Documentation actionDocs = getFirstFindDocumentation(customerServiceWsdl); Assert.assertEquals("ACTION", actionDocs.getThematicRole().getName()); Assert.assertTrue(actionDocs.isErrorCase()); File tmpInterfaceFile = new File(TMP_WSDL_FILE_NAME); actionDocs.setErrorCase(false); parser.write(customerServiceWsdl, tmpInterfaceFile); File xmlSchema = new File(TMP_XML_SCHEMA_FILE_NAME); FileUtils.copyFile(new File(XML_SCHEMA_FILE_NAME), xmlSchema); customerServiceWsdl = parser.parse(tmpInterfaceFile); actionDocs = getFirstFindDocumentation(customerServiceWsdl); Assert.assertEquals("ACTION", actionDocs.getThematicRole().getName()); Assert.assertFalse(actionDocs.isErrorCase()); actionDocs.setErrorCase(true); parser.write(customerServiceWsdl, tmpInterfaceFile); customerServiceWsdl = parser.parse(tmpInterfaceFile); actionDocs = getFirstFindDocumentation(customerServiceWsdl); Assert.assertEquals("ACTION", actionDocs.getThematicRole().getName()); Assert.assertTrue(actionDocs.isErrorCase()); }