Example usage for org.apache.commons.io FilenameUtils concat

List of usage examples for org.apache.commons.io FilenameUtils concat

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils concat.

Prototype

public static String concat(String basePath, String fullFilenameToAdd) 

Source Link

Document

Concatenates a filename to a base path using normal command line style rules.

Usage

From source file:com.abiquo.api.tasks.util.DatacenterTaskBuilder.java

/**
 * Adds a new {@link SnapshotVirtualMachineOp} to the Jobs collection.
 * //from  w w w.  j ava2s . c om
 * @param destinationDisk The destination disk for the snapshot
 * @return The {@link DatacenterTaskBuilder} self
 */
public DatacenterTaskBuilder addSnapshot(final DiskSnapshot destinationDisk) {
    SnapshotVirtualMachineOp job = new SnapshotVirtualMachineOp();
    job.setVirtualMachine(definition);
    job.setHypervisorConnection(hypervisor);
    job.setDiskSnapshot(destinationDisk);

    this.tarantinoTask.addDatacenterJob(job);

    Job redisJob = createRedisJob(job.getId(), JobType.SNAPSHOT);
    redisJob.getData().put("name", destinationDisk.getName());
    redisJob.getData().put("path",
            FilenameUtils.concat(destinationDisk.getPath(), destinationDisk.getSnapshotFilename()));

    this.asyncTask.getJobs().add(redisJob);

    return this;
}

From source file:edu.cornell.med.icb.goby.algorithmic.algorithm.TestAccumulate.java

@Before
public void setUp() throws IOException {
    computeCount = new ComputeCount();
    final File tempDir = File.createTempFile("accumulate", "test", new File(BASE_TEST_DIR));
    FileUtils.deleteQuietly(tempDir);//  ww  w .j a  v  a  2 s  .  c  om
    FileUtils.forceMkdir(tempDir);
    testDir = FilenameUtils.concat(BASE_TEST_DIR, tempDir.getName());

    if (LOG.isDebugEnabled()) {
        LOG.debug("Using test directory: " + testDir);
    }
}

From source file:edu.kit.dama.util.SystemUtils.java

/**
 * Generate the chgrp script for Unix systems.
 *
 * @return The full path to the chgrp script.
 *
 * @throws IOException If the generation fails.
 *///from w  w  w .  j  a  v a2 s. com
private static String generateChgrpScript() throws IOException {
    String scriptFile;
    FileWriter fout = null;
    try {
        scriptFile = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "chgrpFolder.sh");
        fout = new FileWriter(scriptFile, false);
        StringBuilder b = new StringBuilder();
        b.append("#!/bin/sh\n");
        b.append("echo Changing ownership of $2 to $1\n");
        b.append("chgrp $1 $2 -R\n");
        LOGGER.debug("Writing script data to '{}'", scriptFile);
        fout.write(b.toString());
        fout.flush();
    } finally {
        if (fout != null) {
            try {
                fout.close();
            } catch (IOException ioe) {//ignore
            }
        }
    }
    return scriptFile;
}

From source file:com.mbrlabs.mundus.assets.EditorAssetManager.java

private FileHandle copyToAssetFolder(FileHandle file) {
    FileHandle copy = new FileHandle(FilenameUtils.concat(rootFolder.path(), file.name()));
    file.copyTo(copy);
    return copy;
}

From source file:integration.DeleteServiceFilesTest.java

/**
 * Forms a path depending on the type of file to be deleted
 * and its id./*from w ww .  j  a  v a2  s .  co m*/
 * 
 * @param dataDir The path to the directory
 * @param klass The type of object to handle.
 * @param id The identifier of the object.
 */
private String getPath(String klass, Long id) throws Exception {
    String suffix = "";
    String prefix = "";
    Long remaining = id;
    Long dirno = 0L;

    if (id == null) {
        throw new NullPointerException("Expecting a not-null id.");
    }

    if (klass.equals(REF_ORIGINAL_FILE)) {
        prefix = FilenameUtils.concat(dataDir, "Files");
    } else if (klass.equals(REF_PIXELS)) {
        prefix = FilenameUtils.concat(dataDir, "Pixels");
    } else if (klass.equals(REF_THUMBNAIL)) {
        prefix = FilenameUtils.concat(dataDir, "Thumbnails");
    } else {
        throw new Exception("Unknown class: " + klass);
    }

    while (remaining > 999) {
        remaining /= 1000;

        if (remaining > 0) {
            Formatter formatter = new Formatter();
            dirno = remaining % 1000;
            suffix = formatter.format("Dir-%03d", dirno).out().toString() + File.separator + suffix;
        }
    }

    String path = FilenameUtils.concat(prefix, suffix + id);
    return path;
}

From source file:es.urjc.mctwp.image.impl.collection.fs.ImageContentCollectionFSImpl.java

/**
 * Once both path for temporal and persistent images are specified, it is
 * created temporal collection/*from   w w w.  j  ava2s .  c  o m*/
 */
private void createTempCollection() {
    tmpcoll = new File(FilenameUtils.concat(fsBaseDirPath, fsTmpCollDir));
    if (!tmpcoll.exists())
        tmpcoll.mkdir();
}

From source file:com.stgmastek.core.logic.ExecutionOrder.java

/**
 * Reads the saved state of the batch for revision runs 
 * If the current batch number it 1000 and revision is 5, 
 * then this method would look for saved state of batch 1000 
 * with revision (5 - 1) i.e. '1000_4.savepoint' 
 * /*from   w  w  w .  j a v  a2  s . co  m*/
 * @param batchContext
 *         The context for the batch 
 * @throws BatchException
 *          Any exception thrown during reading of the serialized file 
 */
public static synchronized void updateBatchState(BatchContext batchContext) throws BatchException {
    BatchInfo newBatchInfo = batchContext.getBatchInfo();
    String savepointFilePath = Configurations.getConfigurations().getConfigurations("CORE", "SAVEPOINT",
            "DIRECTORY");
    String savePointFile = FilenameUtils.concat(savepointFilePath,
            newBatchInfo.getBatchNo() + "_" + (newBatchInfo.getBatchRevNo() - 1) + ".savepoint");
    if (logger.isDebugEnabled()) {
        logger.debug("Reading the saved state from file : " + savePointFile);
    }
    FileInputStream fis = null;
    try {

        //Check whether the file exists
        File f = new File(savePointFile);
        if (!f.exists())
            throw new BatchException("Cannot locate the the save point file named :" + savePointFile);

        fis = new FileInputStream(f);
        ObjectInputStream ois = new ObjectInputStream(fis);
        BatchInfo savedBatchInfo = (BatchInfo) ois.readObject();
        newBatchInfo.setOrderedMap(savedBatchInfo.getOrderedMap());
        newBatchInfo.setProgressLevelAtLastSavePoint(
                (ProgressLevel) savedBatchInfo.getProgressLevelAtLastSavePoint()); //This object is different but still cloned.
        newBatchInfo.setBatchRunDate(savedBatchInfo.getBatchRunDate());
        newBatchInfo.setDateRun(savedBatchInfo.isDateRun());

        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Last batch saved state is " + savedBatchInfo.getProgressLevelAtLastSavePoint().toString());
        }
        //Set the ExecutionStatus in the ProgressLevel
        ExecutionStatus savedExecutionStatus = newBatchInfo.getProgressLevelAtLastSavePoint()
                .getExecutionStatus();
        ProgressLevel.getProgressLevel(newBatchInfo.getBatchNo())
                .setExecutionStatus(savedExecutionStatus.getEntity(), savedExecutionStatus.getStageCode());
        fis.close();
        fis = null;
        ois.close();
        ois = null;
    } catch (FileNotFoundException e) {
        logger.error(e);
        throw new BatchException(e.getMessage(), e);
    } catch (IOException e) {
        logger.error(e);
        throw new BatchException(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        logger.error(e);
        throw new BatchException(e.getMessage(), e);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
            }
        }
    }
}

From source file:com.stgmastek.core.purge.PurgeBatchDetails.java

/**
 * The method to create insert scripts./*from   w  w w .  ja va  2  s.  c  om*/
 * 
 * Script creation is in the following order <li>BATCH</li><li>
 * PROGRESS_LEVEL</li><li>LOG</li><li>SYSTEM_INFO</li> <li>INSTRUCTION_LOG</li>
 * <li>INSTRUCTION_PARAMETERS</li></br></br>
 * 
 * @param batchDetailsList
 * @param strOutputDirectory
 * @param strInstallation
 * @return true if create insert scripts successful, false otherwise
 * @throws Exception
 * 
 */
private Boolean insertPurgeScripts(Connection con, ArrayList<String> batchDetailsList,
        String strOutputDirectory, String strInstallation) throws Exception {
    boolean returnValue = false;
    String strOutputFileName;
    int count = 1;
    out.println("Create insert script started..");
    InsertScripts is = null;
    for (String batchno : batchDetailsList) {
        strOutputFileName = FilenameUtils.concat(strOutputDirectory,
                "JBeam" + strInstallation + batchno + ".sql");
        try {
            is = new InsertScripts(con);
            if (logger.isInfoEnabled()) {
                logger.info("Insert script file " + strOutputFileName + " created.");
            }
            File file = new File(strOutputFileName);
            if (file.exists()) {
                if (!file.delete()) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(strOutputFileName + " could not be deleted.");
                    }
                }
            }
            is.setAppendToFile(true);
            is.setFile(strOutputFileName, true);
            String strWhereClause = "WHERE BATCH_NO = " + batchno;

            log("BATCH", count, batchDetailsList.size(), batchno, 1);
            is.echo("insert script for BATCH table");
            is.onTable("BATCH", strWhereClause);

            log("PROGRESS_LEVEL", count, batchDetailsList.size(), batchno, 1);
            is.echo("insert script for PROGRESS_LEVEL table");
            is.onTable("PROGRESS_LEVEL", strWhereClause);

            log("LOG", count, batchDetailsList.size(), batchno, 1);
            is.echo("insert script for LOG table");
            is.onTable("LOG", strWhereClause);

            log("SYSTEM_INFO", count, batchDetailsList.size(), batchno, 1);
            is.echo("insert script for SYSTEM_INFO table");
            is.onTable("SYSTEM_INFO", strWhereClause);

            log("INSTRUCTION_LOG", count, batchDetailsList.size(), batchno, 1);
            is.echo("insert script for INSTRUCTION_LOG table");
            strWhereClause = "WHERE BATCH_NO = " + batchno;
            is.onTable("INSTRUCTION_LOG", strWhereClause);

            log("INSTRUCTION_PARAMETERS", count, batchDetailsList.size(), batchno, 1);
            is.echo("insert script for INSTRUCTION_PARAMETERS table");
            strWhereClause = " b where exists (select a.seq_no from instruction_log a where a.seq_no = b.instruction_log_no and a.batch_no = "
                    + batchno + " )";
            is.onTable("INSTRUCTION_PARAMETERS ", strWhereClause);
            count++;
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }
    out.println("Create insert script completed..");
    returnValue = true;
    return returnValue;
}

From source file:com.mosso.client.cloudfiles.sample.FilesCopy.java

public static void getContainerObjects(File localFolder, String containerName) throws IOException,
        HttpException, FilesAuthorizationException, NoSuchAlgorithmException, FilesException {
    FilesClient client = new FilesClient();
    if (client.login()) {
        if (client.containerExists(containerName)) {
            List<FilesObject> objects = client.listObjects(containerName);
            for (FilesObject obj : objects) {
                System.out.println("\t" + StringUtils.rightPad(obj.getName(), 35) + obj.getSizeString());
                File localFile = new File(FilenameUtils.concat(localFolder.getAbsolutePath(), obj.getName()));
                obj.writeObjectToFile(localFile);
            } //for (Object obj: objects)
        } else {/*from w w w.  java2s . c o  m*/
            logger.fatal("The  container: " + containerName + " does not exist.");
            System.out.println("The  container: " + containerName + " does not exist!");
            System.exit(0);
        }
    } //if ( client.login() )
}

From source file:es.urjc.mctwp.image.management.ImageCollectionManager.java

/**
 * This function knows how to retrieve all files of any image and
 * puts all together under a temporal directory. It reproduces 
 * subdirectories when necessary./*  w w  w . ja  v a 2  s.c o  m*/
 * 
 * @param directory
 * @param image
 * @throws IOException
 */
private void copyToDirectory(File directory, Image image) throws IOException {

    if (image instanceof SingleImage) {
        FileUtils.copyFileToDirectory(((SingleImage) image).getContent(), directory);

    } else {

        //Create temp directory where put all file content of Image
        File tmpDir = new File(FilenameUtils.concat(directory.getAbsolutePath(), image.getId()));
        if (tmpDir.exists())
            tmpDir.mkdir();

        //Copy required files in case of Series Images
        if (image instanceof SeriesImage) {
            List<Image> images = ((SeriesImage) image).getImages();
            if (images != null && !images.isEmpty())
                for (Image img : images)
                    copyToDirectory(tmpDir, img);

            //Copy required files in case of Complex Images
        } else if (image instanceof ComplexImage) {
            List<File> aux = ((ComplexImage) image).getContent();

            if (aux != null)
                for (File file : aux)
                    copyToDirectory(tmpDir, file);
        }
    }
}