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:de.uzk.hki.da.cb.RegisterURNActionTest.java

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

    Package pkg = new Package();
    pkg.setDelta(2);//from w  w w  .j  a  v  a 2  s .c om
    o.getPackages().add(pkg);
    String prv_urn = "previous_urn";
    o.setUrn(prv_urn);

    action.implementation();
    assertEquals("previous_urn", o.getUrn());
}

From source file:com.linkedin.pinot.filesystem.LocalPinotFS.java

@Override
public boolean copy(URI srcUri, URI dstUri) throws IOException {
    File srcFile = new File(srcUri);
    File dstFile = new File(dstUri);
    if (dstFile.exists()) {
        FileUtils.deleteQuietly(dstFile);
    }/* w ww. j av  a2s .  c om*/
    if (srcFile.isDirectory()) {
        // Throws Exception on failure
        FileUtils.copyDirectory(srcFile, dstFile);
    } else {
        // Will create parent directories, throws Exception on failure
        FileUtils.copyFile(srcFile, dstFile);
    }
    return true;
}

From source file:com.asual.summer.bundle.BundleDescriptorMojo.java

public void execute() throws MojoExecutionException {

    try {/*from www  .  j  av  a2  s.  c  o m*/

        String webXml = "WEB-INF/web.xml";
        File warDir = new File(buildDirectory, finalName);
        File warFile = new File(buildDirectory, finalName + ".war");
        File webXmlFile = new File(warDir, webXml);
        FileUtils.copyFile(new File(basedir, "src/main/webapp/" + webXml), webXmlFile);

        Configuration[] configurations = new Configuration[] { new WebXmlConfiguration(),
                new FragmentConfiguration() };
        WebAppContext context = new WebAppContext();
        context.setDefaultsDescriptor(null);
        context.setDescriptor(webXmlFile.getAbsolutePath());
        context.setConfigurations(configurations);

        for (Artifact artifact : artifacts) {
            JarInputStream in = new JarInputStream(new FileInputStream(artifact.getFile()));
            while (true) {
                ZipEntry entry = in.getNextEntry();
                if (entry != null) {
                    if ("META-INF/web-fragment.xml".equals(entry.getName())) {
                        Resource fragment = Resource
                                .newResource("file:" + artifact.getFile().getAbsolutePath());
                        context.getMetaData().addFragment(fragment, Resource
                                .newResource("jar:" + fragment.getURL() + "!/META-INF/web-fragment.xml"));
                        context.getMetaData().addWebInfJar(fragment);
                    }
                } else {
                    break;
                }
            }
            in.close();
        }

        for (int i = 0; i < configurations.length; i++) {
            configurations[i].preConfigure(context);
        }

        for (int i = 0; i < configurations.length; i++) {
            configurations[i].configure(context);
        }

        for (int i = 0; i < configurations.length; i++) {
            configurations[i].postConfigure(context);
        }

        Descriptor descriptor = context.getMetaData().getWebXml();
        Node root = descriptor.getRoot();

        List<Object> nodes = new ArrayList<Object>();
        List<FragmentDescriptor> fragmentDescriptors = context.getMetaData().getOrderedFragments();
        for (FragmentDescriptor fd : fragmentDescriptors) {
            for (int i = 0; i < fd.getRoot().size(); i++) {
                Object el = fd.getRoot().get(i);
                if (el instanceof Node && ((Node) el).getTag().matches("^name|ordering$")) {
                    continue;
                }
                nodes.add(el);
            }
        }
        root.addAll(nodes);

        BufferedWriter writer = new BufferedWriter(new FileWriter(new File(warDir, webXml)));
        writer.write(root.toString());
        writer.close();

        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(warFile));
        zip(warDir, warDir, zos);
        zos.close();

    } catch (Exception e) {
        getLog().error(e.getMessage(), e);
        throw new MojoExecutionException(e.getMessage(), e);
    }
}

From source file:com.googlecode.t7mp.scanner.ModifiedFileTimerTask.java

@Override
public void run() {
    long timeStamp = lastrun;
    lastrun = System.currentTimeMillis();
    Set<File> fileSet = FileUtil.getAllFiles(rootDirectory);
    Collection<File> changedFiles = Collections2.filter(fileSet,
            Predicates.and(new ModifiedFilePredicate(timeStamp), new FileSuffixPredicate(suffixe)));
    for (File file : changedFiles) {
        String absolutePath = file.getAbsolutePath();
        String def = getResourceDef(absolutePath);

        int endIndex = absolutePath.lastIndexOf(def);
        String copyFragment = absolutePath.substring(endIndex + def.length());
        File copyToFile = new File(webappDirectory, copyFragment);
        log.debug("CHANGED: " + absolutePath);
        log.debug("COPY TO : " + copyToFile.getAbsolutePath());
        try {/* w w  w . ja  v  a 2 s.com*/
            FileUtils.copyFile(file, copyToFile);
            FileUtils.touch(copyToFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    log.debug("-----------END SCAN-------------");
}

From source file:com.legstar.cob2xsd.Cob2XsdIOTest.java

/**
 * Go through all the samples and check with backward compatibility.
 * /*from www .jav a 2s. c  o m*/
 * @throws Exception if test fails
 */
@Test
public void testAllSamples() throws Exception {
    File cobolDir = new File(COBOL_SAMPLES_DIR);
    for (File cobolFile : cobolDir.listFiles()) {
        if (cobolFile.isFile()) {
            _log.debug("Translating " + cobolFile);
            String name = cobolFile.getName().toLowerCase();
            configProps.put(Cob2XsdConfig.ADD_LEGSTAR_ANNOTATIONS, Boolean.toString(true));

            /* Backward compatibility */
            configProps.put(Cob2XsdConfig.ELEMENT_NAMES_START_WITH_UPPERCASE, Boolean.toString(true));
            configProps.put(Cob2XsdConfig.QUOTE_IS_QUOTE, Boolean.toString(false));

            Cob2XsdIO translator = new Cob2XsdIO(new Cob2XsdConfig(configProps));
            File custmXslt = new File(XSLT_SAMPLES_DIR, name + ".xsl");
            File xsdFile = translator.translate(cobolFile, "ISO-8859-1", tempDir,
                    "http://legstar.com/test/coxb", custmXslt.exists() ? custmXslt.getPath() : null);
            if (_log.isDebugEnabled()) {
                _log.debug("Result:\n" + FileUtils.readFileToString(xsdFile));
            }
            File xsdRefFile = new File(XSD_REFERENCES_DIR, name.toLowerCase() + ".xsd");

            if (CREATE_REFERENCES) {
                FileUtils.copyFile(xsdFile, xsdRefFile);
            } else {
                Document result = getXMLSchemaAsDoc(xsdFile);
                Document expected = getXMLSchemaAsDoc(xsdRefFile);
                compare(xsdFile.getName(), expected, result);
            }
            xsdFile.deleteOnExit();
        }
    }
}

From source file:com.liferay.maven.arquillian.importer.LiferayPluginTestCase.java

protected static void setupPortalMinimal() {

    System.setProperty("liferay.version", LIFERAY_VERSION);

    System.setProperty("liferay.auto.deploy.dir", PORTAL_AUTO_DEPLOY_DIR);

    System.setProperty("liferay.app.server.deploy.dir", PORTAL_SERVER_DEPLOY_DIR);

    System.setProperty("liferay.app.server.lib.global.dir", PORTAL_SERVER_LIB_GLOBAL_DIR);

    System.setProperty("liferay.app.server.portal.dir", SERVER_PORTAL_DIR);

    try {//w ww.  j a  v  a  2 s .c o m

        ArchiverManager archiverManager = plexusContainer.lookup(ArchiverManager.class);

        assertNotNull(archiverManager);

        FileUtils.forceMkdir(new File(PORTAL_AUTO_DEPLOY_DIR));
        FileUtils.forceMkdir(new File(PORTAL_SERVER_DEPLOY_DIR));
        FileUtils.forceMkdir(new File(PORTAL_SERVER_LIB_GLOBAL_DIR));
        FileUtils.forceMkdir(new File(SERVER_PORTAL_DIR));

        final MavenResolverSystem mavenResolverSystem = Maven.configureResolver()
                .fromClassloaderResource("settings.xml");

        File[] dependencies = mavenResolverSystem.loadPomFromClassLoaderResource("liferay-setup.xml")
                .importRuntimeAndTestDependencies().resolve().withoutTransitivity().asFile();

        File warFile = null;

        for (File file : dependencies) {

            String fileName = file.getName();
            String fileExtension = FilenameUtils.getExtension(fileName);

            if ("jar".equalsIgnoreCase(fileExtension)) {
                FileUtils.copyFile(file, new File(PORTAL_SERVER_LIB_GLOBAL_DIR, file.getName()));
            } else if ("war".equalsIgnoreCase(fileExtension) && fileName.contains("portal-web")) {
                warFile = file;
            }

        }

        assertNotNull(warFile);

        // extract portal war
        UnArchiver unArchiver = archiverManager.getUnArchiver(warFile);
        unArchiver.setDestDirectory(new File(SERVER_PORTAL_DIR));
        unArchiver.setSourceFile(warFile);
        unArchiver.setOverwrite(false);
        unArchiver.extract();
        setup = true;

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.google.api.ads.adwords.awreporting.processors.onfile.RunnableProcessorOnFileTest.java

@Before
public void setUp() throws IOException {

    ModifiedCsvToBean<ReportAccount> csvToBean = new ModifiedCsvToBean<ReportAccount>();
    MappingStrategy<ReportAccount> mappingStrategy = new AnnotationBasedMappingStrategy<ReportAccount>(
            ReportAccount.class);

    FileUtils.copyFile(file, newFile);

    runnableProcessorOnFile = new RunnableProcessorOnFile<ReportAccount>(file, true, csvToBean, mappingStrategy,
            ReportDefinitionDateRangeType.CUSTOM_DATE, "20140101", "20140131", "123", mockedEntitiesPersister,
            5);//from w w w.  j av a 2s. co  m

    MockitoAnnotations.initMocks(this);

    runnableProcessorOnFile.setPersister(mockedEntitiesPersister);
}

From source file:javafxqrgenerator.model.GeneratorModel.java

public void exportQRImage(String destPath) {
    File dest = new File(destPath);
    try {/*  www .  j a  va2  s .  c o m*/
        if (!destPath.endsWith(".jpg")) {
            dest = new File(destPath + ".jpg");
        }
        FileUtils.copyFile(new File(QRImage), dest);
        QRImage = dest.getAbsolutePath();
    } catch (IOException iOException) {
        System.out.println(iOException);
    }
}

From source file:gov.va.vinci.leo.tools.GenerateDescriptors.java

/**
 * A utility for generating Descriptors and Type Descriptors for an annotator.
 *
 * @param annotatorClassName The annotator class name. The annotator class must extend LeoBaseAnnotator and
 *                           be in the classpath.
 * @param outputRootPath     The root directory to output the descriptors to. Descriptors are written to outputRootPath/annotator package/Annotator(Descriptor/Type).xml
 * @throws Exception if any exception occurs during generation.
 *//*www  . j a  va 2  s.c om*/
public static void generate(String annotatorClassName, String outputRootPath) throws Exception {
    LeoBaseAnnotator annotator = (LeoBaseAnnotator) Class.forName(annotatorClassName).newInstance();
    String shortName = annotatorClassName;
    if (annotatorClassName.contains(".")) {
        shortName = annotatorClassName.substring(annotatorClassName.lastIndexOf(".") + 1);
    }

    String newOutputPath = outputRootPath;
    if (!outputRootPath.endsWith(File.separator)) {
        newOutputPath += File.separator;
    }

    if (annotatorClassName.contains(".")) {
        newOutputPath += annotatorClassName.substring(0, annotatorClassName.lastIndexOf(".")).replaceAll("\\.",
                File.separator) + File.separator;
    }

    FileUtils.forceMkdir(new File(newOutputPath));
    annotator.getLeoTypeSystemDescription().toXML(newOutputPath + shortName + "Type.xml");

    LeoAEDescriptor desc = (LeoAEDescriptor) annotator.getDescriptor();
    desc.toXML(shortName);
    String descriptorPath = desc.getDescriptorLocator();
    if (descriptorPath.startsWith("file:")) {
        descriptorPath = descriptorPath.substring(5);
    }

    FileUtils.copyFile(new File(descriptorPath), new File(newOutputPath + shortName + "Descriptor.xml"));
}

From source file:com.sonatype.security.ldap.persist.upgrade.UpgradeTest.java

private void runUpgradeTest(String testKey, File ldapXml, File ldapResultXml) throws Exception {
    //copy ldap.xml to conf dir
    File inplaceLdapXml = new File(getConfHomeDir(), "ldap.xml");
    FileUtils.copyFile(ldapXml, inplaceLdapXml);

    File testSecConfigFile = new File(ldapXml.getParentFile(), "security-configuration.xml");
    File inplaceSecConfigFile = new File(getSecurityConfiguration());
    FileUtils.copyFile(testSecConfigFile, inplaceSecConfigFile);

    LdapConfigurationSource source = this.lookup(LdapConfigurationSource.class);
    final CLdapConfiguration configuration = source.load();
    Assert.assertEquals("secret", configuration.getServers().get(0).getConnectionInfo().getSystemPassword());

    // get upgraded file as String
    String upgradeResult = FileUtils.readFileToString(inplaceLdapXml);
    String expected = FileUtils.readFileToString(ldapResultXml);
    compareConfigurations(expected, upgradeResult);
}