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:net.orpiske.sdm.lib.io.support.ShieldAwareCopier.java

@Override
protected void handleFile(File file, int depth, Collection results) throws IOException {
    File destinationFile = new File(destination, file.getName());

    if (!ShieldUtils.isShielded(destinationFile)) {
        FileUtils.copyFile(file, destinationFile);

        destinationFile.setExecutable(file.canExecute());
        destinationFile.setReadable(file.canRead());
        destinationFile.setWritable(file.canWrite());
    } else {//from  w w w. j a  v  a2 s.  c o m
        System.out.println("Ignoring shielded file " + file.getPath());
    }
}

From source file:com.redhat.rcm.version.util.PomUtilsTest.java

@Test
public void pomRewritePreservesXMLAttributesInPluginConfiguration() throws Exception {
    final File srcPom = getResourceFile(BASE + "plugin-config-attributes.pom");

    final File pom = new File(repo, srcPom.getName());
    FileUtils.copyFile(srcPom, pom);

    final Model model = loadModel(pom);

    assertThat(model.getBuild(), notNullValue());

    List<Plugin> plugins = model.getBuild().getPlugins();
    assertThat(plugins, notNullValue());
    assertThat(plugins.size(), equalTo(1));

    Plugin plugin = plugins.get(0);/* w  w w.  j  a  v a  2  s . co  m*/
    Object config = plugin.getConfiguration();
    assertThat(config, notNullValue());

    assertThat(config.toString().contains("<delete dir=\"foobar\""), equalTo(true));

    final VersionManagerSession session = newVersionManagerSession(workspace, reports, null);
    final File out = PomUtils.writeModifiedPom(model, pom, new FullProjectKey(model), model.getVersion(),
            pom.getParentFile(), session, false);

    assertNoErrors(session);
    final String pomStr = readFileToString(out);
    System.out.println("Modified POM for " + name.getMethodName() + ":\n\n" + pomStr + "\n\n");

    final Model changed = loadModel(out);

    assertThat(changed.getBuild(), notNullValue());

    plugins = changed.getBuild().getPlugins();
    assertThat(plugins, notNullValue());
    assertThat(plugins.size(), equalTo(1));

    plugin = plugins.get(0);
    config = plugin.getConfiguration();
    assertThat(config, notNullValue());
    assertThat(config.toString().contains("<delete dir=\"foobar\""), equalTo(true));
}

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

@Test
public void identifierFromPREMIS() throws IOException, JDOMException {
    FileUtils.copyFile(Path.makeFile(WORK_AREA_ROOT_PATH, "premis.xml.urn"), wa.toFile(premis));

    action.implementation();//www.j a  v a 2  s .  c o  m
    assertEquals("urn:nbn:de:xyz-1-20131008367735", o.getUrn());
}

From source file:io.jawg.osmcontributor.utils.core.database.DatabaseUpgradeTest.java

@Before
public void setup() throws IOException {
    File baseDir = new File("build/tmp/sqlupdate");
    baseDir.mkdirs();/*w  ww  .  java 2  s. c om*/
    FileUtils.cleanDirectory(baseDir);

    File baseOldBd = new File("src/test/resources/db-v1.sqlite");
    newDbFile = new File(baseDir, "new.sqlite");
    updatedDbFile = new File(baseDir, "updated.sqlite");
    FileUtils.copyFile(baseOldBd, updatedDbFile);
    Timber.plant(new SysoTree());

}

From source file:com.izforge.izpack.util.IoHelper.java

/**
 * Creates a temp file with delete on exit rule. The extension is extracted from the template if
 * possible, else the default extension is used. The contents of template will be copied into
 * the temporary file./*from  w  ww  .  j a va 2  s. c  o m*/
 *
 * @param templateFile         file to copy from and define file extension
 * @param defaultExtension file extension if no is contained in template
 * @return newly created and filled temporary file
 * @throws IOException if an I/O error occurred
 */
public static File copyToTempFile(File templateFile, String defaultExtension) throws IOException {
    String path = templateFile.getCanonicalPath();
    int pos = path.lastIndexOf('.');
    String ext = path.substring(pos);
    if (ext.isEmpty()) {
        ext = defaultExtension;
    }
    File tmpFile = File.createTempFile("izpack_io", ext);
    tmpFile.deleteOnExit();
    FileUtils.copyFile(templateFile, tmpFile);
    return tmpFile;
}

From source file:edu.synth.SynthHelper.java

public SynthHelper() {
    try {/*from   w ww.  j  a v a  2  s  . com*/
        FileUtils.copyFile(new File(Constants.DEF_SOLAR_ABN), new File(Constants.ABN_PATH));
        FileUtils.copyFile(new File(Constants.DEF_CONV_CONF), new File(Constants.CONV_PATH));
        FileUtils.copyFile(new File(Constants.DEF_SYNTH_INP), new File(Constants.SYNTH_PATH));
    } catch (IOException e) {
        e.printStackTrace();
        ;
    }
    clear();
    initSettings();
    menu();
    controls();
    Messager.publish("Welcome to  SYNTHelper! Logging started...");
    instance = this;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SelectGeneRawFileListener.java

@Override
public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    String path = this.selectRawFileUI.getPath();
    if (path == null)
        return;/*from  w w  w.  j a v a2  s .c o  m*/
    if (path.contains("%")) {
        this.selectRawFileUI.displayMessage("File name can not contain percent ('%') symbol.");
        return;
    }
    File rawFile = new File(path);
    if (rawFile.exists()) {
        if (rawFile.isFile()) {
            if (!this.checkFormat(rawFile))
                return;

            String newPath = this.dataType.getPath().getAbsolutePath() + File.separator + rawFile.getName();

            File copiedRawFile = new File(newPath);
            if (!copiedRawFile.exists()) {
                try {
                    FileUtils.copyFile(rawFile, copiedRawFile);
                    ((GeneExpressionData) this.dataType).setRawFile(copiedRawFile);

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

From source file:com.galenframework.tests.runner.GalenConfigTest.java

@Test
public void shouldRead_configForLocalProject_fromFile() throws IOException {
    //copying file from resources to local folder
    //so it can be picked up by

    File configFile = new File("config");
    configFile.createNewFile();/*  w  w  w.  j a  v a2s .co m*/
    FileUtils.copyFile(new File(getClass().getResource("/config1").getFile()), configFile);

    GalenConfig config = GalenConfig.getConfig();
    config.reset();

    configFile.delete();

    MatcherAssert.assertThat(config.getRangeApproximation(), is(3));
    assertThat(config.getReportingListeners(),
            Matchers.contains("net.mindengine.CustomListener", "net.mindengine.CustomListener2"));
    config.reset();
}

From source file:fm.last.moji.local.LocalFileSystemMoji.java

@Override
public void copyToMogile(File source, MojiFile destination) throws IOException {
    LocalMojiFile localDestination = (LocalMojiFile) destination;
    FileUtils.copyFile(source, localDestination.file);
}

From source file:de.uzk.hki.da.grid.FakeGridFacade.java

@Override
public boolean put(File file, String address_dest, StoragePolicy sp, String checksum) throws IOException {

    if (!address_dest.startsWith(C.FS_SEPARATOR))
        address_dest = C.FS_SEPARATOR + address_dest;

    String dest = getGridCacheAreaRootPath() + WorkArea.AIP + address_dest;
    logger.debug("Putting: " + file + " to " + dest);
    FileUtils.copyFile(file, new File(dest));
    return true;/* w ww .  ja va2 s  . co m*/

}