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.github.bjoern2.codegen.JavaFileWriter.java

public void write(JavaFile javaFile) throws IOException {
    javaFile.setPackage(basePackage);//from   w w  w.  j a  v  a 2  s.  co m

    String packagePath = basePackage.replace(".", "/");
    String filename = javaFile.getDefinition().getName() + ".java";

    String pathname = FilenameUtils.concat(basePath, packagePath);
    File dir = new File(pathname);

    String fullpathname = FilenameUtils.concat(pathname, filename);
    File file = new File(fullpathname);

    dir.mkdirs();

    StringGenerator generator = new StringGenerator();
    javaFile.write(0, generator);

    FileUtils.write(file, generator.toString());
}

From source file:net.sf.jvifm.control.MkdirCommand.java

@Override
public void execute() throws Exception {

    String[] filenames = cmdLine.getArgs();
    for (int i = 0; i < filenames.length; i++) {
        String dirName = FilenameUtils.concat(pwd, filenames[i]);
        fileModelManager.mkdir(dirName);
    }//  w ww  .ja  v  a  2 s.c o m
    return;

}

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

@Test
public void testSampleToDist() throws Exception {

    runConfor();//from   ww  w.j  ava 2  s . c om

    String expectedDItemsFilename = FilenameUtils.concat(_samplePath, "expected_results/ditems");
    BinaryKeyFile expectedDItems = new BinaryKeyFile(expectedDItemsFilename, BinFileMode.FM_READONLY);
    String actualDItemsFilename = FilenameUtils.concat(_samplePath, "ditems");
    BinaryKeyFile ditems = new BinaryKeyFile(actualDItemsFilename, BinFileMode.FM_READONLY);

    List<Integer> header = expectedDItems.readIntegerList(1, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
    ItemsFileHeader itemsHeader = new ItemsFileHeader();
    itemsHeader.fromInts(header);
    int numRecords = expectedDItems.getLength() / BinaryKeyFile.RECORD_LENGTH_BYTES;

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

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

        List<Integer> expectedRecord = expectedDItems.readIntegerList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
        List<Integer> actualRecord = ditems.readIntegerList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
        System.out.println(expectedRecord);
        System.out.println(actualRecord);
        // header
        if (i == 1) {
            for (int j = 0; j < expectedRecord.size(); j++) {
                // The length of the heading is different as the date format
                // is different.
                if (j != 7 && j != 8) {
                    assertEquals(expectedRecord.get(j), actualRecord.get(j));
                } else if (j == 8) {
                    headerRecord = expectedRecord.get(j);
                }
            }
        } else if (i != headerRecord) {

            for (int j = 0; j < expectedRecord.size(); j++) {
                int expectedBits = expectedRecord.get(j);
                String bitsString = toBitString(expectedBits);
                System.out.print(bitsString + " ");
            }
            System.out.println();

            for (int j = 0; j < actualRecord.size(); j++) {
                int actualBits = actualRecord.get(j);
                String bitsString = toBitString(actualBits);
                System.out.print(bitsString + " ");
            }
            System.out.println();
            System.out.println("Expected as string: ");
            char[] chars = expectedDItems.readString(i, BinaryKeyFile.RECORD_LENGTH_BYTES).toCharArray();
            for (int c = 0; c < chars.length; c++) {
                System.out.print(chars[c]);
            }
            System.out.println();
            char[] actualchars = ditems.readString(i, BinaryKeyFile.RECORD_LENGTH_BYTES).toCharArray();
            for (int c = 0; c < actualchars.length; c++) {
                System.out.print(actualchars[c]);
            }
            System.out.println();
            List<Float> expectedFloats = expectedDItems.readFloatList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
            System.out.println(expectedFloats);
            List<Float> actualFloats = ditems.readFloatList(i, BinaryKeyFile.RECORD_LENGTH_INTEGERS);
            System.out.println(actualFloats);

            System.out.println();

            assertEquals(expectedRecord, actualRecord);
        }
    }
}

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

@Before
public void setUp() throws Exception {
    File directory = urlToFile("/dataset/");
    File dest = new File(System.getProperty("java.io.tmpdir"));
    FileUtils.copyDirectory(directory, dest);

    _samplePath = FilenameUtils.concat(dest.getAbsolutePath(), getDataSet());
    _directivesFilePath = FilenameUtils.concat(_samplePath, directivesFileName());

}

From source file:au.org.ala.delta.delfor.DelforTest.java

@Test
public void testDELFORWithSample() throws Exception {
    String path = FilenameUtils.concat(_path, "sample");

    runDELFOR(FilenameUtils.concat(path, "reorder"));

    String[] files = { "specs", "chars", "items", "cimages", "cnotes", "empchari", "empcharm", "headc",
            "layout", "summary", "toali", "todis", "tohen", "toint", "tokey", "tonex", "topau", "topay", "key4",
            "key6", "intkey.ini" };

    for (String file : files) {
        checkResults(path, file + ".new");
    }// ww w.  j  ava2 s. co m
}

From source file:dataflow.docker.HostMountedPath.java

/**
 * Return a new path by appending name to both the host and container paths.
 *
 * @param name/*from   w ww .  j  a v  a 2s. co m*/
 * @return
 */
public HostMountedPath append(String name) {
    return new HostMountedPath(FilenameUtils.concat(hostPath, name), FilenameUtils.concat(containerPath, name));
}

From source file:au.org.ala.delta.dist.DISTTest.java

@Test
public void testDISTWithSample() throws Exception {
    String path = FilenameUtils.concat(_path, "sample");

    runDIST(FilenameUtils.concat(path, "dist"));
    checkResults(path, "grass.nam", false);
    checkResults(path, "grass.dis", true);
}

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

/**
 * Because of ISSUE 66 the output from the original CONFOR has been
 * modified by chaning some inappicables to unknowns (and vice versa) 
 * to allow this test to be run as a part of the build.
 */// ww w  . java 2  s  . co m
@Test
public void testSampleToNex() throws Exception {
    runConfor();

    File expectedFile = new File(FilenameUtils.concat(_samplePath, "expected_results/nexdata"));
    String expected = FileUtils.readFileToString(expectedFile, "utf-8");

    System.out.println(expected);

    File actualFile = new File(FilenameUtils.concat(_samplePath, "nexdata"));
    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"));
    }
    // The heading contains the date so will be different.
    String heading = "Grass Genera 14:43 20-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;
        }
    }
    BufferedReader expectedReader = new BufferedReader(new StringReader(expected));
    BufferedReader actualReader = new BufferedReader(new StringReader(actual));
    String expectedLine = expectedReader.readLine();
    String actualLine = actualReader.readLine();
    /*while (expectedLine != null) {
       assertEquals(expectedLine.trim(), actualLine.trim());
       expectedLine = expectedReader.readLine();
       actualLine = actualReader.readLine();
               
    }*/

    assertEquals(expected.trim(), actual.trim());
}

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

/**
 * Lock the provided folder pLocalFolder. At first, the current operating
 * system is checked for beeing a Unix based system. In this case, a dedicated
 * script will be used for locking. In all other cases or if the script-based
 * approach fails, a single file '.locked' is created inside pLocalFolder.
 *
 * @param pFolder The folder to lock (must be a directory)
 *
 * @return TRUE on success, FALSE on any error
 *///from w  w w . ja v a  2  s.  c o m
public static boolean lockFolder(File pFolder) {
    if (!pFolder.isDirectory()) {
        LOGGER.error("Provided argument 'pLocalFolder' ({}) must be a directory", pFolder);
        return false;
    }

    if (org.apache.commons.lang3.SystemUtils.IS_OS_UNIX && lockFolderUnix(pFolder)) {
        return true;
    } //else...fallback using '.locked' file

    File lockFile = new File(FilenameUtils.concat(pFolder.getAbsolutePath(), ".locked"));
    try {
        LOGGER.debug("Try to create lock '{}'", lockFile);
        FileUtils.touch(lockFile);
    } catch (IOException ioe) {
        LOGGER.error("Failed to lock folder '" + pFolder.getAbsolutePath() + "'", ioe);
        return false;
    }

    return true;
}

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

@Test
public void testSampleToNatWithOmitFinalComma() throws Exception {
    String directivesFileName = "tonat_omitfinalcomma";
    _directivesFilePath = FilenameUtils.concat(_samplePath, directivesFileName);
    String resultFileName = "tonat_omitfinalcomma.prt";

    runAndTest(resultFileName);/*  w  w  w  .jav a 2  s .  c  o  m*/
}