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:io.wcm.devops.conga.generator.plugins.fileheader.JsonFileHeaderTest.java

@Test
public void testApply() throws Exception {
    File file = new File("target/generation-test/fileHeader.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 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();//from w w w .  j  a v a  2s .c  om
}

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

@BeforeClass
public void init() throws IOException {
    FileUtils.forceMkdir(new File(TEST_DIR_PATH));
    FileUtils.copyFile(new File(getClass().getResource("/js-tests/multilevel/main2.test.js").getFile()),
            new File(TEST_DIR_PATH + File.separator + "main2.test.js"));
    FileUtils.copyFile(new File(getClass().getResource("/js-tests/multilevel/included.js").getFile()),
            new File(TEST_DIR_PATH + File.separator + "included.js"));
}

From source file:com.thoughtworks.go.server.web.WebappSessionConfigIntegrationTest.java

@Before
public void setup() throws IOException {
    webapp = temporaryFolder.newFolder();
    File webInf = new File(webapp, "WEB-INF");
    webInf.mkdirs();//from   ww  w.  j  a v a2s  .co  m
    File webXmlForTest = new File(webInf, "web.xml");
    File srcWebXMlFile = new File(
            WebappSessionConfigIntegrationTest.class.getResource("/WEB-INF/web.xml").getFile());
    FileUtils.copyFile(srcWebXMlFile, webXmlForTest);
}

From source file:com.datatorrent.demos.dimensions.generic.EnrichmentOperatorTest.java

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

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

    EnrichmentOperator oper = new EnrichmentOperator();
    oper.setFilePath(fileUrl.toString());
    oper.setLookupKey("productId");
    oper.setScanInterval(10);/*from  w ww.  j  a v a  2s  . 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.outputPort.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.inputPort.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", 6, emitted.get("productCategory"));

    /* Check if modified file is reloaded in beginWindow */
    FileUtils.write(new File(fileUrl.getPath()), "{ \"productId\": 10, \"productCategory\": 5 }");
    Thread.sleep(100);
    oper.beginWindow(2);
    oper.endWindow();
    Assert.assertEquals("Number of mappings ", 1, oper.cache.size());
}

From source file:de.uzk.hki.da.metadata.RdfToJsonLdConverterTest.java

@Before
public void setUp() throws Exception {
    FileUtils.copyFile(new File("src/main/resources/frame.jsonld"), new File("conf/frame.jsonld"));
}

From source file:io.wcm.devops.conga.plugins.sling.fileheader.ProvisioningFileHeaderTest.java

@Test
public void testApply() throws Exception {
    File file = new File("target/generation-test/fileHeader.txt");
    FileUtils.copyFile(new File(getClass().getResource("/validProvisioning.txt").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, StandardCharsets.UTF_8),
            "# Der Jodelkaiser\n# aus dem Oetztal\n# ist wieder daheim.\n"));

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

    file.delete();/*w w w .  j a  va  2 s .co  m*/
}

From source file:com.thoughtworks.go.helpers.LocalhostWithLargeDataSets.java

private static void prepareSampleDataFromZipFile() throws IOException {
    File dbDir = new File("db/hsqldb");
    File unzipped = unzipDatabaseFile(dbDir);
    FileUtils.copyFile(unzipped, new File(dbDir, "cruise.script"));
}

From source file:com.aboutdata.web.controller.AvatarsController.java

/**
 * Get download from file-system//from   ww  w .java2s .co m
 *
 * @param avatar
 * @param t type png jpg
 * @param v ? v=1
 * @param s
 * @param response {@link HttpServletResponse}
 */
@RequestMapping(value = "/{avatar}", method = RequestMethod.GET)
public void download(@PathVariable("avatar") String avatar, String t, String v, String s,
        HttpServletResponse response) {
    if (StringUtils.isEmpty(s)) {
        File file = new File("/var/avatars/" + avatar + "." + t);
        try {
            FileUtils.copyFile(file, response.getOutputStream());
        } catch (IOException ex) {
            logger.error("error {}", ex);
            response.setHeader("message", "?");
            response.setStatus(404);
        }
    } else {
        File file = new File("/var/avatars/" + avatar + "-" + s + "." + t);
        try {
            FileUtils.copyFile(file, response.getOutputStream());
        } catch (IOException ex) {
            logger.error("error {}", ex);
            response.setHeader("message", "?");
            response.setStatus(404);
        }
    }

}

From source file:com.dragovorn.dragonbot.api.bot.file.FileManager.java

public static void reloadFiles() {
    FileManager.config = new File(directory, "config.yml");
    FileManager.logs = new File(directory, "logs");
    FileManager.plugins = new File(directory, "plugins");
    FileManager.updater = new File(directory, "updater.jar");

    List<File> toCopy = new ArrayList<>();

    toCopy.addAll(pluginAddedFiles);/*w  w w.  j ava 2  s  .c o m*/

    pluginAddedFiles.clear();

    toCopy.forEach(file -> {
        try {
            if (file.isDirectory()) {
                FileUtils.copyDirectory(file, new File(directory, file.getName()));
            } else {
                FileUtils.copyFile(file, new File(directory, file.getName()));
            }

            file.delete();

            pluginAddedFiles.add(new File(directory, file.getName()));
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    });
}

From source file:git.egatuts.android.FileUtils.EgaFileSystem.java

/**
 * (non-Javadoc)//from  w ww  .  ja  va  2 s.c  om
 * @see git.egatuts.android.FileUtils.EgaFileSystemBase#copyFile(java.io.File, java.io.File)
 */
@Override
public void copyFile(File from, File to) throws IOException {
    FileUtils.copyFile(from, to);
}