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:application.model.business.EmotionBOImpl.java

@Override
public boolean addEmotion(ArrayList<EmotionPOJO> arrEmotionAdd) {
    String listEmotionValueJSON = "";
    boolean isAdd = emotionDAO.addEmotion(listEmotionValueJSON);
    if (isAdd) {/*ww  w . ja v  a2  s.c  o  m*/
        for (EmotionPOJO emotion : arrEmotionAdd) {
            String linkImage = emotion.linkImage;
            String groupEmotionId = Integer.toString(emotion.groupEmotionId);
            //link empty when it is exist in database
            if (!"".equals(linkImage)) {

                String sourcePath = Registry.get("imageHost") + "/emotions-image/"
                        + UploadConstant.UPLOAD_DIRECTORY + "/" + linkImage;

                //item.getString --> groupEmotion chon
                String desPath = Registry.get("imageHost") + "/emotions-image/" + groupEmotionId + "/"
                        + linkImage;

                File sourceDir = new File(sourcePath);
                File desDir = new File(desPath);
                if (sourceDir.exists()) {
                    try {
                        FileUtils.copyFile(sourceDir, desDir);
                    } catch (IOException ex) {
                        Logger.getLogger(EmotionBOImpl.class.getName()).log(Level.SEVERE, null, ex);
                        isAdd = false;
                    }
                    sourceDir.delete();

                }
            }
        }
    }
    return isAdd;
}

From source file:com.khepry.utilities.GenericUtilities.java

public static void displayLogFile(String logFilePath, long logSleepMillis, String xsltFilePath,
        String xsldFilePath) {/*from  w  ww.ja va 2  s .  c  o  m*/
    Logger.getLogger("").getHandlers()[0].close();
    // only display the log file
    // if the logSleepMillis property
    // is greater than zero milliseconds
    if (logSleepMillis > 0) {
        try {
            Thread.sleep(logSleepMillis);
            File logFile = new File(logFilePath);
            File xsltFile = new File(xsltFilePath);
            File xsldFile = new File(xsldFilePath);
            File tmpFile = File.createTempFile("tmpLogFile", ".xhtml", logFile.getParentFile());
            if (logFile.exists()) {
                if (xsltFile.exists() && xsldFile.exists()) {
                    String xslFilePath;
                    String xslFileName;
                    String dtdFilePath;
                    String dtdFileName;
                    try {
                        xslFileName = new File(logFilePath).getName().replace(".xhtml", ".xsl");
                        xslFilePath = logFile.getParentFile().toString().concat("/").concat(xslFileName);
                        FileUtils.copyFile(new File(xsltFilePath), new File(xslFilePath));
                        dtdFileName = new File(logFilePath).getName().replace(".xhtml", ".dtd");
                        dtdFilePath = logFile.getParentFile().toString().concat("/").concat(dtdFileName);
                        FileUtils.copyFile(new File(xsldFilePath), new File(dtdFilePath));
                    } catch (IOException ex) {
                        String message = Level.SEVERE.toString().concat(": ").concat(ex.getLocalizedMessage());
                        Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, message, ex);
                        GenericUtilities.outputToSystemErr(message, logSleepMillis > 0);
                        return;
                    }
                    BufferedWriter bw = Files.newBufferedWriter(Paths.get(tmpFile.getAbsolutePath()),
                            Charset.defaultCharset(), StandardOpenOption.CREATE);
                    List<String> logLines = Files.readAllLines(Paths.get(logFilePath),
                            Charset.defaultCharset());
                    for (String line : logLines) {
                        if (line.startsWith("<!DOCTYPE log SYSTEM \"logger.dtd\">")) {
                            bw.write("<!DOCTYPE log SYSTEM \"" + dtdFileName + "\">\n");
                            bw.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslFileName + "\"?>\n");
                        } else {
                            bw.write(line.concat("\n"));
                        }
                    }
                    bw.write("</log>\n");
                    bw.close();
                }
                // the following statement is commented out because it's not quite ready for prime-time yet
                // Files.write(Paths.get(logFilePath), transformLogViaXSLT(logFilePath, xsltFilePath).getBytes(), StandardOpenOption.CREATE);
                Desktop.getDesktop().open(tmpFile);
            } else {
                Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, logFilePath,
                        new FileNotFoundException());
            }
        } catch (InterruptedException | IOException ex) {
            Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectWMFListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    String path = this.selectWMFUI.getPath();
    if (path == null)
        return;//from  w  ww  . j av  a  2 s  .c om
    if (path.contains("%")) {
        this.selectWMFUI.displayMessage("File name can not contain percent ('%') symbol.");
        return;
    }
    File file = new File(path);
    if (file.exists()) {
        if (file.isFile()) {
            if (!this.checkFormat(file))
                return;

            String newPath;
            if (file.getName().endsWith(".words")) {
                newPath = this.dataType.getPath().getAbsolutePath() + File.separator + file.getName();
            } else {
                newPath = this.dataType.getPath().getAbsolutePath() + File.separator + file.getName()
                        + ".words";
            }

            File copiedFile = new File(newPath);
            try {
                FileUtils.copyFile(file, copiedFile);
                ((ClinicalData) this.dataType).setWMF(copiedFile);

                this.selectWMFUI.displayMessage("File has been added");
                WorkPart.updateSteps();
                //to do: update files list
                UsedFilesPart.sendFilesChanged(dataType);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                this.selectWMFUI.displayMessage("Error: " + e.getLocalizedMessage());
                e.printStackTrace();
            }
        } else {
            this.selectWMFUI.displayMessage("This is a directory");
        }
    } else {
        this.selectWMFUI.displayMessage("This path does no exist");
    }
}

From source file:de.uzk.hki.da.repository.FakeRepositoryFacade.java

@Override
public void ingestFile(String objectId, String collection, String fileId, File file, String label,
        String mimeType) throws RepositoryException, IOException {
    try {// www.j a va  2s .  c o m
        File destFile = getFile(objectId, collection, fileId);
        FileUtils.copyFile(file, destFile);
    } catch (IOException e) {
        throw new RepositoryException("Unable to create file " + collection + "/" + objectId + "/" + fileId, e);
    }
}

From source file:ZipSourceCallable.java

@Override
public String invoke(File f, VirtualChannel channel) throws IOException {
    String sourceFilePath = workspace.getRemote();

    // Create a temp file to zip into so we do not zip ourselves
    File tempFile = File.createTempFile(f.getName(), null, null);
    try (OutputStream zipFileOutputStream = new FileOutputStream(tempFile)) {
        try (ZipOutputStream out = new ZipOutputStream(zipFileOutputStream)) {
            zipSource(workspace, sourceFilePath, out, sourceFilePath);
        }/*from  w  w  w.  j a v a 2s  .  c o  m*/
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        throw new IOException(e);
    }

    // Copy zip to the location we expect it to be in
    FileUtils.copyFile(tempFile, f);

    try {
        tempFile.delete();
    } catch (Exception e) {
        // If this fails, the file will just be cleaned up
        // by the system later.  We are just trying to be
        // good citizens here.
    }

    String zipFileMD5;

    // Build MD5 checksum before returning
    try (InputStream zipFileInputStream = new FileInputStream(f)) {
        zipFileMD5 = new String(encodeBase64(DigestUtils.md5(zipFileInputStream)), Charsets.UTF_8);
        return zipFileMD5;
    }
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectCMFListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    String path = this.selectCMFUI.getPath();
    if (path == null)
        return;/*  w  ww .  jav  a  2s  . c o m*/
    if (path.contains("%")) {
        this.selectCMFUI.displayMessage("File name can not contain percent ('%') symbol.");
        return;
    }
    File file = new File(path);
    if (file.exists()) {
        if (file.isFile()) {
            if (!this.checkFormat(file))
                return;
            String newPath;
            if (file.getName().endsWith(".columns")) {
                newPath = this.dataType.getPath().getAbsolutePath() + File.separator + file.getName();
            } else {
                newPath = this.dataType.getPath().getAbsolutePath() + File.separator + file.getName()
                        + ".columns";
            }

            File copiedFile = new File(newPath);
            try {
                FileUtils.copyFile(file, copiedFile);
                ((ClinicalData) this.dataType).setCMF(copiedFile);

                this.selectCMFUI.displayMessage("File has been added");
                WorkPart.updateSteps();
                //to do: update files list
                UsedFilesPart.sendFilesChanged(dataType);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                this.selectCMFUI.displayMessage("File error: " + e.getLocalizedMessage());
                e.printStackTrace();
            }
        } else {
            this.selectCMFUI.displayMessage("This is a directory");
        }
    } else {
        this.selectCMFUI.displayMessage("This path does no exist");
    }
}

From source file:com.rapleaf.hank.storage.LocalPartitionRemoteFileOps.java

@Override
public void copyToLocalRoot(String remoteSourceRelativePath, String localDestinationRoot) throws IOException {
    File source = new File(getAbsoluteRemotePath(remoteSourceRelativePath));
    File destination = new File(localDestinationRoot + "/" + source.getName());
    FileUtils.copyFile(source, destination);
}

From source file:net.monofraps.gradlebukkit.tasks.CopyPluginsTask.java

@TaskAction
public void doWork() throws LifecycleExecutionException, IOException {
    final File bukkitTargetDir = new File(getProject().getBuildDir(), "bukkit");
    final File bukkitPluginsDir = new File(bukkitTargetDir, "plugins");

    if (!bukkitTargetDir.exists()) {
        if (!bukkitTargetDir.mkdir())
            throw new LifecycleExecutionException(
                    "Failed to create bukkit target directory " + bukkitTargetDir);
    }/* ww w . jav a  2 s. c  o m*/
    if (!bukkitPluginsDir.exists()) {
        if (!bukkitPluginsDir.mkdir())
            throw new LifecycleExecutionException(
                    "Failed to create bukkit plugin directory " + bukkitPluginsDir);
    }

    for (final Object fileObject : ((Bukkit) getProject().getExtensions().getByName("bukkit"))
            .getPluginsToCopy()) {
        final File plugin = getProject().file(fileObject);
        if (!plugin.exists()) {
            throw new LifecycleExecutionException(
                    "Plugin copy failed: Plugin file " + plugin + " does not exist.");
        }

        final File target = new File(bukkitPluginsDir, plugin.getName());
        if (target.exists())
            continue;

        getLogger().lifecycle("Copying " + plugin + " to " + target);

        if (plugin.isDirectory()) {
            FileUtils.copyDirectory(plugin, target);
        } else {
            FileUtils.copyFile(plugin, target);
        }
    }
}

From source file:net.sourceforge.jweb.maven.minify.YUICompressorMinifier.java

public void minify(File f) {
    File saveTo = getSaveFile(f, "");

    String parent = saveTo.getParent();
    String pname = saveTo.getName().substring(0, saveTo.getName().indexOf("."));
    String sname = saveTo.getName().substring(saveTo.getName().lastIndexOf("."));
    String finalName = parent + File.separator + pname + this.getMinifyMojo().getMiniPrefix() + sname;
    File finalFile = new File(finalName);
    try {//from  www . java  2s.com
        FileUtils.writeStringToFile(finalFile, "");

        String[] provied = this.getMinifyMojo().getYuiArguments();
        int length = (provied == null ? 0 : provied.length);
        length += 5;
        int i = 0;

        String[] ret = new String[length];

        ret[i++] = "--type";
        ret[i++] = (saveTo.getName().toLowerCase().endsWith(".css") ? "css" : "js");

        if (provied != null) {
            for (String s : provied) {
                ret[i++] = s;
            }
        }

        ret[i++] = f.getAbsolutePath();
        ret[i++] = "-o";
        ret[i++] = finalName;
        StringBuilder builder = new StringBuilder();
        builder.append("yuicompressor ");
        for (String s : ret) {
            builder.append(s).append(" ");
        }
        this.getLog().debug(builder);

        YUICompressorNoExit.main(ret);
    } catch (Exception e) {
        //e.printStackTrace();
        this.getLog().warn(e);
        this.getLog().info("minifier will copy source only");
        try {
            FileUtils.copyFile(f, finalFile);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

From source file:io.wcm.devops.conga.plugins.sling.postprocessor.ProvisioningOsgiConfigPostProcessorTest.java

@Test
public void testProvisioningExample() throws Exception {

    // post process example valid provisioning file
    File provisioningFile = new File(targetDir, "provisioningExample.txt");
    FileUtils.copyFile(new File(getClass().getResource("/validProvisioning.txt").toURI()), provisioningFile);
    postProcess(provisioningFile);/*from   w w  w  .j av a 2  s. c  o  m*/

    // validate generated configs
    Dictionary<?, ?> config = readConfig("my.pid.config");
    assertEquals("value1", config.get("stringProperty"));
    assertArrayEquals(new String[] { "v1", "v2", "v3" }, (String[]) config.get("stringArrayProperty"));
    assertEquals(true, config.get("booleanProperty"));
    assertEquals(999999999999L, config.get("longProperty"));

    assertExists("my.factory-my.pid.config");
    assertExists("mode1/my.factory-my.pid2.config");
    assertExists("mode2/my.pid2.config");
}