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:net.sourceforge.atunes.kernel.modules.device.TransferToDeviceProcess.java

@Override
protected File transferAudioFile(File destination, AudioFile file, List<Exception> thrownExceptions) {
    String destDir = getDirectory(file, destination, true);
    String newName = getName(file, true);
    File destFile = new File(StringUtils.getString(destDir, SystemProperties.FILE_SEPARATOR, newName));

    try {/*from   w w w.  j  av  a2 s .c  o m*/
        // Now that we (supposedly) have a valid filename write file
        FileUtils.copyFile(file.getFile(), destFile);
    } catch (IOException e) {
        thrownExceptions.add(e);
    }

    return destFile;
}

From source file:controller.admin.api.AddMenuAction.java

@Override
public String execute() {
    db = new MasterDAO();
    galleryBean = new GalleryBean();

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();

    destinationPath = "C:/Users/Kevin/Documents/NetBeansProjects/Univ/SnackImportIndonesia/web/images/uploads/";

    if (menuName != null && categoryName != null & imgFile != null && menuPrice != null) {
        String fileName = menuName + "-" + dateFormat.format(date) + ".jpg";
        File img = new File(destinationPath, fileName);

        galleryBean.setName(menuName);/*w  w  w.j a v  a 2  s.co  m*/
        galleryBean.setCategory(categoryName);
        galleryBean.setImgPath("images/uploads/" + fileName);
        galleryBean.setPrice(menuPrice);
        try {
            FileUtils.copyFile(imgFile, img);
            statusReport = db.getGalleryMenuDAO().addMenu(galleryBean);

        } catch (IOException ex) {
            Logger.getLogger(AddMenuAction.class.getName()).log(Level.SEVERE, null, ex);
            statusReport = "saving image went wrong!";
        }
    }

    return SUCCESS;
}

From source file:gov.redhawk.core.filemanager.filesystem.JavaFileSystem.java

@Override
public void copy(final String sourceFileName, final String destinationFileName)
        throws InvalidFileName, FileException {
    if ("".equals(sourceFileName) || "".equals(destinationFileName)) {
        throw new InvalidFileName(ErrorNumberType.CF_EIO, "");
    }//  w  w w . j av  a 2  s .c om
    if (sourceFileName.equals(destinationFileName)) {
        throw new InvalidFileName(ErrorNumberType.CF_EINVAL,
                "Source file must be different from destination file.");
    }
    final File sourceFile = new File(this.root, sourceFileName);
    try {
        FileUtils.copyFile(sourceFile, new File(this.root, destinationFileName));
    } catch (final IOException e) {
        throw new FileException(ErrorNumberType.CF_EIO, e.getMessage());
    }
}

From source file:functionaltests.CopyFileExecutable.java

@Override
public Serializable execute(TaskResult... results) throws Throwable {
    File localSpaceFolder = new File(".");
    System.out.println("Using current space folder " + localSpaceFolder.getAbsolutePath());
    System.out.println(Arrays.toString(localSpaceFolder.listFiles()));
    File[] inputFiles = localSpaceFolder.listFiles(new FilenameFilter() {
        @Override//from   ww  w  . j  a v  a  2 s. c  o m
        public boolean accept(File dir, String name) {
            return name.endsWith(TestSmartProxy.inputFileExt);
        }
    });

    for (File inputFile : inputFiles) {
        String outputFileName = inputFile.getName().replace("input", "output")
                .replace(TestSmartProxy.inputFileExt, TestSmartProxy.outputFileExt);
        File outputFile = new File(outputFileName);
        FileUtils.copyFile(inputFile, outputFile);
        System.out.println("Written file " + outputFile.getAbsolutePath());
    }
    return "OK";
}

From source file:de.arago.rike.leaderboard.LeaderBoardImagesServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("image/png");

    try {/*from ww w. j  a v  a  2s  .c  o  m*/
        SVGDataServlet.addExpires(response);

        int pos = request.getRequestURL().lastIndexOf("/");
        String name = request.getRequestURL().substring(pos + 1);
        File tmp = new File(System.getProperty("java.io.tmpdir"), name);
        if (!tmp.exists()) {
            String uri = GlobalConfig.get(GlobalConfig.PATH_TO_PERSONAL_PICS);
            URL resource = (new URI(uri + name)).toURL();
            FileUtils.copyURLToFile(resource, tmp);
        }
        FileUtils.copyFile(tmp, response.getOutputStream());
    } catch (Exception ex) {
        IOUtils.copy(LeaderBoardImagesServlet.class.getResourceAsStream("/unknown.png"),
                response.getOutputStream());
    }
}

From source file:com.linkedin.pinot.core.segment.store.SegmentDirectoryPathsTest.java

@Test
public void testFindMetadataFile() throws IOException {
    File tempDirectory = null;//w  ww  .  j a  va  2 s  .co  m
    try {
        // setup temp dir, v3 subdir and create metadata.properties in both
        tempDirectory = new File(SegmentDirectoryPaths.class.toString());
        tempDirectory.deleteOnExit();
        FileUtils.forceMkdir(tempDirectory);
        File v3Dir = new File(tempDirectory, "v3");
        FileUtils.forceMkdir(v3Dir);
        File metaFile = new File(tempDirectory, V1Constants.MetadataKeys.METADATA_FILE_NAME);
        try (FileOutputStream outputStream = new FileOutputStream(metaFile)) {
            outputStream.write(10);
        }
        File v3MetaFile = new File(v3Dir, V1Constants.MetadataKeys.METADATA_FILE_NAME);
        FileUtils.copyFile(metaFile, v3MetaFile);

        {
            File testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), metaFile.toString());

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v1);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), metaFile.toString());

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v3);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), v3MetaFile.toString());
        }
        {
            // drop v1 metadata file
            FileUtils.forceDelete(metaFile);
            File testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), v3MetaFile.toString());

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v1);
            Assert.assertNull(testMetaFile);

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v3);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), v3MetaFile.toString());
        }
        {
            // drop v3 metadata file
            FileUtils.forceDelete(v3MetaFile);
            File testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory);
            Assert.assertNull(testMetaFile);

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v1);
            Assert.assertNull(testMetaFile);

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v3);
            Assert.assertNull(testMetaFile);
        }
    } finally {
        if (tempDirectory != null) {
            FileUtils.deleteQuietly(tempDirectory);
        }
    }
}

From source file:com.microsoftopentechnologies.windowsazurestorage.helper.CredentialMigration.java

private static File backupFile(String sourceFile) throws IOException {
    String backupFile = sourceFile + ".backup";
    LOGGER.log(Level.INFO, sourceFile + ".backup has been created for backup.");
    File backUp = new File(backupFile);
    FileUtils.copyFile(new File(sourceFile), backUp);
    return backUp;
}

From source file:com.splunk.shuttl.archiver.filesystem.glacier.FakeArchiveTransferManager.java

private void copyFile(File managedFile, File outputFile) {
    try {/*w  w  w. j av a 2  s  .  c o m*/
        FileUtils.copyFile(managedFile, outputFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.bfour.fpliteraturecollector.service.FileStorageService.java

public Link persist(File localFile, Literature lit) throws IOException {

    String fileName = getFileNameForLiterature(lit);
    fileName += "." + FilenameUtils.getExtension(localFile.getAbsolutePath());
    File file = new File(rootDirectory.getAbsolutePath() + "/" + lit.getID() + "/" + fileName);

    FileUtils.copyFile(localFile, file);

    return new Link(fileName, file.toURI());

}

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

@Before
public void setUp() throws IOException {

    object = ath.putPackageToStorage(IDENTIFIER, ORIG_NAME, containerName, new Date(), 100);
    FileUtils.copyFile(Path.makeFile(TC.TEST_ROOT_AT, ORIG_NAME + "2.tgz"),
            Path.makeFile(localNode.getIngestAreaRootPath(), C.TEST_USER_SHORT_NAME, containerName));
}