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:massbank.svn.SVNOperation.java

public boolean addEntry(String[] srcFilePaths, String destSubDirName) {
    String destPath = workCopyPath + File.separator;
    if (!destSubDirName.equals("")) {
        destPath += destSubDirName + File.separator;
    }// w  w  w  . j av a 2 s .com
    try {
        for (String path : srcFilePaths) {
            FileUtils.copyFileToDirectory(new File(path), new File(destPath));
            String name = FilenameUtils.getName(path);
            this.svnClient.add(destPath + name);
        }
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:com.alibaba.citrus.maven.eclipse.PdeEclipsePlugin.java

@Override
protected IdeDependency[] doDependencyResolution() throws MojoExecutionException {
    IdeDependency[] deps = super.doDependencyResolution();

    if (ignoreOsgiBundle) {
        for (int i = 0; i < deps.length; i++) {
            IdeDependency dep = deps[i];

            if (dep.isOsgiBundle()) {
                deps[i] = new IdeDependency(dep.getGroupId(), dep.getArtifactId(), dep.getVersion(),
                        dep.getClassifier(), dep.isReferencedProject(), dep.isTestDependency(),
                        dep.isSystemScoped(), dep.isProvided(), dep.isAddedToClasspath(), dep.getFile(),
                        dep.getType(), false, // force to be false
                        null, -1, dep.getEclipseProjectName());
            }/*from   ww  w. j  a va2s . c o  m*/
        }
    }

    if (isPdeProject() && libdir != null) {
        for (int j = 0; j < deps.length; j++) {
            IdeDependency dep = deps[j];

            if (!dep.isProvided() && !dep.isReferencedProject() && !dep.isTestDependency()
                    && !dep.isOsgiBundle() && dep.getFile() != null) {
                File lib = new File(getProject().getBasedir(), libdir);
                File srcfile = dep.getFile();

                getLog().info("Copying " + srcfile.getName() + " to " + lib.getAbsolutePath());

                try {
                    FileUtils.copyFileToDirectory(srcfile, lib);
                } catch (IOException e) {
                    getLog().error("Failed to copy " + srcfile.getName() + " to " + lib.getAbsolutePath(), e);
                }
            }
        }
    }

    return deps;
}

From source file:com.universal.storage.UniversalFileStorage.java

/**
 * This method stores a file within the storage provider according to the current settings.
 * The method will replace the file if already exists within the root.
 * //  w w  w  . j ava 2  s .  c o m
 * For exemple:
 * 
 * path == null
 * File = /var/wwww/html/index.html
 * Root = /storage/
 * Copied File = /storage/index.html
 * 
 * path == "myfolder"
 * File = /var/wwww/html/index.html
 * Root = /storage/
 * Copied File = /storage/myfolder/index.html
 * 
 * If this file is a folder, a error will be thrown informing that should call the createFolder method.
 * 
 * Validations:
 * Validates if root is a folder.
 * 
 * @param file to be stored within the storage.
 * @param path is the path for this new file within the root.
 * @throws UniversalIOException when a specific IO error occurs.
 */
void storeFile(File file, String path) throws UniversalIOException {
    validateRoot(this.settings);

    if (file.isDirectory()) {
        UniversalIOException error = new UniversalIOException(
                file.getName() + " is a folder.  You should call the createFolder method.");
        this.triggerOnErrorListeners(error);
        throw error;
    }

    try {
        this.triggerOnStoreFileListeners();
        File newFile = new File(this.settings.getRoot() + (path == null ? "" : path));
        FileUtils.copyFileToDirectory(file, newFile);
        this.triggerOnFileStoredListeners(new UniversalStorageData(newFile.getName(),
                FILE_URI + newFile.getAbsolutePath(), newFile.getName(), newFile.getAbsolutePath()));
    } catch (Exception e) {
        UniversalIOException error = new UniversalIOException(e.getMessage());
        this.triggerOnErrorListeners(error);
        throw error;
    }
}

From source file:com.orange.ocara.model.export.docx.AuditDocxExporter.java

private void copyAuditObjectComment(AuditObject auditObject, Comment comment, File commentDir)
        throws IOException, Ole10NativeException {
    switch (comment.getType()) {
    case PHOTO://from  www.  j av a  2  s.c  o  m
        FileUtils.copyFileToDirectory(FileUtils.toFile(new URL(comment.getAttachment())), commentDir);
        break;

    case AUDIO: {

        String baseName = FilenameUtils.getBaseName(comment.getAttachment());

        File from = FileUtils.toFile(new URL(comment.getAttachment()));
        File to = new File(commentDir, String.format("%s.bin", baseName));

        createOleObject(from, to);
        break;
    }

    default:
        break;
    }
}

From source file:com.googlecode.t7mp.steps.ResolveConfigurationArtifactStep.java

private void copyToTomcatConfDirectory(File unpackDirectory) throws IOException {
    this.logger.debug("copy conf-files ...");
    File confDirectory = new File(this.baseConfiguration.getCatalinaBase(), "conf");
    this.logger.debug("targetConfDirectory is " + confDirectory.getAbsolutePath());
    Set<File> files = FileUtil.getAllFiles(unpackDirectory, FileFilters.forAll(), false);
    for (File file : files) {
        this.logger.debug(
                "copy file " + file.getName() + ", path " + file.getAbsolutePath() + " to targetDirectory");
        FileUtils.copyFileToDirectory(file, confDirectory);
    }/*from   w  w  w  .j  ava2  s . co  m*/
}

From source file:ch.unibas.fittingwizard.application.workflows.ExportFitWorkflow.java

private void copyToDestinationIfNecessary(List<File> exportedFiles, File destination) {
    destination.mkdir();//from w  ww  .  j a v a 2 s  .  c  o m
    logger.info("copyToDestinationIfNecessary");
    for (File exported : exportedFiles) {
        boolean alreadyInDestination = FilenameUtils
                .equalsNormalized(exported.getParentFile().getAbsolutePath(), destination.getAbsolutePath());
        if (!alreadyInDestination) {
            try {
                FileUtils.copyFileToDirectory(exported, destination);
            } catch (IOException e) {
                throw new RuntimeException(
                        "Could not copy file to destination " + destination.getAbsolutePath(), e);
            }
            if (!exported.delete()) {
                logger.error("Exported file was not deleted.");
            }
        } else {
            logger.info("Skipping copying to destination, since export file is already in destination.");
        }
    }
}

From source file:io.snappydata.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  ww w.  ja  va 2 s .c o m*/

    String[] cmd = buildJavaCommand(vmNum, namingPort);
    System.out.println("Executing " + Arrays.asList(cmd));
    File workingDir = getVMDir(vmNum, true);
    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, workingDir.getAbsoluteFile());
    processes.put(vmNum, holder);
    linkStreams(vmNum, holder, process.getErrorStream(), System.err);
    linkStreams(vmNum, holder, process.getInputStream(), System.out);
}

From source file:com.microsoftopentechnologies.windowsazurestorage.helper.CredentialMigrationTest.java

/**
 * Test of upgradeStorageConfig method, of class CredentialMigration.
 *//*from w w w  .  j a v  a 2  s.co  m*/
@Test
public void testUpgradeStorageConfig() throws Exception {
    System.out.println("upgradeStorageConfig");

    String storageAccount = "abcdef";
    String storageAccountKey = "12345";
    String storageBlobURL = "http://test1/";
    File configFile = testFolder.newFile(Constants.LEGACY_STORAGE_CONFIG_FILE);
    FileUtils.writeStringToFile(configFile, correctConfigContent);
    FileUtils.copyFileToDirectory(configFile, jenkinsInstance.root);

    CredentialMigration.upgradeStorageConfig();

    CredentialsStore s = CredentialsProvider.lookupStores(jenkinsInstance).iterator().next();

    assertEquals(2, s.getCredentials(Domain.global()).size());

    AzureCredentials.StorageAccountCredential u = new AzureCredentials.StorageAccountCredential(storageAccount,
            storageAccountKey, storageBlobURL);
    AzureCredentials storageCred = CredentialsMatchers.firstOrNull(
            CredentialsProvider.lookupCredentials(AzureCredentials.class, jenkinsInstance, ACL.SYSTEM,
                    Collections.<DomainRequirement>emptyList()),
            CredentialsMatchers.withId(u.getId()));

    assertEquals(u.getStorageAccountName(), storageCred.getStorageAccountName());
    assertEquals(u.getEndpointURL(), storageCred.getBlobEndpointURL());
    assertEquals(u.getSecureKey().getEncryptedValue(), storageCred.getStorageKey());

}

From source file:co.runrightfast.vertx.orientdb.plugins.OrientDBHazelcastPluginTest.java

@BeforeClass
public static void setUpClass() throws Exception {
    System.setProperty("config.resource", String.format("%s.conf", CLASS_NAME));
    ConfigFactory.invalidateCaches();//from ww w .  j av  a  2 s .  c  om
    final Config typesafeConfig = ConfigFactory.load();
    hazelcast = Hazelcast.newHazelcastInstance(HazelcastConfigFactory.hazelcastConfigFactory("OrientDB")
            .apply(typesafeConfig.getConfig("hazelcast")));
    OrientDBPluginWithProvidedHazelcastInstance.HAZELCAST_INSTANCE = () -> hazelcast;

    orientdbHome.mkdirs();
    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);

    final ApplicationId appId = ApplicationId.builder().group("co.runrightfast")
            .name("runrightfast-vertx-orientdb").version("1.0.0").build();
    final AppEventLogger appEventLogger = new AppEventJDKLogger(appId);

    final EmbeddedOrientDBServiceConfig config = EmbeddedOrientDBServiceConfig.builder()
            .orientDBRootDir(orientdbHome.toPath()).handler(OrientDBHazelcastPluginTest::oGraphServerHandler)
            .handler(OrientDBHazelcastPluginTest::oHazelcastPlugin)
            .handler(OrientDBHazelcastPluginTest::oServerSideScriptInterpreter)
            .networkConfig(oServerNetworkConfiguration())
            .user(new OServerUserConfiguration(ROOT_USER, "root", "*"))
            .property(OGlobalConfiguration.DB_POOL_MIN, "1").property(OGlobalConfiguration.DB_POOL_MAX, "50")
            .databasePoolConfig(
                    new OrientDBPoolConfig(CLASS_NAME, String.format("remote:localhost/%s", CLASS_NAME),
                            "admin", "admin", 10, ImmutableSet.of(() -> new SetCreatedOnAndUpdatedOn())))
            .lifecycleListener(() -> new RunRightFastOrientDBLifeCycleListener(appEventLogger)).build();

    service = new EmbeddedOrientDBService(config);
    ServiceUtils.start(service);
    initDatabase();
}

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

private void specialRetrieval(Path tempFolder) throws IOException {

    for (Package p : packagesToRetrieve()) {

        for (DAFile f : p.getFiles()) {

            File destDir = Path.makeFile(tempFolder, WorkArea.DATA, f.getRep_name(),
                    FilenameUtils.getPath(f.getRelative_path()));
            destDir.mkdirs();//from ww w  .  j av a  2s  . com
            FileUtils.copyFileToDirectory(wa.toFile(f), destDir);
        }
    }
}