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:org.apache.oodt.cas.resource.system.TestXmlRpcResourceManager.java

private void generateTestConfiguration() throws IOException {
    Properties config = new Properties();

    String propertiesFile = "." + File.separator + "src" + File.separator + "test" + File.separator
            + "resources" + File.separator + "test.resource.properties";
    System.getProperties().load(new FileInputStream(new File(propertiesFile)));

    // stage policy
    File tmpPolicyDir = null;//w w w .  j a  v a2 s.c o  m
    try {
        tmpPolicyDir = File.createTempFile("test", "ignore").getParentFile();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    for (File policyFile : new File("./src/test/resources/policy").listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isFile() && pathname.getName().endsWith(".xml");
        }
    })) {
        try {
            FileUtils.copyFileToDirectory(policyFile, tmpPolicyDir);
        } catch (Exception e) {
            fail(e.getMessage());
        }
    }

    config.setProperty("org.apache.oodt.cas.resource.nodes.dirs", tmpPolicyDir.toURI().toString());
    config.setProperty("org.apache.oodt.cas.resource.nodetoqueues.dirs", tmpPolicyDir.toURI().toString());

    System.getProperties().putAll(config);
    this.tmpPolicyDir = tmpPolicyDir;
}

From source file:org.apache.openjpa.eclipse.util.PCEnhancerHelperTest.java

private boolean checkEnhance(PCEnhancerHelper eh, String classNameToCheck) throws Exception {
    String classFileName = classPackage.replace('.', '/') + classNameToCheck + ".class";

    FileUtils.forceMkdir(targetDir);/*  w  w  w .  jav  a  2  s  .  c  o  m*/
    FileUtils.cleanDirectory(targetDir);
    FileUtils.copyFileToDirectory(new File(srcDir, classFileName),
            new File(targetDir, classPackage.replace('.', '/')));
    File classFile = new File(targetDir, classFileName);
    assertTrue(classFile.exists());

    return eh.enhance(classFile);
}

From source file:org.apache.parquet.tools.submit.FileFormat.java

public void CopyFiles(String srcDir, String dstDir) throws IOException {
    File source = new File(srcDir);
    File dest = new File(dstDir);

    if (source.isFile()) {
        FileUtils.copyFileToDirectory(source, dest);
    } else if (source.isDirectory()) {
        FileUtils.copyDirectoryToDirectory(source, dest);

    }/* w  w w .  ja  v a 2  s  .c  o m*/
}

From source file:org.apache.pluto.util.install.file.FileSystemInstaller.java

protected void copyFilesToDirectory(Collection dependencies, File destination) throws IOException {
    Iterator it = dependencies.iterator();
    while (it.hasNext()) {
        File from = (File) it.next();
        FileUtils.copyFileToDirectory(from, destination);
    }// w  w  w. j a  v  a 2  s.  co  m
}

From source file:org.apache.pluto.util.install.file.FileSystemInstaller.java

protected void copyFileToDirectory(File file, File destination) throws IOException {
    FileUtils.copyFileToDirectory(file, destination);
}

From source file:org.apache.pluto.util.install.file.jetty.Jetty5FileSystemInstaller.java

/**
 * NOTE: Order is important.  If the server is running, we want to
 * make sure that the correct order is preserved
 * <p/>//from   ww  w .  j a v  a 2  s .c  o  m
 * 1) Install endorsed dependencies
 * 2) Install shared dependencies
 * 4) Prep Time
 * -- Create a domain directory for the portal
 * -- Init the configs holder
 * 5) Install the Portlet Applications
 * 6) Install the Portal Application
 * 7) Finally, install the configs
 *
 * @param config
 * @throws org.apache.pluto.util.UtilityException
 *
 */
public void install(InstallationConfig config) throws UtilityException {
    File endorsedDir = getEndorsedDir(config);
    File sharedDir = getSharedDir(config);
    File domainDir = getWebAppDir(config);
    domainDir.mkdirs();
    File contextConfigurationDirectory = getConfigurationDir(config);

    try {

        // Jetty Doesn't need 'em
        //copyFilesToDirectory(config.getEndorsedDependencies(), endorsedDir);

        copyFilesToDirectory(config.getSharedDependencies(), sharedDir);

        Iterator it = config.getPortletApplications().values().iterator();
        while (it.hasNext()) {
            File portletApp = (File) it.next();
            FileUtils.copyFileToDirectory(portletApp, domainDir);
        }

        FileUtils.copyFileToDirectory(config.getPortalApplication(), domainDir);

        //            it = config.getPortletApplications().entrySet().iterator();
        //            while (it.hasNext()) {
        //                Map.Entry entry = (Map.Entry) it.next();
        //                String context = entry.getKey().toString();
        //                File portletApp = (File) entry.getValue();
        //
        //                File deployed = new File(domainDir, portletApp.getName());
        //                String contents = getPortletApplicationConfig(context, deployed);
        //                //FileWriter out = new FileWriter(
        //                //        new File(contextConfigurationDirectory, context + ".xml"));
        //                out.write(contents);
        //                out.flush();
        //                out.close();
        //            }

        //            File xmlFile = new File(contextConfigurationDirectory, config.getPortalContextPath() + ".xml");
        //            FileWriter out = new FileWriter(xmlFile);
        //            out.write(getPortalApplicationConfig(config));
        //            out.flush();
        //            out.close();
    } catch (IOException io) {
        throw new UtilityException(io);
    }
}

From source file:org.apache.sling.distribution.queue.impl.simple.SimpleDistributionQueueProviderTest.java

@Test
public void testEnableQueueProcessingWithCheckpointRecovery() throws Exception {
    File checkpointDirectory = new File("dummy-agent-simple-queues-checkpoints");
    File file = new File(getClass().getResource("/dummy-agent-checkpoint").getFile());
    FileUtils.copyFileToDirectory(file, checkpointDirectory);

    Scheduler scheduler = mock(Scheduler.class);
    ScheduleOptions options = mock(ScheduleOptions.class);
    when(scheduler.NOW(-1, 1)).thenReturn(options);
    when(scheduler.NOW(-1, 15)).thenReturn(options);
    when(options.canRunConcurrently(false)).thenReturn(options);
    when(options.name(any(String.class))).thenReturn(options);
    String name = "dummy-agent";
    try {/*w ww .jav a 2s.com*/
        SimpleDistributionQueueProvider simpledistributionQueueProvider = new SimpleDistributionQueueProvider(
                scheduler, name, true);
        DistributionQueueProcessor processor = mock(DistributionQueueProcessor.class);
        simpledistributionQueueProvider.enableQueueProcessing(processor, name);
        DistributionQueue queue = simpledistributionQueueProvider.getQueue(name);
        assertNotNull(queue);
        assertEquals(1, queue.getStatus().getItemsCount());
        DistributionQueueEntry head = queue.getHead();
        assertNotNull(head);
        DistributionQueueItem item = head.getItem();
        assertNotNull(item);
        String packageId = item.getPackageId();
        assertNotNull(packageId);
        assertEquals("DSTRQ1", item.get("internal.request.id"));
        assertArrayEquals(new String[] { "/foo", "bar" }, (String[]) item.get("request.paths"));
        assertArrayEquals(new String[] { "/foo" }, (String[]) item.get("request.deepPaths"));
        assertEquals("admin", item.get("internal.request.user"));
        assertEquals("ADD", item.get("request.type"));
        assertEquals("default", item.get("package.type"));
        assertEquals("1464090250095", item.get("internal.request.startTime"));
    } finally {
        FileUtils.deleteDirectory(new File(name + "-simple-queues-checkpoints"));
    }
}

From source file:org.apache.solr.client.solrj.SolrSchemalessExampleTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    File tempSolrHome = createTempDir().toFile();
    // Schemaless renames schema.xml -> schema.xml.bak, and creates + modifies conf/managed-schema,
    // which violates the test security manager's rules, which disallow writes outside the build dir,
    // so we copy the example/example-schemaless/solr/ directory to a new temp dir where writes are allowed.
    FileUtils.copyFileToDirectory(new File(ExternalPaths.SERVER_HOME, "solr.xml"), tempSolrHome);
    File collection1Dir = new File(tempSolrHome, "collection1");
    FileUtils.forceMkdir(collection1Dir);
    FileUtils.copyDirectoryToDirectory(new File(ExternalPaths.SCHEMALESS_CONFIGSET), collection1Dir);
    Properties props = new Properties();
    props.setProperty("name", "collection1");
    OutputStreamWriter writer = null;
    try {/*from w w  w  .j  av  a 2s .c o  m*/
        writer = new OutputStreamWriter(FileUtils.openOutputStream(new File(collection1Dir, "core.properties")),
                "UTF-8");
        props.store(writer, null);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (Exception ignore) {
            }
        }
    }
    createJetty(tempSolrHome.getAbsolutePath());
}

From source file:org.apache.solr.schema.SpatialRPTFieldTypeTest.java

@Before
private void initManagedSchemaCore() throws Exception {
    tmpSolrHome = createTempDir().toFile();
    tmpConfDir = new File(tmpSolrHome, confDir);
    File testHomeConfDir = new File(TEST_HOME(), confDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-managed-schema.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-basic.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"),
            tmpConfDir);//from   w  ww  .  j  a  v  a 2  s .  c  o  m
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-one-field-no-dynamic-field.xml"),
            tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-one-field-no-dynamic-field-unique-key.xml"),
            tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-minimal.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema_codec.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-bm25.xml"), tmpConfDir);

    // initCore will trigger an upgrade to managed schema, since the solrconfig has
    // <schemaFactory class="ManagedIndexSchemaFactory" ... />
    System.setProperty("managed.schema.mutable", "false");
    System.setProperty("enable.update.log", "false");
    initCore("solrconfig-managed-schema.xml", "schema-minimal.xml", tmpSolrHome.getPath());
}

From source file:org.apache.solr.schema.TestManagedSchema.java

@Before
private void initManagedSchemaCore() throws Exception {
    tmpSolrHome = createTempDir().toFile();
    tmpConfDir = new File(tmpSolrHome, confDir);
    File testHomeConfDir = new File(TEST_HOME(), confDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-managed-schema.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-basic.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-managed-schema-test.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"),
            tmpConfDir);//from w  ww .  java  2  s  .co m
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-one-field-no-dynamic-field.xml"),
            tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-one-field-no-dynamic-field-unique-key.xml"),
            tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-minimal.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema_codec.xml"), tmpConfDir);
    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-bm25.xml"), tmpConfDir);

    // initCore will trigger an upgrade to managed schema, since the solrconfig has
    // <schemaFactory class="ManagedIndexSchemaFactory" ... />
    System.setProperty("managed.schema.mutable", "false");
    System.setProperty("enable.update.log", "false");
    initCore("solrconfig-managed-schema.xml", "schema-minimal.xml", tmpSolrHome.getPath());
}