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) throws IOException 

Source Link

Document

Copies a file to a directory preserving the file date.

Usage

From source file:net.sourceforge.atunes.kernel.executors.processes.ExportFilesProcess.java

public void run() {
    File destination = new File(path);
    int filesExported = 0;

    HandlerProxy.getVisualHandler().getExportProgressDialog().getProgressLabel()
            .setText(Integer.toString(filesExported));
    boolean errors = false;
    logger.info("Exporting songs to " + destination);
    try {/*from ww  w.ja  va  2s. co m*/
        for (Iterator it = songs.iterator(); it.hasNext() && !interrupt;) {
            AudioFile song = (AudioFile) it.next();
            File destDir = getDirectory(song, destination, structure);
            FileUtils.copyFileToDirectory(song, destDir);
            if (filePattern != null) {
                File destFile = new File(
                        destDir.getAbsolutePath() + SystemProperties.fileSeparator + song.getName());
                String newName = getNewName(filePattern, song);
                destFile.renameTo(
                        new File(destDir.getAbsolutePath() + SystemProperties.fileSeparator + newName));
            }
            filesExported++;
            HandlerProxy.getVisualHandler().getExportProgressDialog().getProgressLabel()
                    .setText(Integer.toString(filesExported));
            HandlerProxy.getVisualHandler().getExportProgressDialog().getProgressBar().setValue(filesExported);
        }
    } catch (IOException e) {
        errors = true;
        logger.error(e.getMessage());
    }
    logger.info("Exporting process done");
    CopyProgressDialog dialog = HandlerProxy.getVisualHandler().getExportProgressDialog();
    dialog.setVisible(false);
    if (errors)
        HandlerProxy.getVisualHandler().showErrorDialog(LanguageTool.getString("ERRORS_IN_EXPORT_PROCESS"));
}

From source file:com.dotcms.publisher.pusher.bundler.LanguageBundler.java

private void copyFileToBundle(File bundleRoot, File messagesDir, Date lastBundleDate)
        throws IOException, DotBundleException, DotDataException, DotSecurityException, DotPublisherException {

    String myFolderUrl = bundleRoot.getPath() + File.separator + "messages";
    File bundleFolderMessages = new File(myFolderUrl);

    for (File lang : FileUtils.listFiles(messagesDir, new String[] { "properties" }, false)) {
        long lastMod = lang.lastModified();
        long startTime = -1;
        if (lastBundleDate != null)
            startTime = lastBundleDate.getTime();
        if (lastMod > startTime) {
            if (!bundleFolderMessages.exists())
                bundleFolderMessages.mkdirs();

            FileUtils.copyFileToDirectory(lang, bundleFolderMessages);
        }/*from   ww  w  . j  a  v a2  s  .c  om*/
    }
}

From source file:controller.NewEntryDeleteControllerTest.java

@Before
public void setUp() {
    File file = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users"
            + fSeparator + "Panagiwtis Georgiadis" + fSeparator + "Entries" + fSeparator + "Entry1");
    file.mkdirs();//from w w w  . j  a v a2  s  . c  o m
    file = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users"
            + fSeparator + "Panagiwtis Georgiadis" + fSeparator + "Entries" + fSeparator + "Entry2" + fSeparator
            + "Images");
    file.mkdirs();
    File imageFile = new File(System.getProperty("user.dir") + fSeparator + "src" + fSeparator + "test"
            + fSeparator + "java" + fSeparator + "resources" + fSeparator + "testImg.jpg");
    try {
        FileUtils.copyFileToDirectory(imageFile, file);
    } catch (IOException ex) {
        Logger.getLogger(NewEntryDeleteControllerTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    Login.username = "Panagiwtis Georgiadis";
}

From source file:net.refractions.udig.document.source.ShpDocUtils.java

/**
 * Copies a read-only copy of the old file into new file directory.
 * /*  w  w w .  ja  va  2 s .com*/
 * @param oldFile
 * @param newFileDir
 * @return new file
 */
public static File copyFile(File oldFile, File newFileDir) {
    try {
        if (!newFileDir.exists()) {
            newFileDir.mkdir();
        }
        final File newFile = new File(newFileDir, oldFile.getName());
        if (!newFile.exists()) {
            FileUtils.copyFileToDirectory(oldFile, newFileDir);
            newFile.setReadOnly();
        }
        return newFile;
    } catch (IOException e) {
        // Should not happen
        e.printStackTrace();
    }
    return null;
}

From source file:net.sf.taverna.t2.maven.plugins.TavernaPluginPrepareBundlesMojo.java

public void execute() throws MojoExecutionException, MojoFailureException {
    osgiUtils = new MavenOsgiUtils(project, repositorySystemSession, projectDependenciesResolver, getLog());
    outputDirectory.mkdirs();/*w  w w .ja v a  2  s  .c  o m*/

    Set<BundleArtifact> bundleDependencies = osgiUtils.getBundleDependencies(Artifact.SCOPE_COMPILE,
            Artifact.SCOPE_RUNTIME);
    try {
        for (BundleArtifact bundleArtifact : bundleDependencies) {
            Artifact artifact = bundleArtifact.getArtifact();
            FileUtils.copyFileToDirectory(bundleArtifact.getArtifact().getFile(),
                    new File(outputDirectory, artifact.getGroupId()));
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying dependecies to archive directory", e);
    }
}

From source file:co.runrightfast.vertx.orientdb.hooks.RunRightFastOrientDBLifeCycleListenerTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    orientdbHome.mkdirs();//from   w  w w.ja  v  a  2  s  . c o  m
    FileUtils.cleanDirectory(orientdbHome);
    FileUtils.deleteDirectory(orientdbHome);
    log.logp(INFO, CLASS_NAME, "setUpClass",
            String.format("orientdbHome.exists() = %s", orientdbHome.exists()));

    final File configDirSrc = new File("src/test/resources/orientdb/config");
    final File configDirTarget = new File(orientdbHome, "config");
    FileUtils.copyFileToDirectory(new File(configDirSrc, "default-distributed-db-config.json"),
            configDirTarget);
    FileUtils.copyFileToDirectory(new File(configDirSrc, "hazelcast.xml"), configDirTarget);

    server = createOServer();
    server.activate();

    final File dbDir = new File(orientdbHome,
            String.format("databases/%s", RunRightFastOrientDBLifeCycleListenerTest.class.getSimpleName()));
    final String dbUrl = "plocal:" + dbDir.getAbsolutePath();
    try (final ODatabase db = new ODatabaseFactory().createDatabase("document", dbUrl).create()) {
        log.logp(INFO, CLASS_NAME, "setUpClass", String.format("created db = %s", db.getName()));

        final OClass timestampedClass = db.getMetadata().getSchema()
                .createAbstractClass(Timestamped.class.getSimpleName());
        timestampedClass.createProperty(Timestamped.Field.created_on.name(), OType.DATETIME);
        timestampedClass.createProperty(Timestamped.Field.updated_on.name(), OType.DATETIME);

        final OClass logRecordClass = db.getMetadata().getSchema()
                .createClass(EventLogRecord.class.getSimpleName())
                .setSuperClasses(ImmutableList.of(timestampedClass));
        logRecordClass.createProperty(EventLogRecord.Field.event.name(), OType.STRING);
    }
}

From source file:de.uzk.hki.da.cb.UnpackActionTests.java

/**
 * Sets the up./*from w ww.j av  a 2 s  .  c  o  m*/
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Before
public void setUp() throws IOException {
    n.setIngestAreaRootPath(ingestAreaRootPath);
    n.setWorkAreaRootPath(workAreaRootPath);

    new File(CONF).mkdir();
    FileUtils.copyDirectory(Path.makeFile(workAreaRootPath, "ingest_"),
            Path.makeFile(workAreaRootPath, "ingest"));
    FileUtils.copyFileToDirectory(C.PREMIS_XSD_TEST, new File(CONF));
    FileUtils.copyFileToDirectory(C.XLINK_XSD_TEST, new File(CONF));
    FileUtils.copyFileToDirectory(C.CONTRACT_XSD_TEST, new File(CONF));

    gate.setWorkAreaRootPath(workAreaRootPath.toString());
    gate.setFreeDiskSpacePercent(5);
    gate.setFileSizeFactor(3);
    action.setIngestGate(gate);

    this.o.getContractor().setFriendlyFileExtensions(SIDECAR_EXTENSIONS);
}

From source file:de.thischwa.pmcms.gui.listener.ListenerAddSite.java

@Override
public void widgetSelected(SelectionEvent e) {
    logger.debug("SEL add site");
    Site site = new Site();
    if (DialogManager.startDialogPersitentPojo(e.display.getActiveShell(), site)) {
        File defaultResourceDir = new File(InitializationManager.getBean(PropertiesManager.class)
                .getProperty("pmcms.dir.defaultresources"));
        File srcDir = new File(defaultResourceDir.getAbsoluteFile(), "sites");
        File srcConfigDir = new File(srcDir, "configuration");
        File destDir = PoPathInfo.getSiteDirectory(site);
        File destConfigDir = new File(destDir, "configuration");
        destConfigDir.mkdirs();//from   w  w w  .ja  v a 2 s  .c  o  m
        try {
            // copy required files
            FileUtils.copyFileToDirectory(new File(srcDir, "format.css"), destDir);
            FileUtils.copyFileToDirectory(new File(srcConfigDir, "fckconfig.js"), destConfigDir);
            FileUtils.copyFileToDirectory(new File(srcConfigDir, "fckstyles.xml"), destConfigDir);

            // read the templates
            site.add(buildTemplate(srcDir, "layout.html", site, null));
            File srcTemplatedir = new File(srcDir, "templates");
            site.add(buildTemplate(srcTemplatedir, "gallery.html", site, TemplateType.GALLERY));
            site.add(buildTemplate(srcTemplatedir, "image.html", site, TemplateType.IMAGE));
            site.add(buildTemplate(srcTemplatedir, "page.html", site, TemplateType.PAGE));

            // read the macro
            Macro macro = new Macro();
            macro.setParent(site);
            macro.setName("user_menu.vm");
            macro.setText(FileTool.toString(new File(srcConfigDir, "user_menu.vm")));
        } catch (IOException e1) {
            throw new FatalException("While construct the default file structure of a site: " + e1.getMessage(),
                    e1);
        }

        SiteHolder siteHolder = InitializationManager.getBean(SiteHolder.class);
        siteHolder.setSite(site);
        TreeViewManager treeViewManager = InitializationManager.getBean(TreeViewManager.class);
        treeViewManager.fillAndExpands(site);
        BrowserManager browserManager = InitializationManager.getBean(BrowserManager.class);
        browserManager.showHelp();

        WorkspaceToolBarManager.actionAfterSiteRenamed(site);
    }
}

From source file:com.athomas.androidkickstartr.util.LibraryHelper.java

private void copyToLibs(String jar) {
    try {//w  ww.  ja v a  2 s .  com
        File library = fileHelper.getLibraryFile(jar);
        File libsDir = fileHelper.getTargetLibsDir();
        FileUtils.copyFileToDirectory(library, libsDir);
    } catch (IOException e) {
        LOGGER.error("a problem occured during the copy of " + jar + " libs", e);
    }
}

From source file:com.gemstone.gemfire.test.dunit.standalone.ProcessManager.java

public synchronized void launchVM(int vmNum) throws IOException {
    if (processes.containsKey(vmNum)) {
        throw new IllegalStateException("VM " + vmNum + " is already running.");
    }/*from w  w w . j a  va 2  s  .c  o  m*/

    String[] cmd = buildJavaCommand(vmNum, namingPort);
    System.out.println("Executing " + Arrays.asList(cmd));
    File workingDir = getVMDir(vmNum);
    try {
        FileUtil.delete(workingDir);
    } catch (IOException e) {
        //This delete is occasionally failing on some platforms, maybe due to a lingering
        //process. Allow the process to be launched anyway.
        System.err.println(
                "Unable to delete " + workingDir + ". Currently contains " + Arrays.asList(workingDir.list()));
    }
    workingDir.mkdirs();
    if (log4jConfig != null) {
        FileUtils.copyFileToDirectory(log4jConfig, workingDir);
    }

    //TODO - delete directory contents, preferably with commons io FileUtils
    Process process = Runtime.getRuntime().exec(cmd, null, workingDir);
    pendingVMs++;
    ProcessHolder holder = new ProcessHolder(process);
    processes.put(vmNum, holder);
    linkStreams(vmNum, holder, process.getErrorStream(), System.err);
    linkStreams(vmNum, holder, process.getInputStream(), System.out);
}