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:au.org.ala.delta.confor.FillinTest.java

protected void runAndTest(String resultFileName) throws Exception, IOException {
    runConfor();//from   w  w  w  . java2 s  . c om

    File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/" + resultFileName));
    String expected = FileUtils.readFileToString(expectedFile, "cp1252");

    System.out.println(expected);

    File actualFile = new File(FilenameUtils.concat(_samplePath, resultFileName));
    String actual = FileUtils.readFileToString(actualFile, "cp1252");

    System.out.print(actual);

    boolean dosEol = expected.contains("\r\n");
    String expectedLineSeparator = "\n";
    if (dosEol) {
        expectedLineSeparator = "\r\n";
    }

    if (!System.getProperty("line.separator").equals(expectedLineSeparator)) {
        expected = expected.replaceAll(expectedLineSeparator, System.getProperty("line.separator"));
    }

    // CONFOR leaves a lot of trailing spaces around
    expected = expected.replaceAll(" ([\\r\\n]+)", "$1");
    actual = actual.replaceAll(" ([\\r\\n]+)", "$1");

    // The heading contains the date so will be different.
    String heading = "Grass Genera 13:32 12-OCT-11"; // <Date>, eg. 11:32 05-OCT-11

    actual = actual.replaceAll("Grass Genera.*[0-9]{2}-[a-zA-Z]{3}-[0-9]{4}", heading);

    for (int i = 0; i < expected.length(); i++) {
        if (expected.charAt(i) != actual.charAt(i)) {
            System.out.println("Difference @ char: " + i + " Expected: " + expected.charAt(i)
                    + (int) expected.charAt(i) + ", Actual: " + actual.charAt(i) + (int) actual.charAt(i));
            break;
        }
    }
    assertEquals(expected.trim(), actual.trim());
}

From source file:info.balajeerc.spellspider.PageChecker.java

private PageChecker(OutputQueue outputQueue) {
    languageTool = null;//from  w ww .  jav a2 s  . co  m
    this.outputQueue = outputQueue;
    outputFilePath = FilenameUtils.concat(outputQueue.getOutputDirectory(), "errors.csv");
    try {
        languageTool = new JLanguageTool(Language.AMERICAN_ENGLISH);
        languageTool.activateDefaultPatternRules();
        //Write the header for the output file
        FileWriter outFile = new FileWriter(outputFilePath);
        outFile.write("Url, Description, In Text, Error, Category\n");
        outFile.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:au.org.ala.delta.confor.ErrorsTest.java

protected void runAndTest(String path, String directivesFile, String... resultFileName)
        throws Exception, IOException {

    String directivesFileFullPath = FilenameUtils.concat(path, directivesFile);
    CONFOR.main(new String[] { directivesFileFullPath });

    for (String name : resultFileName) {
        File expectedFile = new File(
                FilenameUtils.concat(FilenameUtils.concat(path, "expected_results"), name));
        String expected = FileUtils.readFileToString(expectedFile, "cp1252");

        System.out.println(expected);

        File actualFile = new File(FilenameUtils.concat(path, name));
        String actual = FileUtils.readFileToString(actualFile, "cp1252");

        System.out.print(actual);

        boolean dosEol = expected.contains("\r\n");
        String expectedLineSeparator = "\n";
        if (dosEol) {
            expectedLineSeparator = "\r\n";
        }//from ww w  .j  a  v  a 2 s. c o  m

        if (!System.getProperty("line.separator").equals(expectedLineSeparator)) {
            expected = expected.replaceAll(expectedLineSeparator, System.getProperty("line.separator"));
        }

        String expectedFilePathSeparator = "/";
        if (!File.separator.equals(expectedFilePathSeparator)) {
            expected = expected.replaceAll(expectedFilePathSeparator, "\\\\");
        }

        for (int i = 0; i < expected.length(); i++) {
            if (expected.charAt(i) != actual.charAt(i)) {
                System.out.println("Difference @ char: " + i + " Expected: " + expected.charAt(i)
                        + (int) expected.charAt(i) + ", Actual: " + actual.charAt(i) + (int) actual.charAt(i));
                break;
            }
        }
        assertEquals(expected.trim(), actual.trim());
    }
}

From source file:au.org.ala.delta.confor.ToKeyTest.java

@Test
public void testSampleToKey() throws Exception {

    File tointDirectory = urlToFile("/dataset/");
    File dest = new File(System.getProperty("java.io.tmpdir"));
    FileUtils.copyDirectory(tointDirectory, dest);

    String tokeyFilePath = FilenameUtils.concat(dest.getAbsolutePath(), "sample/tokey");

    CONFOR.main(new String[] { tokeyFilePath });

    String expectedKCharsFilename = FilenameUtils.concat(dest.getAbsolutePath(),
            "sample/expected_results/kchars");
    String expectedKItemsFilename = FilenameUtils.concat(dest.getAbsolutePath(),
            "sample/expected_results/kitems");

    BinaryKeyFile expectedKChars = new BinaryKeyFile(expectedKCharsFilename, BinFileMode.FM_READONLY);
    BinaryKeyFile expectedKItems = new BinaryKeyFile(expectedKItemsFilename, BinFileMode.FM_READONLY);

    String actualKCharsFilename = FilenameUtils.concat(dest.getAbsolutePath(), "sample/kchars");
    String actualKItemsFilename = FilenameUtils.concat(dest.getAbsolutePath(), "sample/kitems");

    BinaryKeyFile kchars = new BinaryKeyFile(actualKCharsFilename, BinFileMode.FM_READONLY);
    BinaryKeyFile kitems = new BinaryKeyFile(actualKItemsFilename, BinFileMode.FM_READONLY);

    int numRecords = expectedKChars.getLength() / BinaryKeyFile.RECORD_LENGTH_BYTES;
    int actualNumRecords = kchars.getLength() / BinaryKeyFile.RECORD_LENGTH_BYTES;

    int count = Math.min(numRecords, actualNumRecords);

    for (int i = 1; i <= count; i++) {
        List<Integer> expectedRecord = expectedKChars.readIntegerList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
        List<Integer> actualRecord = kchars.readIntegerList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS);

        System.out.println("Record: " + i);
        System.out.println(expectedRecord);
        System.out.println(actualRecord);

        System.out.println("Expected as string: ");
        System.out.println(expectedKChars.readString(i, BinaryKeyFile.RECORD_LENGTH_BYTES));

        System.out.println();//ww w  . j  av a 2 s.  c  o m
        assertEquals(expectedRecord, actualRecord);

    }

    numRecords = expectedKItems.getLength() / BinaryKeyFile.RECORD_LENGTH_BYTES;
    System.out.println("**** Items File (" + numRecords + ")*****");

    List<Integer> header = expectedKItems.readIntegerList(1, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
    ItemsFileHeader itemsHeader = new ItemsFileHeader();
    itemsHeader.fromInts(header);

    for (int i = 1; i < numRecords; i++) {

        System.out.println("Record: " + i);

        if ((i >= itemsHeader.getCharcterReliabilitiesRecord() && i < itemsHeader.getTaxonMaskRecord())
                || i >= itemsHeader.getItemAbundancesRecord()) {
            List<Float> expectedFloats = expectedKItems.readFloatList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
            List<Float> actualFloats = kitems.readFloatList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
            System.out.println(expectedFloats);
            System.out.println(actualFloats);

            for (int f = 0; f < expectedFloats.size(); f++) {
                // Note sure if this is a difference in encoding or precision
                // but our floats are quite different.
                assertEquals(expectedFloats.get(f), actualFloats.get(f), 0.021f);
            }
        } else if (i >= itemsHeader.getHeadingRecord() && i < itemsHeader.getCharacterMaskRecord()) {
            // The header has the date in it so will be different.
        } else {
            List<Integer> expectedRecord = expectedKItems.readIntegerList(i,
                    BinaryKeyFile.RECORD_LENGTH_INTEGERS);
            List<Integer> actualRecord = kitems.readIntegerList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
            System.out.println(expectedRecord);
            System.out.println(actualRecord);

            System.out.println("Expected as string: ");
            char[] chars = expectedKItems.readString(i, BinaryKeyFile.RECORD_LENGTH_BYTES).toCharArray();
            for (int c = 0; c < chars.length; c++) {
                System.out.print(chars[c]);
            }
            if (i != 1) {
                assertEquals(expectedRecord, actualRecord);
            }
        }
        System.out.println();

        char[] actualChars = kitems.readString(i, BinaryKeyFile.RECORD_LENGTH_BYTES).toCharArray();
        for (int c = 0; c < actualChars.length; c++) {
            System.out.print(actualChars[c]);
        }
        System.out.println();

        System.out.println();
    }

}

From source file:de.thomasvolk.genexample.bericht.templates.Template.java

protected String getTargetPath(String zielPfad, String name) {
    return FilenameUtils.concat(zielPfad, name);
}

From source file:net.bpelunit.framework.base.BPELUnitBaseRunner.java

@Override
public void configureExtensions() throws ConfigurationException {
    String extensionsFile = FilenameUtils.concat(fHomeDirectory,
            FilenameUtils.concat(CONFIG_DIR, EXTENSIONS_FILE_NAME));

    if ((extensionsFile != null) && (new File(extensionsFile).exists())) {
        try {//from   ww w .  j  a  v a2  s .co m
            ExtensionRegistry.loadRegistry(new File(extensionsFile).toURI().toURL(), isSkipUnknownExtensions());
        } catch (MalformedURLException e) {
            throw new ConfigurationException("BPELUnit could not locate the extension file: " + extensionsFile,
                    e);
        }
    } else {
        // if file could not be loaded, default to embedded settings
        ExtensionRegistry.loadRegistry(
                this.getClass().getResource('/' + CONFIG_DIR + '/' + EXTENSIONS_FILE_NAME),
                isSkipUnknownExtensions());
    }
}

From source file:cop.maven.plugins.RamlMojoIT.java

private static File getResourceFile(String name) {
    return new File(FilenameUtils.concat("src/it/resource", name)).getAbsoluteFile();
}

From source file:au.org.ala.delta.confor.ToNatHTest.java

private void testFile(String fileName, String outputPath) throws IOException {
    File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/" + fileName));
    String expected = FileUtils.readFileToString(expectedFile, "cp1252");

    System.out.println(expected);

    File actualFile = new File(FilenameUtils.concat(_samplePath, outputPath + fileName));
    String actual = FileUtils.readFileToString(actualFile, "cp1252");

    System.out.print(actual);//from  w w w . j a va2 s. c  o m

    boolean dosEol = expected.contains("\r\n");
    String expectedLineSeparator = "\n";
    if (dosEol) {
        expectedLineSeparator = "\r\n";
    }

    if (!System.getProperty("line.separator").equals(expectedLineSeparator)) {
        expected = expected.replaceAll(expectedLineSeparator, System.getProperty("line.separator"));
        //actual = actual.replaceAll(expectedLineSeparator, System.getProperty("line.separator"));
    }
    // The heading contains the date so will be different.

    for (int i = 0; i < expected.length(); i++) {
        if (expected.charAt(i) != actual.charAt(i)) {
            System.out.println("Difference @ char: " + i + " Expected: " + expected.charAt(i)
                    + (int) expected.charAt(i) + ", Actual: " + actual.charAt(i) + (int) actual.charAt(i));
            break;
        }
    }
    //assertEquals(expected, actual);
}

From source file:edu.cornell.med.icb.goby.alignments.TestSpliceSites.java

@Test
/**//from ww  w.j  ava2s. c om
 * Make a synthetic alignment with one read that spans a splice site:
 */
public void writeSplicedTestAlignment() throws IOException {
    final String basename = "spliced-1";
    final AlignmentWriterImpl writer = new AlignmentWriterImpl(FilenameUtils.concat(BASE_TEST_DIR, basename));
    writer.setNumAlignmentEntriesPerChunk(numEntriesPerChunk);

    final int numTargets = 1;
    final int[] targetLengths = new int[numTargets];

    for (int referenceIndex = 0; referenceIndex < numTargets; referenceIndex++) {
        targetLengths[referenceIndex] = 110;
    }
    writer.setTargetLengths(targetLengths);
    // we write this alignment sorted:
    IndexedIdentifier ids = new IndexedIdentifier();
    ids.registerIdentifier(new MutableString("synth1"));
    writer.setTargetIdentifiers(ids);
    writer.setSorted(true);

    Alignments.SequenceVariation mutation = Alignments.SequenceVariation.newBuilder().setFrom("T").setTo("A")
            .setPosition(10).setReadIndex(10).build();
    Alignments.RelatedAlignmentEntry linkForward = Alignments.RelatedAlignmentEntry.newBuilder()
            .setFragmentIndex(1).setPosition(70).setTargetIndex(0).build();

    Alignments.RelatedAlignmentEntry linkBackward = Alignments.RelatedAlignmentEntry.newBuilder()
            .setFragmentIndex(0).setPosition(10).setTargetIndex(0).build();
    Alignments.AlignmentEntry entry1 = Alignments.AlignmentEntry.newBuilder().setPosition(10)
            .setMatchingReverseStrand(false).setQueryLength(50).setQueryIndex(0).setTargetIndex(0)
            .setFragmentIndex(0).setSplicedForwardAlignmentLink(linkForward).setQueryAlignedLength(20)
            .addSequenceVariations(mutation).setMappingQuality(255).setScore(20).build();
    Alignments.AlignmentEntry entry2 = Alignments.AlignmentEntry.newBuilder().setPosition(70)
            .setMatchingReverseStrand(false).setQueryLength(50).setQueryIndex(0).setTargetIndex(0)
            .setFragmentIndex(1).setSplicedBackwardAlignmentLink(linkBackward).setQueryAlignedLength(30)
            .setMappingQuality(255).setScore(30).build();

    writer.appendEntry(entry1);
    writer.appendEntry(entry2);

    // now write on the reverse strand:
    mutation = Alignments.SequenceVariation.newBuilder().setFrom("T").setTo("A").setPosition(10)
            .setReadIndex(10).build();
    linkForward = Alignments.RelatedAlignmentEntry.newBuilder().setFragmentIndex(0).setPosition(70)
            .setTargetIndex(0).build();

    linkBackward = Alignments.RelatedAlignmentEntry.newBuilder().setFragmentIndex(1).setPosition(10)
            .setTargetIndex(0).build();
    entry1 = Alignments.AlignmentEntry.newBuilder().setPosition(10).setMatchingReverseStrand(true)
            .setQueryLength(50).setQueryIndex(1).setTargetIndex(0).setFragmentIndex(1)
            .setSplicedForwardAlignmentLink(linkForward).setQueryAlignedLength(20)
            .addSequenceVariations(mutation).setMappingQuality(255).setScore(20).build();
    entry2 = Alignments.AlignmentEntry.newBuilder().setPosition(70).setMatchingReverseStrand(true)
            .setQueryLength(50).setQueryIndex(1).setTargetIndex(0).setFragmentIndex(0)
            .setSplicedBackwardAlignmentLink(linkBackward).setQueryAlignedLength(30).setMappingQuality(255)
            .setScore(30).build();
    writer.appendEntry(entry1);
    writer.appendEntry(entry2);

    writer.close();
    System.out.println();
}

From source file:com.mbrlabs.mundus.core.registry.Registry.java

public FileHandle createTempFolder() {
    String tempFolderPath = FilenameUtils.concat(TEMP_DIR, UUID.randomUUID().toString()) + "/";
    FileHandle tempFolder = Gdx.files.absolute(tempFolderPath);
    tempFolder.mkdirs();//from ww w.j a  v a 2s.  c om

    return tempFolder;
}