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

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

Introduction

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

Prototype

public static void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate)
        throws IOException 

Source Link

Document

Copies a file to a directory optionally preserving the file date.

Usage

From source file:org.apache.hive.beeline.util.QFileClient.java

public void overwriteResults() {
    try {//from  w  ww .  j  ava 2 s  .  com
        if (expectedFile.exists()) {
            FileUtils.forceDelete(expectedFile);
        }
        FileUtils.copyFileToDirectory(outputFile, expectedDirectory, true);
    } catch (IOException e) {
        LOG.error("Failed to overwrite results!", e);
    }
}

From source file:org.eclipse.koneki.ldt.debug.ui.internal.launchconfiguration.attach.LuaAttachMainTab.java

protected void createClientInfo(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    GridLayoutFactory.swtDefaults().applyTo(comp);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(comp);

    Link lnkDocumentation = new Link(comp, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(lnkDocumentation);
    lnkDocumentation.setText(NLS.bind(/*  w  w  w  .  ja v  a  2s .  c  o  m*/
            org.eclipse.koneki.ldt.debug.ui.internal.launchconfiguration.attach.Messages.LuaAttachMainTab_client_info_description,
            LuaDebugConstants.DEBUGGER_FILE_NAME));

    lnkDocumentation.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            if (LuaDebugConstants.DEBUGGER_FILE_NAME.equals(event.text)) {
                // get debugger file

                // prompt a directory selection dialog
                DirectoryDialog directoryDialog = new DirectoryDialog(
                        PlatformUI.getWorkbench().getDisplay().getActiveShell());
                String selectedDirPath = directoryDialog.open();
                if (selectedDirPath != null) {
                    // if directory is selected :
                    File destDir = new File(selectedDirPath);

                    // get the debugger file
                    try {
                        URL debuggerEntry = org.eclipse.koneki.ldt.debug.core.internal.Activator.getDefault()
                                .getBundle().getEntry(LuaDebugConstants.DEBUGGER_PATH);
                        File debuggerFolder = new File(FileLocator.toFileURL(debuggerEntry).getFile());
                        File debuggerFile = new File(debuggerFolder, LuaDebugConstants.DEBUGGER_FILE_NAME);

                        // copy debugger file in selected directory
                        FileUtils.copyFileToDirectory(debuggerFile, destDir, true);

                        if (MessageDialog.openQuestion(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
                                org.eclipse.koneki.ldt.debug.ui.internal.launchconfiguration.attach.Messages.LuaAttachMainTab_copy_done_title,
                                NLS.bind(
                                        org.eclipse.koneki.ldt.debug.ui.internal.launchconfiguration.attach.Messages.LuaAttachMainTab_copy_done_question,
                                        LuaDebugConstants.DEBUGGER_FILE_NAME))) {
                            Program.launch(destDir.toString());
                        }

                    } catch (IOException e) {
                        ErrorDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
                                org.eclipse.koneki.ldt.debug.ui.internal.launchconfiguration.attach.Messages.LuaAttachMainTab_copy_failed_title,
                                null,
                                new Status(IStatus.WARNING, Activator.PLUGIN_ID, NLS.bind(
                                        org.eclipse.koneki.ldt.debug.ui.internal.launchconfiguration.attach.Messages.LuaAttachMainTab_copy_failed_description,
                                        LuaDebugConstants.DEBUGGER_FILE_NAME), e));
                    }
                }
            } else
                // open documentation
                PlatformUI.getWorkbench().getHelpSystem()
                        .displayHelpResource(DocumentationLinksConstants.ATTACH_DEBUG);
        }
    });
}

From source file:org.isatools.isatab.export.DataFilesDispatcher.java

/**
 * Dispatch the files about a given assay group
 *
 * @param outPath where the files go, no dispatch done if this is null.
 *///from   w w  w. ja v  a  2s.  c  o  m
private void dispatchAssayGroup(final AssayGroup ag) throws IOException {
    SectionInstance assaySectionInstance = ag.getAssaySectionInstance();
    if (assaySectionInstance == null) {
        return;
    }

    Study study = ag.getStudy();

    // Copy the assay file to the submission repo
    String assayFileRelativePath = assaySectionInstance.getFileId();
    dispatchFileToSubmissionRepo(ag.getStudy(), "Assay File Name", assayFileRelativePath);

    for (Record record : assaySectionInstance.getRecords()) {
        int recSize = record.size();
        for (int fieldIndex = 0; fieldIndex < recSize; fieldIndex++) {
            // TODO: change this so that we get: field name, file-type, file-path
            String[] filePathPair = FormatExporter.getExternalFileValue(record, fieldIndex);

            if (filePathPair == null) {
                continue;
            }
            String fieldHeader = filePathPair[0], srcFileRelPath = filePathPair[1],
                    srcFileType = filePathPair[2];

            if (srcFileRelPath == null) {
                continue;
            }

            AnnotationTypes targetType;
            if ("raw".equals(srcFileType)) {
                targetType = AnnotationTypes.RAW_DATA_FILE_PATH;
            } else if ("processed".equals(srcFileType)) {
                targetType = AnnotationTypes.PROCESSED_DATA_FILE_PATH;
            } else {
                targetType = AnnotationTypes.GENERIC_DATA_FILE_PATH;
            }

            String targetPath = StringUtils.trimToNull(dataLocationMgr.getDataLocation(study,
                    ag.getMeasurement(), ag.getTechnology(), targetType));
            if (targetPath == null) {
                continue;
            }

            File srcFile = new File(sourcePath + "/" + srcFileRelPath);
            File targetDir = new File(targetPath);
            File targetFile = new File(targetPath + "/" + srcFileRelPath);

            if (!srcFile.exists()) {
                log.info("WARNING: Source file '" + srcFileRelPath + "' / '" + fieldHeader + "' not found");
            } else {

                if (targetFile.exists() && targetFile.lastModified() == srcFile.lastModified()) {
                    log.debug("Not copying " + srcFile.getCanonicalPath() + "' to '"
                            + targetFile.getCanonicalPath() + "': they seem to be the same.");
                } else {
                    log.trace("Copying data file '" + fieldHeader + "' / '" + srcFileRelPath
                            + "' to data repository...");
                    FileUtils.copyFileToDirectory(srcFile, targetDir, true);
                    // Needed cause of a bug in the previous function
                    targetFile.setLastModified(srcFile.lastModified());
                    log.trace("...done");
                    log.info("Data file '" + fieldHeader + "' / '" + srcFile.getCanonicalPath()
                            + "' copied to '" + targetDir.getCanonicalPath() + "'");
                }
            } // if
        } // for ( field )
    } // for ( record )
}

From source file:org.isatools.isatab.export.isatab.filesdispatching.ISATabExportDataFilesDispatcher.java

/**
 * Dispatch the files about a given assay group
 *
 * @param outPath where the files go, no dispatch done if this is null.
 */// ww w .jav a 2s  .  c om
private void dispatchAssayGroup(final AssayGroup ag) throws IOException {
    if (ag == null) {
        return;
    }

    SectionInstance assaySectionInstance = ag.getAssaySectionInstance();
    if (assaySectionInstance == null) {
        log.warn("I cannot find any record in the DB for the file: " + ag.getFilePath() + ", hope it's fine");
        return;
    }

    log.debug("Dispatching the files referred by " + ag.getFilePath());

    Study study = ag.getStudy();

    for (Record record : assaySectionInstance.getRecords()) {
        int recSize = record.size();
        for (int fieldIndex = 0; fieldIndex < recSize; fieldIndex++) {
            // TODO: change this so that we get: field name, file-type, file-path
            String[] filePathPair = FormatExporter.getExternalFileValue(record, fieldIndex);

            if (filePathPair == null) {
                continue;
            }
            String fieldHeader = filePathPair[0], srcFileRelPath = filePathPair[1],
                    srcFileType = filePathPair[2];

            if (srcFileRelPath == null) {
                continue;
            }

            AnnotationTypes targetType;
            if ("raw".equals(srcFileType)) {
                targetType = AnnotationTypes.RAW_DATA_FILE_PATH;
            } else if ("processed".equals(srcFileType)) {
                targetType = AnnotationTypes.PROCESSED_DATA_FILE_PATH;
            } else {
                targetType = AnnotationTypes.GENERIC_DATA_FILE_PATH;
            }

            String srcFilePath = dataLocationMgr.getDataLocation(study, ag.getMeasurement(), ag.getTechnology(),
                    targetType);
            if (srcFilePath == null) {
                log.trace("source path not available for the file " + srcFileRelPath);
                continue;
            }

            srcFilePath += "/" + srcFileRelPath;
            File srcFile = new File(srcFilePath);
            srcFilePath = srcFile.getCanonicalPath();
            File targetDir = new File(exportPath);
            String targetFilePath = exportPath + "/" + srcFileRelPath;
            File targetFile = new File(targetFilePath);
            targetFilePath = targetFile.getCanonicalPath();

            if (!srcFile.exists()) {
                log.info("WARNING: Source file '" + srcFilePath + "' / '" + fieldHeader + "' not found");
            } else {
                if (targetFile.exists() && targetFile.lastModified() == srcFile.lastModified()) {
                    log.debug("Not copying " + srcFilePath + "' to '" + targetFilePath
                            + "': they seem to be the same.");
                } else {
                    log.trace("Copying data file '" + fieldHeader + "' / '" + srcFilePath
                            + "' to data repository...");
                    FileUtils.copyFileToDirectory(srcFile, targetDir, true);
                    // Needed cause of a bug in the previous function
                    targetFile.setLastModified(srcFile.lastModified());
                    log.trace("...done");
                    log.info("Data file '" + fieldHeader + "' / '" + srcFilePath + "' copied to '"
                            + targetFilePath + "'");
                }
            } // if
        } // for ( field )
    } // for ( record )
}

From source file:org.isatools.tablib.export.FormatExporter.java

/**
 * Dispatch the submission files present in the format into a target path. This is an helper for dealing with
 * external data files during tabular exports.
 *//* www .  j a v  a  2 s .c  o  m*/
public void dispatchFiles(String sourcePath, String outPath) throws IOException {
    // All the external files
    for (String fileType : getExternalFileFieldHeaders()) {
        for (String filePath : getExternalFilePaths(fileType)) {
            File file = new File(sourcePath + "/" + filePath);
            if (!file.exists()) {
                log.warn("WARNING, Source file '" + filePath + "' not found");
                continue;
            }
            log.info("Dispatching file '" + fileType + "' / '" + filePath + "'");
            FileUtils.copyFileToDirectory(file, new File(outPath), true);
        }
    }
}

From source file:org.jahia.utils.maven.plugin.DeployMojo.java

private void copyToKarafDeploy(File srcFile) throws IOException {
    File deployDir = new File(getDataDir(), "karaf/deploy");
    getLog().info(/*w  ww. ja v  a  2  s .c  om*/
            "Copying file " + srcFile.getCanonicalPath() + " into folder " + deployDir.getCanonicalPath());
    FileUtils.copyFileToDirectory(srcFile, deployDir, false);
    getLog().info("...done");
}

From source file:org.jboss.arquillian.container.mobicents.servlet.sip.tomcat.embedded_7.MobicentsSipServletsContainer.java

@Override
public void startTomcatEmbedded(Properties sipStackProperties)
        throws UnknownHostException, org.apache.catalina.LifecycleException, LifecycleException {

    System.setProperty("javax.servlet.sip.ar.spi.SipApplicationRouterProvider",
            configuration.getSipApplicationRouterProviderClassName());
    if (bindAddress != null) {
        System.setProperty("org.mobicents.testsuite.testhostaddr", bindAddress);
    } else {/*from  w  w  w .j a  va2 s  .co m*/
        System.setProperty("org.mobicents.testsuite.testhostaddr", "127.0.0.1");
    }
    //Required in order to read the dar conf of each file
    //The Router in the arquillian.xml should be <property name="sipApplicationRouterProviderClassName">org.mobicents.servlet.sip.router.DefaultApplicationRouterProvider</property>
    String darConfiguration = Thread.currentThread().getContextClassLoader().getResource("test-dar.properties")
            .toString();
    if (darConfiguration != null) {
        System.setProperty("javax.servlet.sip.dar",
                Thread.currentThread().getContextClassLoader().getResource("test-dar.properties").toString());
    } else {
        System.setProperty("javax.servlet.sip.dar",
                Thread.currentThread().getContextClassLoader().getResource("empty-dar.properties").toString());
    }

    // creating the tomcat embedded == service tag in server.xml
    MobicentsSipServletsEmbeddedImpl embedded = new MobicentsSipServletsEmbeddedImpl();
    this.embedded = embedded;
    sipStandardService = (SipStandardService) embedded.getService();
    sipStandardService
            .setSipApplicationDispatcherClassName(SipApplicationDispatcherImpl.class.getCanonicalName());
    sipStandardService.setCongestionControlCheckingInterval(-1);
    sipStandardService.setAdditionalParameterableHeaders("additionalParameterableHeader");
    sipStandardService.setUsePrettyEncoding(true);
    sipStandardService.setName(serverName);
    if (sipStackProperties != null)
        sipStandardService.setSipStackProperties(sipStackProperties);
    // TODO this needs to be a lot more robust
    String tomcatHome = configuration.getTomcatHome();
    File tomcatHomeFile = null;
    if (tomcatHome != null) {
        if (tomcatHome.startsWith(ENV_VAR)) {
            String sysVar = tomcatHome.substring(ENV_VAR.length(), tomcatHome.length() - 1);
            tomcatHome = System.getProperty(sysVar);
            if (tomcatHome != null && tomcatHome.length() > 0 && new File(tomcatHome).isAbsolute()) {
                tomcatHomeFile = new File(tomcatHome);
                log.info("Using tomcat home from environment variable: " + tomcatHome);
            }
        } else {
            tomcatHomeFile = new File(tomcatHome);
        }
    }

    if (tomcatHomeFile == null) {
        tomcatHomeFile = new File(System.getProperty(TMPDIR_SYS_PROP), "mss-tomcat-embedded-7");
    }

    tomcatHomeFile.mkdirs();
    embedded.setCatalinaBase(tomcatHomeFile.getAbsolutePath());
    embedded.setCatalinaHome(tomcatHomeFile.getAbsolutePath());

    // creates the engine, i.e., <engine> element in server.xml
    Engine engine = embedded.createEngine();
    this.engine = engine;
    engine.setName(serverName);
    engine.setDefaultHost(bindAddress);
    engine.setService(sipStandardService);
    sipStandardService.setContainer(engine);
    embedded.addEngine(engine);

    // creates the host, i.e., <host> element in server.xml
    appBase = new File(tomcatHomeFile, configuration.getAppBase());
    appBase.mkdirs();

    //Host configuration
    StandardHost host = (StandardHost) embedded.createHost(bindAddress, appBase.getAbsolutePath());
    this.standardHost = host;

    if (configuration.getTomcatWorkDir() != null) {
        host.setWorkDir(configuration.getTomcatWorkDir());
    }
    host.setUnpackWARs(configuration.isUnpackArchive());

    host.setDeployOnStartup(false);
    host.setAutoDeploy(false);

    embedded.getEngine().addChild(host);

    //Copy the license file
    try {

        System.setProperty("telscale.license.dir", tomcatHomeFile.getPath());

        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader == null) {
            classLoader = Class.class.getClassLoader();
        }

        File license = FileUtils.toFile(classLoader.getResource("telestax-license.xml").toURI().toURL());
        if (license != null) {
            FileUtils.copyFileToDirectory(license, tomcatHomeFile, false);
        } else {
            try {
                InputStream is = classLoader.getResourceAsStream("telestax-license.xml");

                OutputStream os = new FileOutputStream(
                        tomcatHomeFile + File.separator + "telestax-license.xml");

                byte[] buffer = new byte[1024];
                int bytesRead;
                //read from is to buffer
                while ((bytesRead = is.read(buffer)) != -1) {
                    os.write(buffer, 0, bytesRead);
                }
                is.close();
                //flush OutputStream to write any buffered data to file
                os.flush();
                os.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    //          creates an http connector, i.e., <connector> element in server.xml
    Connector connector = embedded.createConnector(InetAddress.getByName(bindAddress), bindPort, false);
    embedded.setPort(bindPort);
    embedded.setHostname(bindAddress);
    embedded.addConnector(connector);
    embedded.setConnector(connector);

    // Enable JNDI - it is disabled by default.
    embedded.enableNaming();
    //         
    // starts embedded Mobicents Sip Serlvets
    embedded.start();
    embedded.getService().start();

    // creates an sip connector, i.e., <connector> element in server.xml
    for (SipConnector sipConnector : sipConnectors) {
        addSipConnector(sipConnector);
    }

    wasStarted = true;
}

From source file:org.jflicks.update.system.SystemUpdate.java

/**
 * {@inheritDoc}/*from ww  w  . j  a  v a  2s. c om*/
 */
public boolean update(UpdateState us) {

    boolean result = false;

    if (us != null) {

        result = true;
        if (us.getUpdateCount() > 0) {

            File[] array = us.getFiles();
            File wdir = us.getWorkingDirectory();
            String dir = us.getBundleDirectory();
            String sourceURL = us.getSourceURL();
            if ((array != null) && (wdir != null) && (sourceURL != null) && (dir != null)) {

                File bdir = new File(dir);
                for (int i = 0; i < array.length; i++) {

                    String fname = array[i].getName();
                    File wfile = new File(wdir, fname);
                    try {

                        URL url = new URL(sourceURL + fname);
                        FileUtils.copyURLToFile(url, wfile);

                    } catch (IOException ex) {

                        LogUtil.log(LogUtil.WARNING, ex.getMessage());
                        result = false;
                        break;
                    }
                }

                if (result) {

                    // Ok we have things downloaded.
                    File[] bundles = wdir.listFiles(new BundleFilter());
                    if ((bundles != null) && (bundles.length > 0)) {

                        for (int i = 0; i < bundles.length; i++) {

                            try {

                                FileUtils.copyFileToDirectory(bundles[i], bdir, false);

                            } catch (IOException ex) {

                                LogUtil.log(LogUtil.WARNING, ex.getMessage());
                                result = false;
                            }
                        }
                    }
                }
            }
        }
    }

    return (result);
}

From source file:org.jumpmind.metl.core.runtime.resource.LocalFileDirectory.java

@Override
public void copyToDir(String fromFilePath, String toDirPath) {
    try {/*www .  j  a va 2 s  .co  m*/
        File fromFile = new File(basePath, fromFilePath);
        File toDir = new File(basePath, toDirPath);
        File toFile = new File(toDir, fromFile.getName());
        toFile.delete();
        FileUtils.copyFileToDirectory(fromFile, toDir, true);
    } catch (IOException e) {
        throw new IoException(e);
    }
}

From source file:org.jvnet.hudson.plugins.thinbackup.backup.HudsonBackup.java

private void backupNextBuildNumberFile(final File jobDirectory, final File jobBackupDirectory)
        throws IOException {
    if (plugin.isBackupNextBuildNumber()) {
        final File nextBuildNumberFile = new File(jobDirectory, NEXT_BUILD_NUMBER_FILE_NAME);
        if (nextBuildNumberFile.exists()) {
            FileUtils.copyFileToDirectory(nextBuildNumberFile, jobBackupDirectory, true);
        }//from   w w  w  .  j  a  v a 2  s  . c o m
    }
}