Example usage for org.apache.commons.io FileUtils copyFile

List of usage examples for org.apache.commons.io FileUtils copyFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils copyFile.

Prototype

public static void copyFile(File srcFile, File destFile) throws IOException 

Source Link

Document

Copies a file to a new location preserving the file date.

Usage

From source file:ch.admin.suis.msghandler.signer.SignerTest.java

private void populateSigningOutboxes1and2() throws IOException {
    List<File> files = getAllFilesFromDir(new File(BASE_PATH + "/signingOutbox1Files"));
    for (File f : files) {
        FileUtils.copyFile(f, new File(signingOutbox1, f.getName()));
    }//from w w  w.j a  v  a2 s  .c  o m

    files = getAllFilesFromDir(new File(BASE_PATH + "/signingOutbox2Files"));
    for (File f : files) {
        FileUtils.copyFile(f, new File(signingOutbox2, f.getName()));
    }
}

From source file:celepsa.rrcc.web.actions.DocumentosAdjuntosAction.java

public String subirArchivo() {
    try {//from w  w w  .  java 2 s  .com
        if (getUploadFileName() != null) {
            String filePath = request.getRealPath("/") + "uploads/";
            String sExtension = getUploadFileName().substring(getUploadFileName().lastIndexOf(".") - 1);
            String sFecha = Funciones.formatearFecha_yyyyMMdd(new Date());
            String sCodigo = sFecha + sExtension;

            File fileToCreate = new File(filePath, sCodigo);
            FileUtils.copyFile(getUpload(), fileToCreate);

            // adjunto
            AdjuntoBE objAdjunto = new AdjuntoBE();
            objAdjunto.setNombre(getUploadFileName());
            objAdjunto.setScodigo(sCodigo);

            DocumentoBL objAdjuntoBL = new DocumentoBL();
            objAdjuntoBL.registrarAdjunto(objAdjunto, Documento);
            //int iIdArchivo = objAdjuntoBL.registrarAdjunto(objAdjunto, Documento);
            this.listarAdjuntos();
            //  adjunto = new AdjuntoBE();
            // adjunto.setId(String.valueOf(iIdArchivo));
            addActionMessage("El adjunto se cargo correctamente");
            msgAction = "";
        } else {
            msgAction = "Seleccione el archivo";
        }
    } catch (Exception e) {
        procesarError(e);
    }
    return INPUT;
}

From source file:net.jsign.pe.PEFileTest.java

public void testPadNoOp() throws Exception {
    File testFile = new File("target/test-classes/wineyes.exe");
    File testFilePadded = new File("target/test-classes/wineyes-padded.exe");
    FileUtils.copyFile(testFile, testFilePadded);

    PEFile file = new PEFile(testFilePadded);
    file.pad(8);//from  ww w  .j  a  v a 2  s .c  o  m
    file.close();

    assertEquals("Padded file size", testFile.length(), testFilePadded.length());
}

From source file:com.genericworkflownodes.knime.nodes.io.outputfile.OutputFileNodeModel.java

@Override
protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) throws Exception {
    IURIPortObject obj = (IURIPortObject) inObjects[0];
    List<URIContent> uris = obj.getURIContents();

    if (uris.size() == 0) {
        throw new Exception("There were no URIs in the supplied IURIPortObject at port 0");
    }/*from w w  w . j  av  a 2  s . c o m*/

    String filename = m_filename.getStringValue();

    File in = new File(uris.get(0).getURI());
    File out = new File(filename);

    FileUtils.copyFile(in, out);

    data = Helper.readFileSummary(in, 50);

    return new PortObject[] {};
}

From source file:edu.synth.state.SyntHelperState.java

private void handleWorkspace(File wDir) throws IOException {
    if (wDir.isDirectory()) {
        if (!handleFileList(wDir, new FilenameFilter(".abn"), new File(Constants.ABN_PATH))) {
            FileUtils.copyFile(new File(Constants.DEF_SOLAR_ABN), new File(Constants.ABN_PATH));
            Messager.publish("SYNTHelperState - handleWorkspace", Constants.DEF_SOLAR_ABN + " to "
                    + Constants.ABN_PATH + " has been copied successfuly... Default settings!");
        }//  w  w w  . j  a  va2  s  . c  o  m

        if (!handleFileList(wDir, new FilenameFilter("synt.inp"), new File(Constants.SYNTH_PATH))) {
            FileUtils.copyFile(new File(Constants.DEF_SYNTH_INP), new File(Constants.SYNTH_PATH));
            Messager.publish("SYNTHelperState - handleWorkspace", Constants.DEF_SYNTH_INP + " to "
                    + Constants.SYNTH_PATH + " has been copied successfuly... Default settings!");
        }

        if (!handleFileList(wDir, new FilenameFilter("input.atl"), new File(Constants.MODEL_PATH)))
            Messager.publish("SYNTHelperState - handleWorkspace",
                    "Kurucz's format model file is not found... Some error? Check workspace directory or file names there...");

        if (!handleFileList(wDir, new FilenameFilter(".obs"), new File(Constants.OBS_DATA)))
            Messager.publish("SYNTHelperState - handleWorkspace",
                    "Observational data file is not found... Some error? Check workspace directory or file names there...");

        if (!handleFileList(wDir, new FilenameFilter("convolve.conf"), new File(Constants.CONV_PATH))) {
            FileUtils.copyFile(new File(Constants.DEF_CONV_CONF), new File(Constants.CONV_PATH));
            Messager.publish("SYNTHelperState - handleWorkspace", Constants.DEF_CONV_CONF + " to "
                    + Constants.CONV_PATH + " has been copied successfuly... Default settings!");
        }
    }
}

From source file:SaveLiveEditAction.java

/**
 * This is the action called from the Struts framework.
 *
 * @param mapping The ActionMapping used to select this instance.
 * @param form The optional ActionForm bean for this request.
 * @param request The HTTP Request we are processing.
 * @param response The HTTP Response we are processing.
 * @throws java.lang.Exception//w w w  .j  ava  2s  .c  om
 * @return
 */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    LiveEditFormBean2 lfb22 = (LiveEditFormBean2) request.getSession().getAttribute("lfb2");
    String p = lfb22.getProjectname();
    System.out.println("PROJECT NAME=" + p);
    LiveEditFormBean2 lfb2 = (LiveEditFormBean2) form;
    int m = lfb2.getModnosave();
    /*int c=lfb2.getCodenosave();*/
    String code = lfb2.getEditorcontent();
    int m1 = lfb2.getModnosave1();
    int c1 = lfb2.getCodenosave1();
    int c = 0;
    System.out.println("@@@!!!" + m + "," + p);
    System.out.println("@@@!!!222**" + m1 + "," + c1 + "," + p);

    try {

        if (m1 != 0 && c1 != 0) {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("Driver loaded successfully");
            Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "System",
                    "pass");
            PreparedStatement pst1 = conn.prepareStatement(
                    "select code1,code2,code3,code4,code5,code6,code7,code8 from CONCOLLABMODULES where projectname=? and moduleno=?");
            System.out.println("okay!!@@@@");
            pst1.setString(1, p);
            pst1.setInt(2, m1);
            System.out.println("allright@");
            ResultSet rst1 = pst1.executeQuery();
            System.out.println("allright@2");
            int count1 = 0;
            while (rst1.next()) {
                if (rst1.getString(1) != null)
                    count1 = count1 + 1;
                if (rst1.getString(2) != null)
                    count1 = count1 + 1;
                if (rst1.getString(3) != null)
                    count1 = count1 + 1;
                if (rst1.getString(4) != null)
                    count1 = count1 + 1;
                if (rst1.getString(5) != null)
                    count1 = count1 + 1;
                if (rst1.getString(6) != null)
                    count1 = count1 + 1;
                if (rst1.getString(7) != null)
                    count1 = count1 + 1;
                if (rst1.getString(8) != null)
                    count1 = count1 + 1;
            }
            if (c1 > 0 && c1 <= count1 && c1 < 9) {
                File ff1 = new File("a1.txt");
                FileOutputStream fos = new FileOutputStream(ff1);
                byte bb[] = code.getBytes();
                fos.write(bb);
                fos.close();
                String filepath = "C:\\apache-tomcat-7.0.55\\webapps";
                String filename = p + m1 + "." + c1 + ".txt";
                File ff2 = new File(filepath, filename);
                System.out.println("Output file=" + ff2);
                FileUtils.copyFile(ff1, ff2);
                System.out.println("Attempting to update db!!!!!!");

                String qrr = "update CONCOLLABMODULES set code" + c1 + "=? where projectname=? and moduleno=?";

                PreparedStatement pst2 = conn.prepareStatement(qrr);
                pst2.setString(1, "okay1");
                pst2.setString(2, p);
                pst2.setInt(3, m1);
                int rr = pst2.executeUpdate();
                System.out.println("Overwrite update over!!!!=" + rr);
                conn.close();
            }

        } else {

            File ff = new File("a.txt");
            FileOutputStream fos = new FileOutputStream(ff);
            byte b[] = code.getBytes();
            fos.write(b);
            fos.close();
            String filepath1 = "C:\\apache-tomcat-7.0.55\\webapps";

            Class.forName("oracle.jdbc.driver.OracleDriver");
            System.out.println("Driver loaded successfully");
            Connection con1 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "System",
                    "pass");
            System.out.println("Connection successful!!!");
            PreparedStatement ps = con1.prepareStatement(
                    "select code1,code2,code3,code4,code5,code6,code7,code8 from CONCOLLABMODULES where projectname=? and moduleno=?");
            System.out.println("okay!!@@@@");
            ps.setString(1, p);
            ps.setInt(2, m);
            System.out.println("allright@");
            ResultSet rs = ps.executeQuery();
            System.out.println("allright@2");
            int count = 0;
            while (rs.next()) {
                if (rs.getString(1) != null)
                    count = count + 1;
                if (rs.getString(2) != null)
                    count = count + 1;
                if (rs.getString(3) != null)
                    count = count + 1;
                if (rs.getString(4) != null)
                    count = count + 1;
                if (rs.getString(5) != null)
                    count = count + 1;
                if (rs.getString(6) != null)
                    count = count + 1;
                if (rs.getString(7) != null)
                    count = count + 1;
                if (rs.getString(8) != null)
                    count = count + 1;
            }
            System.out.println("allright@3");
            c = count + 1;
            System.out.println("!!!c=" + c);
            if (c < 9) {
                String filename = p + m + "." + c + ".txt";
                File ff1 = new File(filepath1, filename);
                System.out.println("Output file=" + ff1);
                FileUtils.copyFile(ff, ff1);
                System.out.println("Attempting to update db");

                String q = "update CONCOLLABMODULES set code" + c + "=? where projectname=? and moduleno=?";
                System.out.println("allright@4");
                PreparedStatement ps1 = con1.prepareStatement(q);
                System.out.println("allright@5");
                ps1.setString(1, "okay");
                ps1.setString(2, p);
                ps1.setInt(3, m);
                System.out.println("allright@6");
                int r1 = ps1.executeUpdate();
                System.out.println("allright@7");
                System.out.println("$$$$" + r1);
                con1.close();
            }
        }
    } catch (SQLException se) {
        System.out.println("Sorry SQL Error");
    } catch (FileNotFoundException fne) {
        System.out.println("Sorry file error");

    } catch (Exception ee) {
        System.out.println("Sorry Error");

    }

    return mapping.findForward("backtoeditor");
}

From source file:common.MyListener.java

@Override
public synchronized void onTestFailure(ITestResult tr) {
    try {//  w  w w  . j a va  2  s.c om
        time = tr.getEndMillis() - tr.getStartMillis();
        time = time / 1000;
        String testName = null;
        DateFormat dateFormat = new SimpleDateFormat("dd_MMM_yyyy__hh_mm_ssaa");
        String destFile = null;
        for (Map.Entry<String, String> entry : MyTestContext.getTestStats().entrySet()) {
            testName = entry.getKey();
            destFile = testName + "_" + dateFormat.format(new Date()) + ".png";
            String[] err = null;
            err = tr.getThrowable().getMessage().split("\\n");
            err[0] = err[0] + "\n. Screen shot saved at /screenshots/" + destFile;
            testFailed.put(testName, new Object[] { entry.getValue(), err[0], MyTestContext.getStep(), time });
            t = entry.getKey();
        }
        addTestLogs(t);
        MyTestContext.testStats.remove();
        WebDriver driver = new Augmenter().augment(driver());
        File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        String destDir = "screenshots";
        new File(destDir).mkdirs();
        FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
    } catch (Exception e) {
        StringWriter s = new StringWriter();
        PrintWriter p = new PrintWriter(s, true);
        e.printStackTrace(p);
        log.error(s.getBuffer().toString());
        Assert.fail("Check log file for error details");
    }
}

From source file:com.ppcxy.cyfm.showcase.demos.web.StaticContentServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // ??//from w ww  .  ja  v a 2 s.  c  om
    String contentPath = request.getParameter("contentPath");
    if (StringUtils.isBlank(contentPath)) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "contentPath parameter is required.");
        return;
    }

    // ??.
    ContentInfo contentInfo = getContentInfo(contentPath);

    // ?EtagModifiedSince Header?, ??304,.
    if (!Servlets.checkIfModifiedSince(request, response, contentInfo.lastModified)
            || !Servlets.checkIfNoneMatchEtag(request, response, contentInfo.etag)) {
        return;
    }

    // Etag/
    Servlets.setExpiresHeader(response, Servlets.ONE_YEAR_SECONDS);
    Servlets.setLastModifiedHeader(response, contentInfo.lastModified);
    Servlets.setEtag(response, contentInfo.etag);

    // MIME
    response.setContentType(contentInfo.mimeType);

    // ?Header
    if (request.getParameter("download") != null) {
        Servlets.setFileDownloadHeader(request, response, contentInfo.fileName);
    }

    // OutputStream
    OutputStream output;
    if (checkAccetptGzip(request) && contentInfo.needGzip) {
        // outputstream, http1.1 trunked??content-length.
        output = buildGzipOutputStream(response);
    } else {
        // outputstream, content-length.
        response.setContentLength(contentInfo.length);
        output = response.getOutputStream();
    }

    // ?,?input file
    FileUtils.copyFile(contentInfo.file, output);
    output.flush();
}

From source file:com.iyonger.apm.web.model.Home.java

/**
 * Copy the given file from given location.
 *
 * @param from file location//from   w w w  .  j  ava  2  s. c om
 */
public void copyFrom(File from) {
    // Copy missing files
    try {
        for (File file : checkNotNull(from.listFiles())) {
            if (!(new File(directory, file.getName()).exists())) {
                FileUtils.copyFileToDirectory(file, directory);
            } else {
                File orgConf = new File(directory, "org_conf");
                if (orgConf.mkdirs()) {
                    LOGGER.info("{}", orgConf.getPath());
                }
                FileUtils.copyFile(file, new File(orgConf, file.getName()));
            }
        }
    } catch (IOException e) {
        throw processException("Fail to copy files from " + from.getAbsolutePath(), e);
    }
}

From source file:com.badlogicgames.packr.Packr.java

public void pack(Config config) throws IOException {
    // create output dir
    File out = new File(config.outDir);
    File target = out;/*  w  ww . j  a  v  a 2 s .c  om*/
    if (out.exists()) {
        if (new File(".").equals(out)) {
            System.out.println("Output directory equals working directory, aborting");
            System.exit(-1);
        }

        System.out.println("Output directory '" + out.getAbsolutePath() + "' exists, deleting");
        FileUtils.deleteDirectory(out);
    }
    out.mkdirs();

    Map<String, String> values = new HashMap<String, String>();
    values.put("${executable}", config.executable);
    values.put("${bundleIdentifier}", "com.yourcompany.identifier"); // FIXME add as a param

    // if this is a mac build, let's create the app bundle structure
    if (config.platform == Platform.mac) {
        new File(out, "Contents").mkdirs();
        FileUtils.writeStringToFile(new File(out, "Contents/Info.plist"),
                readResourceAsString("/Info.plist", values));
        target = new File(out, "Contents/MacOS");
        target.mkdirs();
        new File(out, "Contents/Resources").mkdirs();
        // FIXME copy icons
    }

    // write jar, exe and config to target folder
    byte[] exe = null;
    String extension = "";
    switch (config.platform) {
    case windows:
        exe = readResource("/packr-windows.exe");
        extension = ".exe";
        break;
    case linux32:
        exe = readResource("/packr-linux");
        break;
    case linux64:
        exe = readResource("/packr-linux-x64");
        break;
    case mac:
        exe = readResource("/packr-mac");
        break;
    }
    FileUtils.writeByteArrayToFile(new File(target, config.executable + extension), exe);
    new File(target, config.executable + extension).setExecutable(true);
    FileUtils.copyFile(new File(config.jar), new File(target, new File(config.jar).getName()));
    writeConfig(config, new File(target, "config.json"));

    // add JRE from local or remote zip file
    File jdkFile = null;
    if (config.jdk.startsWith("http://") || config.jdk.startsWith("https://")) {
        System.out.println("Downloading JDK from '" + config.jdk + "'");
        jdkFile = new File(target, "jdk.zip");
        InputStream in = new URL(config.jdk).openStream();
        OutputStream outJdk = FileUtils.openOutputStream(jdkFile);
        IOUtils.copy(in, outJdk);
        in.close();
        outJdk.close();
    } else {
        jdkFile = new File(config.jdk);
    }
    File tmp = new File(target, "tmp");
    tmp.mkdirs();
    System.out.println("Unpacking JRE");
    ZipUtil.unpack(jdkFile, tmp);
    File jre = searchJre(tmp);
    if (jre == null) {
        System.out.println("Couldn't find JRE in JDK, see '" + tmp.getAbsolutePath() + "'");
        System.exit(-1);
    }
    FileUtils.copyDirectory(jre, new File(target, "jre"));
    FileUtils.deleteDirectory(tmp);
    if (config.jdk.startsWith("http://") || config.jdk.startsWith("https://")) {
        jdkFile.delete();
    }

    // copy resources
    System.out.println("copying resources");
    copyResources(target, config.resources);

    // perform tree shaking      
    if (config.minimizeJre != null) {
        minimizeJre(config, target);
    }

    System.out.println("Done!");
}