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.netease.dagger.LogTools.java

public static String screenShot(BrowserEmulator be) {
    String dir = "screenshot"; // TODO
    String time = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date());
    String screenShotPath = dir + File.separator + time + ".png";

    WebDriver augmentedDriver = null;/*from   ww w.  ja  va  2s  .  co m*/
    if (GlobalSettings.browserCoreType == 1 || GlobalSettings.browserCoreType == 3) {
        augmentedDriver = be.getBrowserCore();
        augmentedDriver.manage().window().setPosition(new Point(0, 0));
        augmentedDriver.manage().window().setSize(new Dimension(9999, 9999));
    } else if (GlobalSettings.browserCoreType == 2) {
        augmentedDriver = new Augmenter().augment(be.getBrowserCore());
    } else {
        return "Incorrect browser type";
    }

    try {
        File sourceFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(sourceFile, new File(screenShotPath));
    } catch (Exception e) {
        e.printStackTrace();
        return "Failed to screenshot";
    }

    return screenShotPath;
}

From source file:com.wavemaker.common.util.ClassLoaderUtilsTest.java

public void testTempClassLoader_getClass() throws Exception {

    File sourceJar = new ClassPathResource("com/wavemaker/common/foojar.jar").getFile();
    File jar = File.createTempFile("testTempClassLoader_getClass", ".jar");
    jar.deleteOnExit();//from w w  w. j av  a 2s .  c  om
    FileUtils.copyFile(sourceJar, jar);

    try {
        ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar);
        Class<?> klass = ClassLoaderUtils.loadClass("foo.bar.baz.JarType", cl);
        assertNotNull(klass);
    } finally {
        jar.delete();
    }
}

From source file:com.exalttech.trex.stateful.utilities.FileManager.java

/**
 * Copy the select file to the local directory
 *
 * @param srcFile//from  w  w w . j a va  2s  .  c  om
 * @return
 * @throws IOException
 */
public static File copyFile(File srcFile) throws IOException {
    File destFile;
    String srcFileDirectory = "";
    if (srcFile.getParentFile() != null) {
        srcFileDirectory = srcFile.getParentFile().getName();
    }
    destFile = new File(createDirectoryIfNotExists(getLocalFilePath() + srcFileDirectory) + File.separator
            + srcFile.getName());
    FileUtils.copyFile(srcFile, destFile);
    return destFile;
}

From source file:com.wavemaker.commons.util.utils.ClassLoaderUtilsTest.java

@Test
public void tempClassLoader_getClassTest() throws Exception {

    File sourceJar = new ClassPathResource("com/wavemaker/commons/foojar.jar").getFile();
    File jar = File.createTempFile("tempClassLoader_getClassTest", ".jar");
    jar.deleteOnExit();/*from www .  ja va 2 s  .  c  o  m*/
    FileUtils.copyFile(sourceJar, jar);

    try {
        ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar);
        Class<?> klass = ClassLoaderUtils.loadClass("foo.bar.baz.JarType", cl);
        assertNotNull(klass);
    } finally {
        jar.delete();
    }
}

From source file:app.worker.DoUploadImgActionSupport.java

public String execute() throws Exception {
    String destPath = "D:/hoctap/SEM4/ProjectSem4Strut2/web/images/avatars";
    DataProcess dataProcess = new DataProcess();
    String url = "";
    try {//w  w  w . j a v  a 2  s. c  o m
        Random rand = new Random();
        int ran = rand.nextInt();
        url = Integer.toString(ran) + ".jpg";
        File destFile = new File(destPath, url);
        FileUtils.copyFile(file, destFile);

    } catch (IOException e) {
        return "error";
    }
    url = "images/avatars/" + url;
    if (dataProcess.setAvata(codeWorker, url))
        return "index";
    return "error";
}

From source file:it.geosolutions.jaiext.JAIEXTTest.java

@BeforeClass
public static void setup() throws FileNotFoundException, IOException {
    final File inputJAIFile = TestData.file(JAIEXTTest.class,
            "META-INF" + File.separator + "registryFile2.jaiext");
    newJAIFile = new File(inputJAIFile.getParentFile().getParentFile().getParentFile().getParentFile()
            .getParentFile().getParentFile(), "META-INF" + File.separator + "registryFile.jaiext");
    FileUtils.copyFile(inputJAIFile, newJAIFile);

    // Setting of the operation registry
    JAIExt.initJAIEXT();/* w w  w . java  2 s  . co m*/
}

From source file:com.googlecode.t7mp.CommonsSetupUtil.java

@Override
public void copyFile(File source, File target) throws IOException {
    FileUtils.copyFile(source, target);
}

From source file:com.liferay.maven.plugins.PluginDeployerMojo.java

protected void doExecute() throws Exception {
    if (warFile.exists()) {
        getLog().info("Deploying " + warFileName + " to " + autoDeployDir.getAbsolutePath());

        FileUtils.copyFile(warFile, new File(autoDeployDir, warFileName));
    } else {/*from  w  w  w.j  a  v  a  2  s .  c o m*/
        getLog().warn(warFileName + " does not exist");
    }
}

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

@BeforeClass
public static void putPackages() throws IOException {

    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));

    ath.putPackageToIngestArea(ORIG_NAME, "tgz", ORIG_NAME);

    ath.putPackageToIngestArea(AT_ERSTE_ZEILE_TAGMANIFEST1_ZEICHENGEAENDERT, "tgz",
            AT_ERSTE_ZEILE_TAGMANIFEST1_ZEICHENGEAENDERT);
    ath.putPackageToIngestArea(AT_MANIFEST_MD5_2FILESGEAENDERT, "tgz", AT_MANIFEST_MD5_2FILESGEAENDERT);
    ath.putPackageToIngestArea(AT_EINE_DATEI_GELOESCHT, "tgz", AT_EINE_DATEI_GELOESCHT);
    ath.putPackageToIngestArea(AT_INVALID_PREMIS, "zip", AT_INVALID_PREMIS);
    ath.putPackageToIngestArea(AT_DUPLICATE_METADATA_FILES, "tgz", AT_DUPLICATE_METADATA_FILES);
    ath.putPackageToIngestArea(AT_DUPLICATE_DOCUMENT_NAME, "tgz", AT_DUPLICATE_DOCUMENT_NAME);
}

From source file:gov.nih.nci.caintegrator.web.action.query.NCIADicomFileResultTest.java

@Test
public void testExecute() throws IOException {
    MockHttpServletResponse response = new MockHttpServletResponse();
    ServletActionContext.setResponse(response);
    NCIADicomJob dicomJob = new NCIADicomJob();
    File destFile = new File(System.getProperty("java.io.tmpdir"), "tmpFile.zip");
    FileUtils.copyFile(TestDataFiles.VALID_FILE, destFile);
    dicomJob.setDicomFile(destFile);//from  w w  w .j  a  v a 2  s  . c  om
    dicomJob.setCompleted(true);
    SessionHelper.getInstance().getDisplayableUserWorkspace().setDicomJob(dicomJob);
    assertTrue(destFile.exists());

    NCIADicomFileResult result = new NCIADicomFileResult();
    result.execute(new MockActionInvocation());

    assertFalse(destFile.exists());
    assertFalse(dicomJob.isCompleted());
    assertEquals("application/zip", response.getContentType());
}