List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException
From source file:lineage2.gameserver.utils.Files.java
/** * Method copyFile.//from w w w.jav a 2 s.c o m * @param srcFile String * @param destFile String * @return boolean */ public static boolean copyFile(String srcFile, String destFile) { try { FileUtils.copyFile(new File(srcFile), new File(destFile), false); return true; } catch (IOException e) { _log.error("Error while copying file : " + srcFile + " to " + destFile, e); } return false; }
From source file:app.common.X3DViewer.java
/** * View an X3D file using an external X3DOM player * * @param grid/*w w w .j ava 2 s. com*/ * @param smoothSteps * @param maxDecimateError * @throws IOException */ public static void viewX3DOM(Grid grid, int smoothSteps, double maxDecimateError) throws IOException { // TODO: Make thread safe using tempDir String dest = "/tmp/ringpopper/"; File dir = new File(dest); dir.mkdirs(); String pf = "x3dom/x3dom.css"; String dest_pf = dest + pf; File dest_file = new File(dest_pf); File src_file = new File("src/html/" + pf); if (!dest_file.exists()) { System.out.println("Copying file: " + src_file + " to dir: " + dest); FileUtils.copyFile(src_file, dest_file, true); } pf = "x3dom/x3dom.js"; dest_pf = dest + pf; dest_file = new File(dest_pf); src_file = new File("src/html/" + pf); if (!dest_file.exists()) { System.out.println("Copying file: " + src_file + " to dir: " + dest); FileUtils.copyFile(src_file, dest_file, true); } File f = new File("/tmp/ringpopper/out.xhtml"); FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream bos = new BufferedOutputStream(fos); PrintStream ps = new PrintStream(bos); try { ps.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); ps.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); ps.println("<head>"); ps.println("<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />"); ps.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"); ps.println("<title>Ring Popper Demo</title>"); // ps.println("<link rel='stylesheet' type='text/css' href='http://www.x3dom.org/x3dom/release/x3dom.css'></link>"); ps.println("<link rel='stylesheet' type='text/css' href='x3dom/x3dom.css'></link>"); ps.println("</head>"); ps.println("<body>"); ps.println("<p class='case'>"); GridSaver.writeIsosurfaceMaker(grid, bos, "x3d", smoothSteps, maxDecimateError); // ps.println("<script type='text/javascript' src='http://www.x3dom.org/x3dom/release/x3dom.js'></script>"); ps.println("<script type='text/javascript' src='x3dom/x3dom.js'></script>"); ps.println("</p>"); ps.println("</body></html>"); } finally { bos.flush(); bos.close(); fos.close(); } Desktop.getDesktop().browse(f.toURI()); }
From source file:fr.ironcraft.assets.Assets.java
/** * Download and convert assets if necessary *//* w w w . jav a2 s . com*/ public void downloadAssets() { for (FileDownloader todown : queue) { todown.downloadFile(); } if (this.indexName.equals("legacy")) { for (Entry<String, AssetObject> entry : index.getFileMap().entrySet()) { File target = new File(legacyFolder, entry.getKey()); File original = new File(new File(objectsFolder, entry.getValue().getHash().substring(0, 2)), entry.getValue().getHash()); if (!target.isFile()) { try { FileUtils.copyFile(original, target, false); } catch (IOException e) { } } } } }
From source file:com.thalesgroup.hudson.plugins.tusarnotifier.types.coverage.TusarCoverageInputMetric.java
/** * Convert an input file to an output file * Give your conversion process/*from w w w.ja v a 2s.c om*/ * Input and Output files are relatives to the filesystem where the process is executed on (like Hudson agent) * * @param inputFile the input file to convert * @param outFile the output file to convert * @param params the xsl parameters * @throws com.thalesgroup.dtkit.util.converter.ConversionException * an application Exception to throw when there is an error of conversion * The exception is catched by the API client (as Hudson plugin) */ @Override public void convert(File inputFile, File outFile, Map<String, Object> params) throws ConversionException { //Copy input to output try { FileUtils.copyFile(inputFile, outFile, false); } catch (IOException ioe) { throw new ConversionException( "Conversion error occur- Can't copy file from " + inputFile + "to " + outFile, ioe); } }
From source file:com.thalesgroup.hudson.plugins.tusarnotifier.types.measure.TusarMeasureInputMetric.java
/** * Convert an input file to an output file * Give your conversion process//from w ww . j a v a 2 s . co m * Input and Output files are relatives to the filesystem where the process is executed on (like Hudson agent) * * @param inputFile the input file to convert * @param outFile the output file to convert * @param params the xsl parameters * @throws com.thalesgroup.dtkit.util.converter.ConversionException * an application Exception to throw when there is an error of conversion * The exception is catched by the API client (as Hudson plugin) */ @Override public void convert(File inputFile, File outFile, Map<String, Object> params) throws ConversionException { //Copy input to output try { FileUtils.copyFile(inputFile, outFile, false); } catch (IOException ioe) { throw new ConversionException( "Conversion error occur- Can't copy file from " + inputFile + "to " + outFile, ioe); } }
From source file:edu.ku.brc.web.ParsePaleo.java
/** * /*from ww w . j a v a2 s. co m*/ */ private void startUp() { try { dbConn = DBConnection.getInstance(); dbConn.setUsernamePassword("root", "root"); dbConn.setDriver("com.mysql.jdbc.Driver"); dbConn.setConnectionStr("jdbc:mysql://localhost/"); dbConn.setDatabaseName("test1"); dbConn.getConnection().setCatalog("digitalatlas"); Connection conn = dbConn.getConnection(); BasicSQLUtils.setDBConnection(conn); File srcFile = new File("/Users/rods/databases/digitalatlas.sqlite"); File dstFile = new File("/Users/rods/databases/daal.sqlite"); FileUtils.copyFile(srcFile, dstFile, true); Class.forName("org.sqlite.JDBC"); dbS3Conn = DriverManager.getConnection("jdbc:sqlite:" + dstFile.getAbsolutePath()); dbS3Conn.setAutoCommit(false); String pStr = "INSERT INTO taxon (name, commonname, parentId, rankId) VALUES(?,?,?,?)"; taxonInsertStmt = dbS3Conn.prepareStatement(pStr, Statement.RETURN_GENERATED_KEYS); isInitialized = true; } catch (Exception ex) { ex.printStackTrace(); } }
From source file:app.common.X3DViewer.java
/** * View an X3D file using an external X3DOM player * * @param filename//from w w w . j av a 2 s . co m * @throws IOException */ public static void viewX3DOM(String[] filename, float[] pos) throws IOException { // TODO: Make thread safe using tempDir String dest = "/tmp/"; File dir = new File(dest); dir.mkdirs(); String pf = "x3dom/x3dom.css"; String dest_pf = dest + pf; File dest_file = new File(dest_pf); File src_file = new File("src/html/" + pf); if (!dest_file.exists()) { System.out.println("Copying file: " + src_file + " to dir: " + dest); FileUtils.copyFile(src_file, dest_file, true); } pf = "x3dom/x3dom.js"; dest_pf = dest + pf; dest_file = new File(dest_pf); src_file = new File("src/html/" + pf); if (!dest_file.exists()) { System.out.println("Copying file: " + src_file + " to dir: " + dest); FileUtils.copyFile(src_file, dest_file, true); } File f = new File("/tmp/out.xhtml"); FileOutputStream fos = new FileOutputStream(f); BufferedOutputStream bos = new BufferedOutputStream(fos); PrintStream ps = new PrintStream(bos); try { ps.println( "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"); ps.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); ps.println("<head>"); ps.println("<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" />"); ps.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"); ps.println("<title>Ring Popper Demo</title>"); // ps.println("<link rel='stylesheet' type='text/css' href='http://www.x3dom.org/x3dom/release/x3dom.css'></link>"); ps.println("<link rel='stylesheet' type='text/css' href='x3dom/x3dom.css'></link>"); ps.println("</head>"); ps.println("<body>"); ps.println("<p class='case'>"); ps.println( "<X3D profile='Immersive' showLog='true' showStats='true' version='3.0' height='600px' width='600px' y='0px' x='0px'>"); // had to turn of isStaticHierarchy // ps.println("<Scene isStaticHierarchy=\"true\" sortTrans=\"false\" doPickPass=\"false\" frustumCulling=\"false\">"); ps.println("<Scene sortTrans=\"false\" doPickPass=\"false\" frustumCulling=\"false\">"); // ps.println("<Scene>"); ps.println("<Background skyColor=\"1 1 1\" />"); if (pos != null) { ps.println("<Viewpoint position='" + pos[0] + " " + pos[1] + " " + pos[2] + "' />"); } for (int i = 0; i < filename.length; i++) { if (filename[i] != null) { ps.println("<Inline url='" + filename[i] + "' />"); } } ps.println("</Scene>"); ps.println("</X3D>"); // ps.println("<script type='text/javascript' src='http://www.x3dom.org/x3dom/release/x3dom.js'></script>"); ps.println("<script type='text/javascript' src='x3dom/x3dom.js'></script>"); ps.println("</p>"); ps.println("</body></html>"); } finally { bos.flush(); bos.close(); fos.close(); } Desktop.getDesktop().browse(f.toURI()); }
From source file:com.volkhart.selenium.report.Screenshot.java
void generateReport(String path) { // Delete the directory that contains the images so if re-running a test // we don't keep images from the previous test File oldImgDir = new File(path + DIRECTORY_SUFFIX); if (oldImgDir.exists()) { try {/* w w w. jav a2s. co m*/ FileUtils.deleteDirectory(oldImgDir); } catch (IOException e) { e.printStackTrace(); } } for (String filePath : mFiles.keySet()) { File file = mFiles.get(filePath); try { // We copy since moving across file systems sometimes causes // problems, particularly on unix machines. FileUtils.copyFile(file, new File(path + filePath), true); } catch (IOException e1) { e1.printStackTrace(); } // Delete regardless to avoid loose files file.delete(); } }
From source file:fr.acxio.tools.agia.io.AbstractFileOperations.java
protected void copyFile(Resource sOriginFile, Resource sDestinationFile) throws IOException { File aOrigineFile = sOriginFile.getFile(); if (aOrigineFile.isFile()) { if (!isDirectory(sDestinationFile)) { FileUtils.copyFile(aOrigineFile, sDestinationFile.getFile(), preserveAttributes); } else {// w w w . j a va 2s. c o m FileUtils.copyFileToDirectory(aOrigineFile, sDestinationFile.getFile(), preserveAttributes); } } else { if (recursive) { FileUtils.copyDirectory(aOrigineFile, sDestinationFile.getFile(), preserveAttributes); } else { FileUtils.copyDirectory(aOrigineFile, sDestinationFile.getFile(), FileFileFilter.FILE, preserveAttributes); } } }
From source file:abfab3d.shapejs.Project.java
public void save(String file) throws IOException { EvaluatedScript escript = m_script.getEvaluatedScript(); Map<String, Parameter> scriptParams = escript.getParamMap(); Gson gson = JSONParsing.getJSONParser(); String code = escript.getCode(); Path workingDirName = Files.createTempDirectory("saveScript"); String workingDirPath = workingDirName.toAbsolutePath().toString(); Map<String, Object> params = new HashMap<String, Object>(); // Write the script to file File scriptFile = new File(workingDirPath + "/main.js"); FileUtils.writeStringToFile(scriptFile, code, "UTF-8"); // Loop through params and create key/pair entries for (Map.Entry<String, Parameter> entry : scriptParams.entrySet()) { String name = entry.getKey(); Parameter pval = entry.getValue(); if (pval.isDefaultValue()) continue; ParameterType type = pval.getType(); switch (type) { case URI: URIParameter urip = (URIParameter) pval; String u = (String) urip.getValue(); // System.out.println("*** uri: " + u); File f = new File(u); String fileName = null; // TODO: This is hacky. If the parameter value is a directory, then assume it was // originally a zip file, and its contents were extracted in the directory. // Search for the zip file in the directory and copy that to the working dir. if (f.isDirectory()) { File[] files = f.listFiles(); for (int i = 0; i < files.length; i++) { String fname = files[i].getName(); if (fname.endsWith(".zip")) { fileName = fname; f = files[i];// w w w . ja v a 2 s . c o m } } } else { fileName = f.getName(); } params.put(name, fileName); // Copy the file to working directory FileUtils.copyFile(f, new File(workingDirPath + "/" + fileName), true); break; case LOCATION: LocationParameter lp = (LocationParameter) pval; Vector3d p = lp.getPoint(); Vector3d n = lp.getNormal(); double[] point = { p.x, p.y, p.z }; double[] normal = { n.x, n.y, n.z }; // System.out.println("*** lp: " + java.util.Arrays.toString(point) + ", " + java.util.Arrays.toString(normal)); Map<String, double[]> loc = new HashMap<String, double[]>(); loc.put("point", point); loc.put("normal", normal); params.put(name, loc); break; case AXIS_ANGLE_4D: AxisAngle4dParameter aap = (AxisAngle4dParameter) pval; AxisAngle4d a = (AxisAngle4d) aap.getValue(); params.put(name, a); break; case DOUBLE: DoubleParameter dp = (DoubleParameter) pval; Double d = (Double) dp.getValue(); // System.out.println("*** double: " + d); params.put(name, d); break; case INTEGER: IntParameter ip = (IntParameter) pval; Integer i = ip.getValue(); // System.out.println("*** int: " + pval); params.put(name, i); break; case STRING: StringParameter sp = (StringParameter) pval; String s = sp.getValue(); // System.out.println("*** string: " + s); params.put(name, s); break; case COLOR: ColorParameter cp = (ColorParameter) pval; Color c = cp.getValue(); // System.out.println("*** string: " + s); params.put(name, c.toHEX()); break; case ENUM: EnumParameter ep = (EnumParameter) pval; String e = ep.getValue(); // System.out.println("*** string: " + s); params.put(name, e); break; default: params.put(name, pval); } } if (params.size() > 0) { String paramsJson = gson.toJson(params); File paramFile = new File(workingDirPath + "/" + "params.json"); FileUtils.writeStringToFile(paramFile, paramsJson, "UTF-8"); } File[] files = (new File(workingDirPath)).listFiles(); FileOutputStream fos = new FileOutputStream(file); ZipOutputStream zos = new ZipOutputStream(fos); System.out.println("*** Num files to zip: " + files.length); try { byte[] buffer = new byte[1024]; for (int i = 0; i < files.length; i++) { // if (files[i].getName().endsWith(".zip")) continue; System.out.println("*** Adding file: " + files[i].getName()); FileInputStream fis = new FileInputStream(files[i]); ZipEntry ze = new ZipEntry(files[i].getName()); zos.putNextEntry(ze); int len; while ((len = fis.read(buffer)) > 0) { zos.write(buffer, 0, len); } fis.close(); } } finally { zos.closeEntry(); zos.close(); } }