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:com.mscorp.automation.seleniumCoreUtils.TakeScreenshot.java

public void takeScreenShotForCucumber(String screenshotFileName) {

    File file = new File(System.getProperty("user.dir") + File.separator + screenshotPath);
    if (!file.isDirectory())
        file.mkdir();// www  . jav a 2 s  .c om
    File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    String saveImgFile = System.getProperty("user.dir") + File.separator + screenshotPath + File.separator
            + "Failure_Screenshot_" + screenshotFileName + ".jpg";
    System.out.println("Save Image File Path : " + saveImgFile);
    try {
        FileUtils.copyFile(scrFile, new File(saveImgFile));
    } catch (IOException e) {
        System.out.println("Error in saving file");
        e.printStackTrace();
    }

}

From source file:com.datatorrent.stram.cli.DTCliTest.java

@BeforeClass
public static void starting() {
    try {/*from  ww w .ja  v  a  2s  . com*/
        userHome = System.getProperty("user.home");
        String newHome = System.getProperty("user.dir") + "/target";
        FileUtils.forceMkdir(new File(newHome + "/.dt"));
        FileUtils.copyFile(
                new File(System.getProperty("user.dir") + "/src/test/resources/testAppPackage/dt-site.xml"),
                new File(newHome + "/.dt/dt-site.xml"));
        env.put("HOME", newHome);
        setEnv(env);

        cli.init();
        // Set up jar file to use with constructor
        testFolder.create();
        appFile = StramTestSupport.createAppPackageFile();
        configFile = StramTestSupport.createConfigPackageFile(new File(testFolder.getRoot(), configJarPath));
        ap = new AppPackage(appFile, true);
        cp = new ConfigPackage(configFile);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:de.uzk.hki.da.action.ActionInformationTests.java

/**
 * Sets the up.//w  w w . j a  v a  2  s.c  o  m
 * @throws IOException 
 */
@Before
public void setUp() throws IOException {
    FileUtils.copyFile(new File("src/main/conf/config.properties.dev"), new File("conf/config.properties"));

    context = new FileSystemXmlApplicationContext(
            "src/test/resources/core/ActionInformationTests/action-definitions.xml");
    ;
    info = (ActionInformation) context.getBean("actionInformation");
}

From source file:io.wcm.devops.conga.generator.plugins.postprocessor.AbstractPostProcessorTest.java

@Test
public void testApply() throws Exception {
    File file = new File("target/generation-test/postProcessor.json");
    FileUtils.copyFile(new File(getClass().getResource("/validators/json/validJson.json").toURI()), file);

    List<String> lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim.");
    FileHeaderContext fileHeader = new FileHeaderContext().commentLines(lines);
    FileContext fileContext = new FileContext().file(file);
    new JsonFileHeader().apply(fileContext, fileHeader);

    PostProcessorPlugin postProcessor = new DummyPostProcessor();
    PostProcessorContext postProcessorContext = new PostProcessorContext().pluginManager(new PluginManager());

    List<FileContext> result = postProcessor.apply(fileContext, postProcessorContext);

    assertEquals(1, result.size());/* w  w w.  j a  v  a2 s.  c om*/

    FileContext newFileContext = result.get(0);
    FileHeaderContext newFileHeader = new ConfFileHeader().extract(newFileContext);

    assertEquals(fileHeader.getCommentLines(), newFileHeader.getCommentLines());

    file.delete();
    result.forEach(fc -> fc.getFile().delete());
}

From source file:net.jsign.PESignerCLITest.java

protected void setUp() throws Exception {
    cli = new PESignerCLI();

    // remove the files signed previously
    if (targetFile.exists()) {
        assertTrue("Unable to remove the previously signed file", targetFile.delete());
    }/*from  w  w  w .j  a  v  a2  s .  c  o  m*/

    FileUtils.copyFile(sourceFile, targetFile);
}

From source file:de.uzk.hki.da.at.ATUseCaseIngestDeltaValidationNotPassed.java

@Before
public void setUp() throws IOException {

    object = ath.putPackageToStorage(IDENTIFIER, ORIG_NAME, CONTAINER_NAME, null, 100);
    FileUtils.copyFile(Path.makeFile(TC.TEST_ROOT_AT, CONTAINER_NAME),
            Path.makeFile(localNode.getIngestAreaRootPath(), C.TEST_USER_SHORT_NAME, CONTAINER_NAME));
}

From source file:com.datatorrent.contrib.enrichment.FileEnrichmentTest.java

@Test
public void testEnrichmentOperator() throws IOException, InterruptedException {
    URL origUrl = this.getClass().getResource("/productmapping.txt");

    URL fileUrl = new URL(this.getClass().getResource("/").toString() + "productmapping1.txt");
    FileUtils.deleteQuietly(new File(fileUrl.getPath()));
    FileUtils.copyFile(new File(origUrl.getPath()), new File(fileUrl.getPath()));

    MapEnrichmentOperator oper = new MapEnrichmentOperator();
    FSLoader store = new FSLoader();
    store.setFileName(fileUrl.toString());
    oper.setLookupFieldsStr("productId");
    oper.setStore(store);/* w  w w  .  j a v  a2 s.c  o  m*/

    oper.setup(null);

    /* File contains 6 entries, but operator one entry is duplicate,
     * so cache should contains only 5 entries after scanning input file.
     */
    //Assert.assertEquals("Number of mappings ", 7, oper.cache.size());

    CollectorTestSink<Map<String, Object>> sink = new CollectorTestSink<Map<String, Object>>();
    @SuppressWarnings({ "unchecked", "rawtypes" })
    CollectorTestSink<Object> tmp = (CollectorTestSink) sink;
    oper.output.setSink(tmp);

    oper.beginWindow(0);
    Map<String, Object> tuple = Maps.newHashMap();
    tuple.put("productId", 3);
    tuple.put("channelId", 4);
    tuple.put("amount", 10.0);

    Kryo kryo = new Kryo();
    oper.input.process(kryo.copy(tuple));

    oper.endWindow();

    /* Number of tuple, emitted */
    Assert.assertEquals("Number of tuple emitted ", 1, sink.collectedTuples.size());
    Map<String, Object> emitted = sink.collectedTuples.iterator().next();

    /* The fields present in original event is kept as it is */
    Assert.assertEquals("Number of fields in emitted tuple", 4, emitted.size());
    Assert.assertEquals("value of productId is 3", tuple.get("productId"), emitted.get("productId"));
    Assert.assertEquals("value of channelId is 4", tuple.get("channelId"), emitted.get("channelId"));
    Assert.assertEquals("value of amount is 10.0", tuple.get("amount"), emitted.get("amount"));

    /* Check if productCategory is added to the event */
    Assert.assertEquals("productCategory is part of tuple", true, emitted.containsKey("productCategory"));
    Assert.assertEquals("value of product category is 1", 5, emitted.get("productCategory"));

}

From source file:cc.kune.selenium.SeleniumUtils.java

/**
 * Do screenshot./* w w  w  . ja va2s  .c  om*/
 * 
 * @param webdriver
 *          the webdriver
 * @param filename
 *          the filename
 */
public static void doScreenshot(final WebDriver webdriver, final String filename) {
    final File scrFile = ((TakesScreenshot) webdriver).getScreenshotAs(OutputType.FILE);
    try {
        FileUtils.copyFile(scrFile,
                new File(SeleniumConstants.SCREENSHOTS_DIR + "kune-" + filename + "-sele.png"));
    } catch (final IOException e) {
        LOG.info("Cannot take the screen shot", e);
    }
}

From source file:com.daphne.es.maintain.staticresource.web.controller.utils.YuiCompressorUtils.java

/**
 * js/css  ??.min.js/css//from  w  w  w .j  av a  2s  .c o m
 * @param fileName
 * @return ??
 */
public static String compress(final String fileName) {
    String minFileName = null;
    final String extension = FilenameUtils.getExtension(fileName);
    if ("js".equalsIgnoreCase(extension)) {
        minFileName = fileName.substring(0, fileName.length() - 3) + ".min.js";
    } else if ("css".equals(extension)) {
        minFileName = fileName.substring(0, fileName.length() - 4) + ".min.css";
    } else {
        throw new RuntimeException(
                "file type only is js/css, but was fileName:" + fileName + ", extension:" + extension);
    }
    Reader in = null;
    Writer out = null;
    try {
        in = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), Constants.ENCODING));
        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(minFileName), Constants.ENCODING));

        if ("js".equals(extension)) {

            CustomErrorReporter errorReporter = new CustomErrorReporter();

            JavaScriptCompressor compressor = new JavaScriptCompressor(in, errorReporter);
            compressor.compress(out, 10, true, false, false, false);

            if (errorReporter.hasError()) {
                throw new RuntimeException(errorReporter.getErrorMessage());
            }

        } else if ("css".equals(extension)) {

            CssCompressor compressor = new CssCompressor(in);
            compressor.compress(out, 10);
        }
    } catch (Exception e) {
        //?js/css
        try {
            FileUtils.copyFile(new File(fileName), new File(minFileName));
        } catch (IOException ioException) {
            throw new RuntimeException("compress error:" + ioException.getMessage(), ioException);
        }
        throw new RuntimeException("compress error:" + e.getMessage(), e);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
            }
        }
    }

    if (FileUtils.sizeOf(new File(minFileName)) == 0) {
        try {
            FileUtils.copyFile(new File(fileName), new File(minFileName));
        } catch (IOException ioException) {
            throw new RuntimeException("compress error:" + ioException.getMessage(), ioException);
        }
    }

    return minFileName;
}

From source file:io.wcm.devops.conga.generator.plugins.fileheader.XmlFileHeaderTest.java

@Test
public void testApply() throws Exception {
    File file = new File("target/generation-test/fileHeader.xml");
    FileUtils.copyFile(new File(getClass().getResource("/validators/xml/validXml.xml").toURI()), file);

    List<String> lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim.");
    FileHeaderContext context = new FileHeaderContext().commentLines(lines);
    FileContext fileContext = new FileContext().file(file);

    assertTrue(underTest.accepts(fileContext, context));
    underTest.apply(fileContext, context);

    assertTrue(StringUtils.contains(FileUtils.readFileToString(file),
            "Der Jodelkaiser\naus dem Oetztal\nist wieder daheim.\n"));

    FileHeaderContext extractContext = underTest.extract(fileContext);
    assertEquals(lines, extractContext.getCommentLines());

    file.delete();//ww w  . java2  s . co m
}