List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:info.magnolia.filesystembrowser.app.action.DuplicateFileAction.java
@Override public void execute() throws ActionExecutionException { Object itemId = contentConnector.getItemId(item); if (itemId instanceof File) { File file = (File) itemId; File copy = createFileCopy(file); try {//from w ww . j a v a 2 s .com if (file.isFile()) { FileUtils.copyFile(file, copy); } else { FileUtils.copyDirectory(file, copy); } eventBus.fireEvent(new ContentChangedEvent(file)); } catch (IOException e) { String message = translator.translate("ui-framework.abstractcommand.executionfailure"); uiContext.openNotification(MessageStyleTypeEnum.ERROR, true, message); } } }
From source file:com.thoughtworks.selenium.ScreenshotListenerVir.java
/** * On test failure./*from ww w . j a va 2 s. com*/ * * result the result * * @param result * the result * @see org.testng.ITestListener#onTestFailure(org.testng.ITestResult) */ @Override public final void onTestFailure(final ITestResult result) { Reporter.setCurrentTestResult(result); try { if (outputDirectory.mkdirs()) { String fileloc = getProperties(); File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File(fileloc + ".png")); Reporter.log("<a href='" + fileloc + ".png'>screenshot</a>"); } else { System.err.println("Creation of directory failed " + outputDirectory.getAbsolutePath()); } } catch (Exception e) { e.printStackTrace(); Reporter.log("Couldn't create screenshot"); Reporter.log(e.getMessage()); } Reporter.setCurrentTestResult(null); }
From source file:ch.cern.dss.teamcity.agent.MockModeCommandLine.java
/** * * @return//from w ww .j a va 2 s . c om * @throws RunBuildException */ @NotNull @Override public List<String> getArguments() throws RunBuildException { List<String> arguments = new Vector<String>(); StringBuilder command = new StringBuilder(); try { FileUtils.copyFile(new File(AbiCheckerConstants.MOCK_CONFIG_DIRECTORY, "site-defaults.cfg"), new File(context.getWorkingDirectory().getAbsolutePath(), "site-defaults.cfg")); FileUtils.copyFile(new File(AbiCheckerConstants.MOCK_CONFIG_DIRECTORY, "logging.ini"), new File(context.getWorkingDirectory().getAbsolutePath(), "logging.ini")); } catch (IOException e) { throw new RunBuildException("Error reading mock site-defaults.cfg", e); } for (String chroot : mockEnvironmentBuilder.getChroots()) { String mockConfig; try { mockConfig = IOUtil.readFile( new File(AbiCheckerConstants.MOCK_CONFIG_DIRECTORY, chroot + ".cfg").getAbsolutePath()); } catch (IOException e) { throw new RunBuildException("Error reading mock config: " + chroot, e); } mockConfig += "\nconfig_opts['plugin_conf']['bind_mount_enable'] = True\n"; mockConfig += "config_opts['plugin_conf']['root_cache_opts']['age_check'] = False\n"; mockConfig += "config_opts['plugin_conf']['bind_mount_opts']['create_dirs'] = True\n"; mockConfig += "config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('" + context.getBuildTempDirectory() + "', '" + context.getBuildTempDirectory() + "' ))\n"; try { IOUtil.writeFile(new File(context.getWorkingDirectory().getAbsolutePath(), chroot + ".cfg") .getAbsolutePath(), mockConfig); } catch (IOException e) { throw new RunBuildException("Error writing mock config: " + chroot, e); } command.append(AbiCheckerConstants.MOCK_EXECUTABLE).append(" --configdir=") .append(context.getWorkingDirectory().getAbsolutePath()).append(" -r ").append(chroot) .append(" --install abi-compliance-checker ctags\n"); command.append(AbiCheckerConstants.MOCK_EXECUTABLE).append(" --configdir=") .append(context.getWorkingDirectory().getAbsolutePath()).append(" -r ").append(chroot) .append(" --chroot '").append(context.getAbiCheckerExecutablePath()).append(" -show-retval") .append(" -lib ").append(StringUtil.join(context.getLibNames(), ", ")).append(" -component ") .append(context.getLibNames().size() > 1 ? "libraries" : "library").append(" -old ") .append(context.getReferenceXmlFilename()).append(" -new ").append(context.getNewXmlFilename()) .append(" -binary -bin-report-path ").append(context.getNewArtifactsDirectory()).append("/") .append(chroot).append(AbiCheckerConstants.REPORT_DIRECTORY) .append(AbiCheckerConstants.ABI_REPORT).append(" -source -src-report-path ") .append(context.getNewArtifactsDirectory()).append("/").append(chroot) .append(AbiCheckerConstants.REPORT_DIRECTORY).append(AbiCheckerConstants.SRC_REPORT) .append(" -log-path ").append(context.getNewArtifactsDirectory()).append("/").append(chroot) .append(AbiCheckerConstants.REPORT_DIRECTORY).append("log.txt").append(" -report-format html") .append(" -logging-mode w'\n"); } File mockScriptFile = new File(context.getWorkingDirectory(), "mock-install.sh"); try { IOUtil.writeFile(mockScriptFile.getAbsolutePath(), command.toString()); } catch (IOException e) { throw new RunBuildException("Error writing mock script", e); } arguments.add(mockScriptFile.getAbsolutePath()); logger.message("Arguments: " + StringUtil.join(arguments, " ")); return arguments; }
From source file:com.googlecode.DownloadCache.java
public void install(String url, File outputFile, String md5, String sha1) throws Exception { loadIndex();// ww w . j a va 2 s . c o m if (md5 == null) { md5 = SignatureUtils.computeSignatureAsString(outputFile, MessageDigest.getInstance("MD5")); } if (sha1 == null) { sha1 = SignatureUtils.computeSignatureAsString(outputFile, MessageDigest.getInstance("SHA1")); } CachedFileEntry entry = getEntry(url, md5, sha1); if (entry != null) { return; // entry already here } entry = new CachedFileEntry(); entry.fileName = outputFile.getName(); this.index.put(url, entry); FileUtils.copyFile(outputFile, new File(this.basedir, entry.fileName)); saveIndex(); }
From source file:net.primomc.OneTimeKit.CommonsConfig.java
protected void createBackup() { File file = new File(datafolder, FILENAME + ".bak"); try {/*w w w . ja v a 2 s . c o m*/ FileUtils.copyFile(this.file, file); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.project.AddStock.java
@Override public String execute() throws Exception { HttpServletRequest request;//w w w. ja v a 2 s . c om Connection con; FileWriter jspFile; File file; try { con = getDbObj().getConnection(); request = ServletActionContext.getRequest(); if (con != null) { int diskId; PreparedStatement pst = con.prepareStatement( "INSERT INTO StockMaster(StockID, StockName, Version, Image, Casting, Director, Year, Quantity, Price, DiskDesc) values (?,?,?,?,?,?,?,?,?,?)"); pst.setString(1, getObj().getId()); pst.setString(2, getObj().getName()); pst.setString(3, getObj().getVersion()); pst.setString(4, "0.jpg"); pst.setString(5, getObj().getCasting()); pst.setString(6, getObj().getDirector()); pst.setString(7, getObj().getYear()); pst.setString(8, getObj().getQuantity()); pst.setString(9, getObj().getPrice()); pst.setString(10, getObj().getDesc()); int status = pst.executeUpdate(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT DiskID FROM StockMaster WHERE StockID=" + getObj().getId()); rs.next(); diskId = rs.getInt(1); st = con.createStatement(); String query = "UPDATE StockMaster SET Image='" + diskId + ".jpg' WHERE StockID=" + getObj().getId(); status = st.executeUpdate(query); if (status > 0) { String imagePath = "/home/raxor/NetBeansProjects/DiskTunes/web/product/image/"; String jspPath = "/home/raxor/NetBeansProjects/DiskTunes/web/product/"; System.out.println("Content type " + getObj().getImageContentType()); try { file = new File(imagePath, diskId + ".jpg"); FileUtils.copyFile(getObj().getImage(), file); jspFile = new FileWriter(jspPath + diskId + ".jsp"); jspFile.write("<%@page contentType=\"text/html\" pageEncoding=\"UTF-8\"%>\n" + "<%@taglib uri=\"/struts-tags\" prefix=\"s\" %>\n" + "<%@include file=\"../layout/header.html\" %>\n" + "<%@taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>" + "<!DOCTYPE html>\n" + "<html>\n" + " <head>\n" + " <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n" + " <link type=\"text/css\" rel=\"stylesheet\" href=\"../layout/custom.css\" />\n" + " <link type=\"text/css\" rel=\"stylesheet\" href=\"../layout/product.css\" />" + " <style>\n" + " .songNameFinal{\n" + " position: relative;\n" + " top: -10px;\n" + " font-size: 35px;\n" + " color: #8efd39;\n" + " font-family: Hobo Std;\n" + " }\n" + " </style>" + " <script type=\"text/javascript\">\n" + " function checkQuantity(quantity)\n" + " { \n" + " xmlHttp=GetXmlHttpObject();\n" + " \n" + " if(xmlHttp==null)\n" + " {\n" + " alert(\"Your Browser Does Not Support This Website! Kindly Update your Browser\");\n" + " return;\n" + " }\n" + " \n" + " var url=\"quantityAjax.jsp?id=\"+" + diskId + ";\n" + " xmlHttp.onreadystatechange= displayQuantity;\n" + " xmlHttp.open(\"GET\",url,true);\n" + " xmlHttp.send();\n" + " }\n" + " \n" + " function displayQuantity()\n" + " { \n" + " document.getElementById(\"submit\").disabled=true;\n" + " \n" + " if((xmlHttp.readyState==4 || xmlHttp.readyState==\"complete\")&& xmlHttp.status==200)\n" + " {\n" + " var dataReceived=parseInt(xmlHttp.response);\n" + " if(dataReceived===-1)\n" + " {\n" + " alert(\"Invalid ID\");\n" + " document.getElementById(\"submit\").disabled=true;\n" + " }\n" + " else if(dataReceived < document.getElementById(\"Quantity\").value)\n" + " {\n" + " \n" + " alert(\"Stock Less\\nQuantity Left : \"+dataReceived);\n" + " document.getElementById(\"submit\").disabled=true;\n" + " }\n" + " else\n" + " {\n" + " document.getElementById(\"submit\").disabled=false;\n" + " }\n" + " \n" + " }\n" + " \n" + " }\n" + " function GetXmlHttpObject()\n" + " { \n" + " var xmlHttp=null;\n" + " try\n" + " {\n" + " xmlHttp=new XMLHttpRequest();\n" + " }\n" + " catch(e)\n" + " {\n" + " try\n" + " {\n" + " xmlHttp=new ActiveXObject(\"Msxml2.XMLHTTP\");\n" + " \n" + " }\n" + " catch(e)\n" + " {\n" + " xmlHttp=new ActiveXObject(\"Microsoft.XMLHTTP\");\n" + " }\n" + " }\n" + " return xmlHttp;\n" + " \n" + " } \n" + " </script>" + " </head>\n" + " <body>\n" + " <c:if test=\"${sessionScope.LoginID ne null}\">\n" + " <%@include file=\"layout/UserLook.jsp\" %>\n" + " </c:if>\n" + " <c:if test=\"${sessionScope.LoginID eq null}\">\n" + " <form class=\"logInButton\" action=\"../login.jsp\">\n" + " <input type=\"submit\" value=\"LOG IN\"/>\n" + " </form>\n" + " <form class=\"signUpButton\" action=\"../SignUp.jsp\">\n" + " <input type=\"submit\" value=\"SIGN UP\"/>\n" + " </form>\n" + " </c:if>" + " <div class=\"product\"> \n" + " <div class=\"songNameFinal\"><h1>" + obj.getName() + "</h1></div><br><br><br><br>\n" + " <img src=\"image/" + diskId + ".jpg\" class=\"productImage\"/><br/>\n" + " <table>\n" + " <tr>\n" + " <td class=\"fCol\">Version</td>\n" + " <td>" + obj.getVersion() + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td class=\"fCol\">Casting</td>\n" + " <td>" + obj.getCasting() + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td class=\"fCol\">Director</td>\n" + " <td>" + obj.getDirector() + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td class=\"fCol\">Year</td>\n" + " <td>" + obj.getYear() + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td class=\"fCol\">Description</td>\n" + " <td>" + obj.getDesc() + "</td>\n" + " </tr>\n" + "\n" + " </table>\n" + " <br /><br />\n" + " <div class=\"price\"> Rs. " + obj.getPrice() + " </div> \n" + " <c:if test=\"${sessionScope.LoginID ne null}\">\n" + " <center>\n" + " <form action=\"addToCart.action\" method=\"POST\" class=\"buyNow\"><br/>\n" + " <input type=\"hidden\" name=\"DiskID\" value=\"" + diskId + "\"/> \n" + " <input type=\"text\" name=\"Quantity\" size=\"5\" placeholder=\"Quantity\"/><br/>\n" + " <input type=\"submit\" value=\"Add To Cart\"/><br/>\n" + " </form>\n" + " </center>\n" + " </c:if>" + " </div>\n" + " </body>\n" + "</html>"); jspFile.flush(); jspFile.close(); return "Success"; } catch (FileNotFoundException e) { System.out.println("Exception " + e); return "Error"; } finally { con.close(); } } else { request.setAttribute("err", "Cannot Insert"); return "Fail"; } } else { System.out.println("Cannot Establish Connection!"); return "Error"; } } catch (Exception e) { System.out.println("Exception " + e); return "Error"; } }
From source file:MyFormApp.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.//from ww w. ja va 2 s .c om */ private static void copyFileUsingApacheCommonsIO(File source, File dest) throws IOException { //? ?pdf ? ? FileUtils.copyFile(source, dest); }
From source file:hu.bme.mit.trainbenchmark.generator.sql.SQLGenerator.java
@Override public void initModel() throws IOException { // header file (DDL operations) final String headerFileDirectory = generatorConfig.getWorkspacePath() + "/hu.bme.mit.trainbenchmark.sql/src/main/resources/metamodel/"; final String headerFilePath = headerFileDirectory + (sqlGeneratorConfig.isMemSQL() ? "railway-header-memsql.sql" : "railway-header.sql"); final File headerFile = new File(headerFilePath); // destination file sqlRawPath = generatorConfig.getModelPathNameWithoutExtension() + "-raw.sql"; sqlDumpPath = generatorConfig.getModelPathNameWithoutExtension() + ".sql"; sqlPostgreDumpPath = generatorConfig.getModelPathNameWithoutExtension() + "-posgres.sql"; final File sqlRawFile = new File(sqlRawPath); // this overwrites the destination file if it exists FileUtils.copyFile(headerFile, sqlRawFile); writer = new BufferedWriter(new FileWriter(sqlRawFile, true)); }
From source file:FileTransferPackage.MultiFileUpload.java
public boolean saveFiles(String filePath) { for (int i = 0; i < uploadedFiles.size(); ++i) { System.out.println("FILE_NAME: " + getUploadedFilesFileName().get(i)); System.out.println("FILE_CONTENT_TYPE: " + getUploadedFilesContentType().get(i)); File dir = new File(path); if (!dir.exists()) { dir.mkdirs();// w w w . ja va2 s .c o m } else if (dir.isDirectory()) { //Clear out the directory String[] children = dir.list(); for (String children1 : children) { new File(dir, children1).delete(); } } try { FileUtils.copyFile(getUploadedFiles().get(i), new File(path + "/" + getUploadedFilesFileName().get(i))); } catch (IOException ex) { Logger.getLogger(MultiFileUpload.class.getName()).log(Level.SEVERE, null, ex); return false; } } //End-For return true; }
From source file:com.flipkart.flux.examples.WorkflowExecutionDemo.java
/** * Does necessary actions to run an example/user's workflow. * @param moduleName name of user module in which workflow code is present * @param workflowClassFQN fully qualified name of main class which triggers user workflow execution at client side. * @see com.flipkart.flux.examples.concurrent.RunEmailMarketingWorkflow for example. * @param configFileName "flux_config.yml" which contains workflow related configuration. * @see flux/examples/src/main/resources/flux_config.yml for example. * @throws Exception//from w w w . ja va 2 s . c om */ private static void runExample(String moduleName, String workflowClassFQN, String configFileName, String mavenPath) throws Exception { //copy dependencies to module's target directory executeCommand(mavenPath + " -pl " + moduleName + " -q package dependency:copy-dependencies -DincludeScope=runtime -DskipTests"); //get deployment path from configuration.yml FileReader reader = new FileReader( WorkflowExecutionDemo.class.getResource("/packaged/configuration.yml").getFile()); String deploymentUnitsPath = (String) ((Map) new Yaml().load(reader)).get("deploymentUnitsPath"); if (!deploymentUnitsPath.endsWith("/")) { deploymentUnitsPath = deploymentUnitsPath + "/"; } reader.close(); //create deployment structure String deploymentUnitName = "DU1/1"; String mainDirPath = deploymentUnitsPath + deploymentUnitName + "/main"; String libDirPath = deploymentUnitsPath + deploymentUnitName + "/lib"; executeCommand("mkdir -p " + mainDirPath); executeCommand("mkdir -p " + libDirPath); //copy dependencies to deployment unit FileUtils.copyFile( new File(moduleName + "/target/") .listFiles((FilenameFilter) new WildcardFileFilter(moduleName + "*.jar"))[0], new File(mainDirPath + "/" + moduleName + ".jar")); FileUtils.copyDirectory(new File(moduleName + "/target/dependency"), new File(libDirPath)); FileUtils.copyFile(new File(moduleName + "/src/main/resources/" + configFileName), new File(deploymentUnitsPath + deploymentUnitName + "/flux_config.yml")); //start flux runtime FluxInitializer.main(new String[] {}); //Invoke workflow in separate process, the below system out prints this process's output in blue color System.out.println((char) 27 + "[34m" + executeCommand( "java -cp " + moduleName + "/target/*:" + moduleName + "/target/dependency/* " + workflowClassFQN) + (char) 27 + "[0m"); }