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.buddycloud.mediaserver.download.DownloadVideoTest.java

@Override
protected void testSetUp() throws Exception {
    File destDir = new File(configuration.getProperty(MediaServerConfiguration.MEDIA_STORAGE_ROOT_PROPERTY)
            + File.separator + BASE_CHANNEL);
    if (!destDir.mkdir()) {
        FileUtils.cleanDirectory(destDir);
    }/*from ww w  .j av a 2s . c om*/

    FileUtils.copyFile(new File(TEST_FILE_PATH + TEST_VIDEO_NAME),
            new File(destDir + File.separator + MEDIA_ID));

    Media media = buildMedia(MEDIA_ID, TEST_FILE_PATH + TEST_VIDEO_NAME);
    dataSource.storeMedia(media);

    // mocks
    AuthVerifier authClient = xmppTest.getAuthVerifier();
    EasyMock.expect(authClient.verifyRequest(BASE_USER, BASE_TOKEN, URL)).andReturn(true);

    PubSubClient pubSubClient = xmppTest.getPubSubClient();
    EasyMock.expect(pubSubClient.matchUserCapability(EasyMock.matches(BASE_USER),
            EasyMock.matches(BASE_CHANNEL), (CapabilitiesDecorator) EasyMock.notNull())).andReturn(true);

    EasyMock.replay(authClient);
    EasyMock.replay(pubSubClient);
}

From source file:com.hs.mail.imap.message.MailMessage.java

public void save(boolean deleteSrc) throws IOException {
    File dest = Config.getDataFile(getInternalDate(), getPhysMessageID());
    if (deleteSrc) {
        FileUtils.moveFile(file, dest);//ww w.j  a v a2s.  c o m
    } else {
        FileUtils.copyFile(file, dest);
    }
}

From source file:com.buddycloud.mediaserver.update.UpdateAvatarTest.java

@Override
protected void testSetUp() throws Exception {
    File destDir = new File(configuration.getProperty(MediaServerConfiguration.MEDIA_STORAGE_ROOT_PROPERTY)
            + File.separator + BASE_CHANNEL);
    if (!destDir.mkdir()) {
        FileUtils.cleanDirectory(destDir);
    }/*ww  w .j a  v  a 2s.  c  o m*/

    FileUtils.copyFile(new File(TEST_FILE_PATH + TEST_AVATAR_NAME),
            new File(destDir + File.separator + MEDIA_ID));

    Media media = buildMedia(MEDIA_ID, TEST_FILE_PATH + TEST_AVATAR_NAME);
    dataSource.storeMedia(media);
    dataSource.storeAvatar(media);

    // mocks
    AuthVerifier authClient = xmppTest.getAuthVerifier();
    EasyMock.expect(authClient.verifyRequest(EasyMock.matches(BASE_USER), EasyMock.matches(BASE_TOKEN),
            EasyMock.startsWith(URL))).andReturn(true);

    PubSubClient pubSubClient = xmppTest.getPubSubClient();
    EasyMock.expect(pubSubClient.matchUserCapability(EasyMock.matches(BASE_USER),
            EasyMock.matches(BASE_CHANNEL), (CapabilitiesDecorator) EasyMock.notNull())).andReturn(true);

    EasyMock.replay(authClient);
    EasyMock.replay(pubSubClient);
}

From source file:de.joinout.criztovyl.tools.CloneUtils.java

/**
 * Copies a file and keep the same modification date/time.
 * @param src/*w w  w.  jav a  2s.  c  om*/
 *            the source path
 * @param target
 *            the target path
 * @throws IOException If an I/O error occurs
 */
public static void cloneFile(Path src, Path target) throws IOException {

    // Cancel if is no file
    if (!src.getFile().isFile())
        return;

    // Copy file
    FileUtils.copyFile(src.getFile(), target.getFile());

    // Long is not accurate enough, so re-set lastModifed @ src file
    src.getFile().setLastModified(src.getFile().lastModified());

    // Copy lastModified to target file
    target.getFile().setLastModified(src.getFile().lastModified());

}

From source file:co.com.sigemco.alfa.admin.logica.LogoLogica.java

/**
 * Funcion con la cual guardo la imagen en el repositorio de imagenes
 * @return /*from w ww.j  a  va 2  s  . co m*/
 */
public String guardaImagenServidor(File file) {
    String rta = "Ok";
    try {
        File nuevoArchivo = new File(this.rutaBase + "logo.jpg");
        FileUtils.copyFile(nuevoArchivo, file);
    } catch (Exception e) {
        e.printStackTrace();
        rta = "Error " + e;
    }
    return rta;
}

From source file:fr.inria.atlanmod.neoemf.benchmarks.datastore.helper.BackendHelper.java

public static File copyStore(File sourceFile) throws IOException {
    File outputFile = Workspace.newTempDirectory().resolve(sourceFile.getName()).toFile();

    log.info("Copy {} to {}", sourceFile, outputFile);

    if (sourceFile.isDirectory()) {
        FileUtils.copyDirectory(sourceFile, outputFile, true);
    } else {//from w  w  w  .  j a  v  a2 s  .co m
        FileUtils.copyFile(sourceFile, outputFile);
    }

    return outputFile;
}

From source file:gov.nih.nci.caintegrator.file.FileManagerImpl.java

/**
 * {@inheritDoc}/* ww w.  j  av a2s.  c o m*/
 */
public File storeStudyFile(File sourceFile, String filename, StudyConfiguration studyConfiguration)
        throws IOException {
    File destFile = new File(getStudyDirectory(studyConfiguration), filename);
    try {
        FileUtils.copyFile(sourceFile, destFile);
    } catch (IOException e) {
        LOGGER.error("Couldn't copy " + sourceFile.getAbsolutePath() + " to " + destFile.getAbsolutePath(), e);
        throw e;
    }
    return destFile;
}

From source file:com.frostwire.platform.DefaultFileSystem.java

@Override
public boolean copy(File src, File dest) {
    try {//from   ww  w  .  j  a  v  a2  s .c o m
        FileUtils.copyFile(src, dest);
        return true;
    } catch (Throwable e) {
        LOG.error("Error in copy file: " + src + " -> " + dest, e);
    }

    return false;
}

From source file:fm.last.commons.test.TestAssertTest.java

@Test
public void assertFilesEqualWithSameFileInDifferentFolders() throws IOException {
    File file1 = new File(dataFolder.getFolder(), "file1.txt");
    File file2 = temporaryFolder.newFile("copy.txt");
    FileUtils.copyFile(file1, file2);
    TestAssert.assertFileEquals(file1, file2);
}

From source file:com.buddycloud.mediaserver.download.DownloadAvatarTest.java

@Override
protected void testSetUp() throws Exception {
    File destDir = new File(configuration.getProperty(MediaServerConfiguration.MEDIA_STORAGE_ROOT_PROPERTY)
            + File.separator + BASE_CHANNEL);
    if (!destDir.mkdir()) {
        FileUtils.cleanDirectory(destDir);
    }/*from  w w w .  j ava 2  s .  com*/

    FileUtils.copyFile(new File(TEST_FILE_PATH + TEST_AVATAR_NAME),
            new File(destDir + File.separator + MEDIA_ID));

    Media media = buildMedia(MEDIA_ID, TEST_FILE_PATH + TEST_AVATAR_NAME);
    dataSource.storeMedia(media);
    dataSource.storeAvatar(media);

    // mocks
    AuthVerifier authClient = xmppTest.getAuthVerifier();
    EasyMock.expect(authClient.verifyRequest(BASE_USER, BASE_TOKEN, URL)).andReturn(true);

    PubSubClient pubSubClient = xmppTest.getPubSubClient();

    EasyMock.expect(pubSubClient.isChannelPublic(EasyMock.matches(BASE_CHANNEL))).andReturn(true);
    EasyMock.expect(pubSubClient.matchUserCapability(EasyMock.matches(BASE_USER),
            EasyMock.matches(BASE_CHANNEL), (CapabilitiesDecorator) EasyMock.notNull())).andReturn(true);

    EasyMock.replay(authClient);
    EasyMock.replay(pubSubClient);
}