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.iyonger.apm.web.service.PerfTestService.java

/**
 * Create {@link GrinderProperties} based on the passed {@link PerfTest}.
 *
 * @param perfTest      base data/*from  w  ww .  j a  v  a  2  s .c o  m*/
 * @param scriptHandler scriptHandler
 * @return created {@link GrinderProperties} instance
 */
public GrinderProperties getGrinderProperties(PerfTest perfTest, ScriptHandler scriptHandler) {
    try {
        // Use default properties first
        GrinderProperties grinderProperties = new GrinderProperties(
                config.getHome().getDefaultGrinderProperties());

        User user = perfTest.getCreatedUser();

        // Get all files in the script path
        String scriptName = perfTest.getScriptName();
        FileEntry userDefinedGrinderProperties = fileEntryService.getOne(user,
                FilenameUtils.concat(FilenameUtils.getPath(scriptName), DEFAULT_GRINDER_PROPERTIES), -1L);
        if (!config.isSecurityEnabled() && userDefinedGrinderProperties != null) {
            // Make the property overridden by user property.
            GrinderProperties userProperties = new GrinderProperties();
            userProperties.load(new StringReader(userDefinedGrinderProperties.getContent()));
            grinderProperties.putAll(userProperties);
        }
        grinderProperties.setAssociatedFile(new File(DEFAULT_GRINDER_PROPERTIES));
        grinderProperties.setProperty(GRINDER_PROP_SCRIPT, scriptHandler.getScriptExecutePath(scriptName));

        grinderProperties.setProperty(GRINDER_PROP_TEST_ID, "test_" + perfTest.getId());
        grinderProperties.setInt(GRINDER_PROP_AGENTS, getSafe(perfTest.getAgentCount()));
        grinderProperties.setInt(GRINDER_PROP_PROCESSES, getSafe(perfTest.getProcesses()));
        grinderProperties.setInt(GRINDER_PROP_THREAD, getSafe(perfTest.getThreads()));
        if (perfTest.isThresholdDuration()) {
            grinderProperties.setLong(GRINDER_PROP_DURATION, getSafe(perfTest.getDuration()));
            grinderProperties.setInt(GRINDER_PROP_RUNS, 0);
        } else {
            grinderProperties.setInt(GRINDER_PROP_RUNS, getSafe(perfTest.getRunCount()));
            if (grinderProperties.containsKey(GRINDER_PROP_DURATION)) {
                grinderProperties.remove(GRINDER_PROP_DURATION);
            }
        }
        grinderProperties.setProperty(GRINDER_PROP_ETC_HOSTS,
                StringUtils.defaultIfBlank(perfTest.getTargetHosts(), ""));
        grinderProperties.setBoolean(GRINDER_PROP_USE_CONSOLE, true);
        if (BooleanUtils.isTrue(perfTest.getUseRampUp())) {
            grinderProperties.setBoolean(GRINDER_PROP_THREAD_RAMPUP, perfTest.getRampUpType() == RampUp.THREAD);
            grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT, getSafe(perfTest.getRampUpStep()));
            grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT_INTERVAL,
                    getSafe(perfTest.getRampUpIncrementInterval()));
            if (perfTest.getRampUpType() == RampUp.PROCESS) {
                grinderProperties.setInt(GRINDER_PROP_INITIAL_SLEEP_TIME,
                        getSafe(perfTest.getRampUpInitSleepTime()));
            } else {
                grinderProperties.setInt(GRINDER_PROP_INITIAL_THREAD_SLEEP_TIME,
                        getSafe(perfTest.getRampUpInitSleepTime()));
            }
            grinderProperties.setInt(GRINDER_PROP_INITIAL_PROCESS, getSafe(perfTest.getRampUpInitCount()));
        } else {
            grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT, 0);
        }

        if (BooleanUtils.isTrue(perfTest.getUseFixedRateRPS())) {
            grinderProperties.setDouble(GRINDER_PROP_FIXED_RPS_RATE, perfTest.getRps());
        }
        grinderProperties.setInt(GRINDER_PROP_REPORT_TO_CONSOLE, 500);
        grinderProperties.setProperty(GRINDER_PROP_USER, perfTest.getCreatedUser().getUserId());
        grinderProperties.setProperty(GRINDER_PROP_JVM_CLASSPATH, getCustomClassPath(perfTest));
        grinderProperties.setInt(GRINDER_PROP_IGNORE_SAMPLE_COUNT, getSafe(perfTest.getIgnoreSampleCount()));
        grinderProperties.setBoolean(GRINDER_PROP_SECURITY, config.isSecurityEnabled());
        // For backward agent compatibility.
        // If the security is not enabled, pass it as jvm argument.
        // If enabled, pass it to grinder.param. In this case, I drop the
        // compatibility.
        if (StringUtils.isNotBlank(perfTest.getParam())) {
            String param = perfTest.getParam().replace("'", "\\'").replace(" ", "");
            if (config.isSecurityEnabled()) {
                grinderProperties.setProperty(GRINDER_PROP_PARAM, StringUtils.trimToEmpty(param));
            } else {
                String property = grinderProperties.getProperty(GRINDER_PROP_JVM_ARGUMENTS, "");
                property = property + " -Dparam=" + param + " ";
                grinderProperties.setProperty(GRINDER_PROP_JVM_ARGUMENTS, property);
            }
        }
        LOGGER.info("Grinder Properties : {} ", grinderProperties);
        return grinderProperties;
    } catch (Exception e) {
        throw processException("error while prepare grinder property for " + perfTest.getTestName(), e);
    }
}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

@Test
// To test import of soft clips:
public void testSamToCompactTrickCase13NoGenomeSoftClips() throws IOException {

    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile("test-data/splicedsamhelper/tricky-spliced-13.sam");
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-13");
    importer.setOutputFile(outputFilename);
    importer.setPreserveSoftClips(true);
    importer.execute();//from   w w  w . j a v a2  s.c  o m

    AlignmentReader reader = new AlignmentReaderImpl(outputFilename);
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry first = reader.next();
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry second = reader.next();

    assertEquals(15013, first.getPosition());
    assertEquals(3, first.getQueryPosition());
    assertEquals("AAT", first.getSoftClippedBasesLeft());
    assertEquals("", first.getSoftClippedBasesRight());
    assertEquals(25, first.getQueryAlignedLength());

    assertEquals(15795, second.getPosition());
    assertEquals(28, second.getQueryPosition());
    assertEquals(1, second.getFragmentIndex());
    assertEquals(5, second.getQueryAlignedLength());
    assertEquals("", second.getSoftClippedBasesLeft());
    assertEquals("TC", second.getSoftClippedBasesRight());
}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

@Test
// To test import of soft clips:
public void testSamToCompactTrickCase13SoftClipsWithGenome() throws IOException {

    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile("test-data/splicedsamhelper/tricky-spliced-14.sam");
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-14");

    MutableString seq = new MutableString();

    seq.append("NCAGTGCCCACCTTGGCTCGTGGCTCTCANNNNNNNNNNCTTGCCTNNN");
    String[] refs = { seq.toString() };

    RandomAccessSequenceTestSupport genomeTestSupport = new RandomAccessSequenceTestSupport(refs);
    importer.setGenome(genomeTestSupport);
    importer.setOutputFile(outputFilename);
    importer.setPreserveSoftClips(true);
    importer.execute();/*ww  w.j a  v  a  2  s . co  m*/

    AlignmentReader reader = new AlignmentReaderImpl(outputFilename);
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry first = reader.next();
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry second = reader.next();

    assertEquals(4, first.getPosition());
    assertEquals(3, first.getQueryPosition());
    assertEquals("A=T", first.getSoftClippedBasesLeft());
    assertEquals("", first.getSoftClippedBasesRight());
    assertEquals(25, first.getQueryAlignedLength());

    assertEquals(40 - 1, second.getPosition());
    assertEquals(28, second.getQueryPosition());
    assertEquals(1, second.getFragmentIndex());
    assertEquals(5, second.getQueryAlignedLength());
    assertEquals("TC", second.getSoftClippedBasesRight());
    assertEquals("", second.getSoftClippedBasesLeft());

}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

@Test
// To test import of three splice with initial 2-clip.
public void testSamToCompactTrickCase15NoGenomeThreeSplice() throws IOException {

    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile("test-data/splicedsamhelper/tricky-spliced-15.sam");
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-15");
    importer.setOutputFile(outputFilename);
    importer.setPreserveSoftClips(true);
    //  importer.setPropagateTargetIds(true);
    importer.execute();//  w  ww. j  av a 2s .  co m

    AlignmentReader reader = new AlignmentReaderImpl(outputFilename);
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry first = reader.next();
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry second = reader.next();
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry third = reader.next();

    assertEquals(32485524 - 1, first.getPosition());
    assertEquals(2, first.getQueryPosition());
    assertEquals("CG", first.getSoftClippedBasesLeft());
    assertEquals("", first.getSoftClippedBasesRight());
    assertEquals(6, first.getQueryAlignedLength());

    assertEquals(32485524 + 6 + 301 - 1, second.getPosition());
    assertEquals(8, second.getQueryPosition());
    assertEquals("", second.getSoftClippedBasesLeft());
    assertEquals("", second.getSoftClippedBasesRight());
    assertEquals(24, second.getQueryAlignedLength());

    assertEquals(32485524 + 6 + 301 + 24 + 478 - 1, third.getPosition());
    assertEquals(32, third.getQueryPosition());
    assertEquals("", third.getSoftClippedBasesLeft());
    assertEquals("", third.getSoftClippedBasesRight());
    assertEquals(3, third.getQueryAlignedLength());
}

From source file:edu.cornell.med.icb.goby.stats.TestAnnotationAveragingWriter.java

private String makeDensityEstimator() throws IOException {
    int fixedValue = 40;
    EstimatedDistribution estimator = new EstimatedDistribution(1,
            new PassThroughStatisticAdaptor(100, fixedValue));
    estimator.setBinningStrategy(new FastSmallAndLog10BinningStrategy());
    int[] delta = { 0000, 001, 002, 003, 004, 5 };
    int[] frequencies = { 1000, 900, 800, 700, 600, 1 };
    for (int index = 0; index < delta.length; index++) {

        for (int i = 0; i < frequencies[index]; i++) {
            estimator.observe(0, fixedValue, delta[index]);
        }//from  w  ww.j a  v a 2s  . co  m
    }
    String filename = FilenameUtils.concat(BASE_TEST_DIR, "density.bin");
    EstimatedDistribution.store(estimator, filename);
    return filename;
}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

@Test
// Failed on server when converting back to BAM because seqVar.position would be set to zero:

public void testSamToCompactTrickCase19() throws IOException {

    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile("test-data/splicedsamhelper/tricky-spliced-19.sam");
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-19");
    importer.setOutputFile(outputFilename);
    importer.setPreserveSoftClips(true);
    //  importer.setPropagateTargetIds(true);
    importer.execute();//w  w w  . jav a2  s. c o  m
    AlignmentReader reader = new AlignmentReaderImpl(outputFilename);
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry first = reader.next();
    assertFalse(reader.hasNext());
    assertEquals("seqVar.position must be zero", 0, first.getSequenceVariations(0).getPosition());
}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

@Test
// Failed on server when converting back to BAM because seqVar.position would be set to zero:

public void testSamToCompactTrickCase20() throws IOException {

    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile("test-data/sam/test.sam");
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "test-sam-1");
    importer.setOutputFile(outputFilename);

    importer.setPreserveAllTags(true);// w w w . ja  v  a2 s  .com
    importer.setPreserveReadName(true);
    //  importer.setPropagateTargetIds(true);
    importer.execute();
    AlignmentReader reader = new AlignmentReaderImpl(outputFilename);
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry first = reader.next();

    CompactToSAMMode exporter = new CompactToSAMMode();
    final String samOutputFilename = FilenameUtils.concat(BASE_TEST_DIR, "test-sam-out.sam");

    exporter.setInputBasename(outputFilename);
    exporter.setOutput(samOutputFilename);
    exporter.setGenome("test-data/sam/test.fa");
    exporter.execute();
    FileAssert.assertEquals(new File("test-data/sam/test.sam"), new File(samOutputFilename));
}

From source file:net.sf.jvifm.ui.FileLister.java

private void updateEditItem(Text textEditor, String itemType) {
    if (!textEditor.getText().trim().equals("")) {
        TableItem item = table.getItem(currentRow);
        File currentFile = new File(FilenameUtils.concat(pwd, textEditor.getText()));
        boolean isSuccess = false;
        if (itemType.equals("file")) {
            isSuccess = true;/*  ww w.  j av a2s.c o m*/
            if (!currentFile.exists()) {
                try {
                    currentFile.createNewFile();
                } catch (IOException e) {
                    isSuccess = false;
                }
            } else {
                currentFile.setLastModified(System.currentTimeMillis());
            }

        } else if (itemType.equals("folder")) {
            isSuccess = fileModelManager.mkdir(currentFile.getPath());

        } else if (itemType.equals("rename")) {
            isSuccess = currentFile.renameTo(new File(FilenameUtils.concat(pwd, textEditor.getText().trim())));
        }

        if (isSuccess) {
            fileManager.setStatusInfo("command successed."); //$NON-NLS-1$
        } else {
            fileManager.setStatusInfo("command failed."); //$NON-NLS-1$
        }

        item.setText(0, textEditor.getText().trim());
        textEditor.dispose();
        editor.dispose();
    }
    updateStatusText();
}

From source file:com.daphne.es.showcase.excel.service.ExcelDataService.java

private String generateFilename(final User user, final String contextRootPath, Integer index,
        final String extension) {
    String path = FilenameUtils.concat(contextRootPath, storePath);
    path = FilenameUtils.concat(path, user.getUsername());
    path = FilenameUtils.concat(path,//from  ww w  .  j  av  a 2s .c o m
            EXPORT_FILENAME_PREFIX + "_" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmssSSS")
                    + (index != null ? ("_" + index) : "") + "." + extension);

    File file = new File(path);
    if (!file.exists()) {
        File parentFile = file.getParentFile();
        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }
        return path;
    }
    return generateFilename(user, contextRootPath, extension);
}

From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java

@Test
// Failed on server when converting back to BAM because query_aligned_length and target_aligned_length differ
// without an apparent indel
public void testSamToCompactTrickCase16() throws IOException {

    SAMToCompactMode importer = new SAMToCompactMode();
    importer.setInputFile("test-data/splicedsamhelper/tricky-spliced-16.sam");
    final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-16");
    importer.setOutputFile(outputFilename);
    importer.setPreserveSoftClips(true);
    //  importer.setPropagateTargetIds(true);
    importer.execute();//from   w  w  w.j a  v a2 s . c  om
    // cigar is  13S21M1I29M4S   13 21 -1 29 4
    AlignmentReader reader = new AlignmentReaderImpl(outputFilename);
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry first = reader.next();
    assertTrue(reader.hasNext());
    Alignments.AlignmentEntry second = reader.next();
    assertFalse(reader.hasNext());

    assertEquals(190077 - 1, first.getPosition());
    assertEquals(13, first.getQueryPosition());
    assertEquals("AGTGGCAGCACGA", first.getSoftClippedBasesLeft());
    assertEquals("TGCT", first.getSoftClippedBasesRight());
    assertEquals(51, first.getQueryAlignedLength());
    assertEquals(50, first.getTargetAlignedLength());

    assertEquals(5, first.getSequenceVariationsCount());

    Alignments.SequenceVariation seqvar = first.getSequenceVariations(0);
    assertEquals("T", seqvar.getFrom());
    assertEquals("C", seqvar.getTo());
    assertEquals(22, seqvar.getReadIndex());
    assertEquals(9, seqvar.getPosition());
    assertArrayEquals(byteArray(3), seqvar.getToQuality().toByteArray());

    seqvar = first.getSequenceVariations(1);
    assertEquals("T", seqvar.getFrom());
    assertEquals("G", seqvar.getTo());
    assertEquals(26, seqvar.getReadIndex());
    assertEquals(13, seqvar.getPosition());
    assertArrayEquals(byteArray(34), seqvar.getToQuality().toByteArray());

    seqvar = first.getSequenceVariations(2);
    assertEquals("C", seqvar.getFrom());
    assertEquals("A", seqvar.getTo());
    assertEquals(33, seqvar.getReadIndex());
    assertEquals(20, seqvar.getPosition());
    assertArrayEquals(byteArray(28), seqvar.getToQuality().toByteArray());

    seqvar = first.getSequenceVariations(3);
    assertEquals("-", seqvar.getFrom());
    assertEquals("C", seqvar.getTo());
    assertEquals(35, seqvar.getReadIndex());
    assertEquals(21, seqvar.getPosition());
    assertArrayEquals(byteArray(27), seqvar.getToQuality().toByteArray());

    seqvar = first.getSequenceVariations(4);
    assertEquals("T", seqvar.getFrom());
    assertEquals("A", seqvar.getTo());
    assertEquals(36, seqvar.getReadIndex());
    assertEquals(22, seqvar.getPosition());
    assertArrayEquals(byteArray(35), seqvar.getToQuality().toByteArray());

    //second's CIGAR is 20S48M
    assertEquals(190246 - 1, second.getPosition());
    assertEquals(20, second.getQueryPosition());
    assertEquals("CAGTGTCGTGGCTGCACGCC", second.getSoftClippedBasesLeft());
    assertEquals("", second.getSoftClippedBasesRight());
    assertEquals(48, second.getQueryAlignedLength());
    assertEquals(48, second.getTargetAlignedLength());

}