Example usage for org.apache.commons.io FileUtils moveFileToDirectory

List of usage examples for org.apache.commons.io FileUtils moveFileToDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils moveFileToDirectory.

Prototype

public static void moveFileToDirectory(File srcFile, File destDir, boolean createDestDir) throws IOException 

Source Link

Document

Moves a file to a directory.

Usage

From source file:com.thoughtworks.go.plugin.activation.DefaultGoPluginActivatorIntegrationTest.java

@Test
public void shouldNotLoadClassesFoundInMETA_INFEvenIfTheyAreProperGoExtensionPoints() throws Exception {
    File bundleWithActivator = createBundleWithActivator(BUNDLE_DIR_WHICH_HAS_PROPER_ACTIVATOR,
            DummyTestPlugin.class);
    File sourceClassFile = new File(bundleWithActivator,
            "com/thoughtworks/go/plugin/activation/test/DummyTestPlugin.class");
    File destinationFile = new File(bundleWithActivator,
            "META-INF/com/thoughtworks/go/plugin/activation/test/");
    FileUtils.moveFileToDirectory(sourceClassFile, destinationFile, true);

    Bundle bundle = installBundleFoundInDirectory(bundleWithActivator);
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
    GoPluginDescriptor descriptor = registry.getPlugin(GO_TEST_DUMMY_SYMBOLIC_NAME);
    assertThat(descriptor.isInvalid(), is(true));
    assertThat(descriptor.getStatus().getMessages().contains(NO_EXT_ERR_MSG), is(true));

}

From source file:fr.gael.dhus.datastore.FileSystemDataStore.java

/**
 * Moves product download zip into the given destination.
 * <p><b>Note:</b> generates the zip of product if necessary.</p>
 *
 * @param product     product to move./*from ww w  .j  a v  a 2 s . c om*/
 * @param destination destination of product
 */
private void moveProduct(Product product, String destination) {

    if (destination == null || destination.trim().isEmpty()) {
        return;
    }

    Path zip_destination = Paths.get(destination);
    String download_path = product.getDownloadablePath();
    try {
        if (download_path != null) {
            File product_zip_file = Paths.get(download_path).toFile();
            FileUtils.moveFileToDirectory(product_zip_file, zip_destination.toFile(), true);
        } else {
            Path product_path = Paths.get(product.getPath().getPath());
            if (UnZip.supported(product_path.toAbsolutePath().toString())) {
                FileUtils.moveFileToDirectory(product_path.toFile(), zip_destination.toFile(), true);
            } else {
                zip_destination.resolve(product_path.getFileName());
                generateZip(product_path.toFile(), zip_destination.toFile());
            }
        }
    } catch (IOException e) {
        LOGGER.error("Cannot move product: " + product.getPath() + " into " + destination, e);
    }
}

From source file:com.stefanbrenner.droplet.service.impl.XMPMetadataService.java

/**
 * A new raw file was created in the watched folder. A new xmp file with the
 * same filename as the raw file is created and the metadata gets added to
 * it. If an output folder is set, both files are finally moved to that
 * folder.//from w  w  w  . jav  a2  s .  c o  m
 * 
 * @param rawFile
 *            the new raw file
 */
@Override
public void onFileCreate(final File rawFile) {

    dropletContext.addLoggingMessage(Messages.getString("ProcessingPanel.newRAWFileFound", rawFile.getName()));

    try {
        // create xmp file
        File xmpFile = com.stefanbrenner.droplet.utils.FileUtils.newFileBasedOn(rawFile, "xmp");

        // fill with metadata
        XMPMeta xmpMeta = XMPMetaFactory.create();

        /* Keywords */
        for (String tag : StringUtils.split(metadata.getTags(), ',')) {
            xmpMeta.appendArrayItem(SCHEMA_DC, "dc:subject", new PropertyOptions().setArray(true),
                    StringUtils.trim(tag), null);
        }

        /* Title and Description */
        // xmpMeta.setLocalizedText(schemaDc, "dc:title",
        // "x-default", "x-default", "Droplet Title");
        String description = StringUtils.trim(metadata.getDescription());
        description += "\n\n" + TITLE;
        description += "\n" + Configuration.getMessageProtocolProvider().getName();
        description += "\n" + dropletContext.getLastSetMessage();
        xmpMeta.setLocalizedText(SCHEMA_DC, "dc:description", "x-default", "x-default", description);

        // final String NS_DRP = "http://www.droplet.com/schema/1.0/";
        // REGISTRY.registerNamespace(NS_DRP, "drp");
        //
        // for (IActionDevice device :
        // dropletContext.getDroplet().getDevices(IActionDevice.class)) {
        // xmpMeta.appendArrayItem(NS_DRP, "device", new
        // PropertyOptions().setArray(true),
        // "Device " + device.getName(), null);
        // for (IAction action : device.getEnabledActions()) {
        // xmpMeta.appendArrayItem(NS_DRP, "action", new
        // PropertyOptions().setArray(true),
        // "Action " + action.getOffset(), null);
        // }
        // }

        /* UserComments */
        xmpMeta.setProperty(SCHEMA_EXIF, "exif:UserComment",
                "This picture was created with the help of Droplet - Toolkit for Liquid Art Photographer");

        // write to file
        FileOutputStream fos = FileUtils.openOutputStream(xmpFile);
        XMPMetaFactory.serialize(xmpMeta, fos, new SerializeOptions(SerializeOptions.OMIT_PACKET_WRAPPER));
        fos.close();

        dropletContext
                .addLoggingMessage(Messages.getString("ProcessingPanel.newXMPFileCreated", xmpFile.getName()));

        if (outputFolderURI != null) {
            File outputFolder = new File(outputFolderURI);
            FileUtils.moveFileToDirectory(xmpFile, outputFolder, false);
            FileUtils.moveFileToDirectory(rawFile, outputFolder, false);
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (XMPException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.github.jengelman.gradle.plugins.integration.TestFile.java

public void moveToDirectory(File target) {
    if (target.exists() && !target.isDirectory()) {
        throw new RuntimeException(String.format("Target '%s' is not a directory", target));
    }/*w ww.j a  v  a  2  s  .  co m*/
    try {
        FileUtils.moveFileToDirectory(this, target, true);
    } catch (IOException e) {
        throw new RuntimeException(
                String.format("Could not move test file '%s' to directory '%s'", this, target), e);
    }
}

From source file:com.datatorrent.contrib.avro.AvroFileInputOperatorTest.java

private void writeErrorFile(int cnt, File errorFile) throws IOException {
    List<String> allLines = Lists.newArrayList();
    HashSet<String> lines = Sets.newHashSet();
    for (int line = 0; line < 5; line++) {
        lines.add("f0" + "l" + line);
    }/*from  w  w w .jav a  2 s . co m*/

    allLines.addAll(lines);

    FileUtils.write(errorFile, StringUtils.join(lines, '\n'));

    FileUtils.moveFileToDirectory(new File(errorFile.getAbsolutePath()), new File(testMeta.dir), true);
}

From source file:com.siberhus.tdfl.DataFileLoader.java

/**
 * /*from w w  w.j a  va2 s  . c  om*/
 */
private void _load() {
    Resource sources[] = getSources();
    if (sources == null) {
        return;
    }

    DataFileReader reader = null;
    DataFileWriter successWriter = null, errorWriter = null;

    for (int i = 0; i < sources.length; i++) {
        Resource source = sources[i];
        try {
            String filename = source.getFilename();
            DataFileHandler fileHandler = null;
            for (DataFileHandler fh : dataFileHandlers) {
                if (fh.accept(filename)) {
                    fileHandler = fh;
                    break;
                }
            }
            if (fileHandler == null) {
                throw new DataFileLoaderException("No handler found for filename: " + filename);
            }

            reader = fileHandler.getReader();
            reader.setResource(source);
            successWriter = fileHandler.getSuccessWriter();
            if (successWriter != null) {
                Resource successResource = fileHandler.getSuccessResourceCreator().create(source);
                successWriter.setResource(successResource);
            }
            errorWriter = fileHandler.getErrorWriter();
            if (errorWriter != null) {
                Resource errorResource = fileHandler.getErrorResourceCreator().create(source);
                errorWriter.setResource(errorResource);
            }

            DataContext dataContext = new DataContext(this.attributes);
            dataContext.resource = source;
            dataContext.resourceNum = i;
            dataContext.startTime = new Date();
            if (dataFileProcessor instanceof DataContextAware) {
                ((DataContextAware) dataFileProcessor).setDataContext(dataContext);
            }
            try {
                doReadProcessWrite(dataContext, reader, successWriter, errorWriter);
                dataContext.exitStatus = ExitStatus.COMPLETED;
            } catch (Exception e) {
                dataContext.exitStatus = ExitStatus.FAILED;
                throw e;
            } finally {
                dataContext.finishTime = new Date();
                //may persist dataContext here

                if (reader != null)
                    try {
                        reader.close();
                    } catch (Exception e) {
                    }
                if (successWriter != null)
                    try {
                        successWriter.close();
                    } catch (Exception e) {
                    }
                if (errorWriter != null)
                    try {
                        errorWriter.close();
                    } catch (Exception e) {
                    }
            }

            if (shouldDeleteIfFinish) {
                logger.info("Deleting file " + source);
                source.getFile().delete();
            } else if (destination != null) {
                File destFile = destination.getFile();
                logger.debug("Moving file: " + source.getFile().getCanonicalPath() + " to file: "
                        + destFile.getCanonicalPath());
                if (resource.getFile().isDirectory()) {
                    FileUtils.moveFileToDirectory(source.getFile(), destFile, true);
                } else {
                    FileUtils.moveFile(source.getFile(), destFile);
                }
            }

        } catch (Exception e) {
            if (stopOnError) {
                if (e instanceof DataFileLoaderException) {
                    throw (DataFileLoaderException) e;
                } else {
                    throw new DataFileLoaderException(e.getMessage(), e);
                }
            } else {
                logger.error(e.getMessage(), e);
            }
        }
    } //for each resource
}

From source file:net.mad.ads.base.api.importer.Importer.java

private void moveFileToDirectory(File file, String directory) {
    try {//w ww.  j  av a2s  . co  m
        FileUtils.moveFileToDirectory(file, new File(this.basePath, directory), true);
    } catch (Exception e) {
        logger.error("moving file to directory " + directory, e);
    }
}

From source file:models.data.providers.LogProvider.java

/**
 * 20130924: add for all none standard folder and folder of adhoc components
 * /*from  ww  w.j a  v  a 2  s. co  m*/
 * @param dateForArchive
 * @param logFolder
 */
public static void moveFilesForAppLogs(String dateForArchive, String logFolder) {

    try {
        String appLogsFolderPath = logFolder;
        List<String> fileNamesForAppLogs = FileIoUtils.getFileNamesInFolder(appLogsFolderPath);

        String destDirPath = generateAppLogAchiveFolderDate(dateForArchive, logFolder);

        // now create folder
        FileIoUtils.createFolder(destDirPath);

        File destDir = new File(destDirPath);

        for (String appLogFileName : fileNamesForAppLogs) {

            // only move for that date.
            if (!appLogFileName.startsWith(dateForArchive)
                    // 201309 for none standard logs and for ADHOCDATASTORE
                    // components
                    && !(appLogFileName.startsWith(VarUtils.ADHOCDATASTORE)
                            && appLogFileName.contains(dateForArchive))

            ) {
                continue;
            }

            String appLogAbsolutePath = generateAppLogAbsolutePath(logFolder);
            String appLogFileFullPath = appLogAbsolutePath + appLogFileName;

            File srcFile = new File(appLogFileFullPath);
            FileUtils.moveFileToDirectory(srcFile, destDir, true);

        } // end for loop

    } catch (Throwable e) {
        e.printStackTrace();
        models.utils.LogUtils
                .printLogError("Error in moveFilesForAppLogs " + DateUtils.getNowDateTimeStrSdsm());
    }

}

From source file:com.datatorrent.contrib.avro.AvroFileInputOperatorTest.java

private void writeAvroFile(File outputFile) throws IOException {

    DatumWriter<GenericRecord> datumWriter = new GenericDatumWriter<GenericRecord>(
            new Schema.Parser().parse(AVRO_SCHEMA));

    DataFileWriter<GenericRecord> dataFileWriter = new DataFileWriter<GenericRecord>(datumWriter);
    dataFileWriter.create(new Schema.Parser().parse(AVRO_SCHEMA), outputFile);

    for (GenericRecord record : recordList) {
        dataFileWriter.append(record);// www.  j  a v  a2  s. co m
    }

    dataFileWriter.close();

    FileUtils.moveFileToDirectory(new File(outputFile.getAbsolutePath()), new File(testMeta.dir), true);

}

From source file:com.hortonworks.streamline.streams.service.CustomProcessorUploadHandler.java

private void moveFileToDirectory(File fileToMove, File moveToDirectory) throws IOException {
    FileUtils.moveFileToDirectory(fileToMove, moveToDirectory, false);
}