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

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

Introduction

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

Prototype

public static String separatorsToSystem(String path) 

Source Link

Document

Converts all separators to the system separator.

Usage

From source file:edu.ur.file.db.TreeFolderInfo.java

/**
 * Set the path of the folder. This makes no changes to the children
 * folders. //from w ww  .  j  ava 2s.  co m
 * 
 * 
 * This converts the paths to the correct path immediately / for unix and \
 * for windows.
 * 
 * @param path
 * @throws IllegalState Exception if the file database is equal to null.
 */
void setPath(String inPath) {

    if (fileDatabase == null) {
        throw new IllegalStateException("File Database cannot be null");
    }
    if (isRoot()) {
        path = null;
    } else {
        inPath = FilenameUtils.separatorsToSystem(inPath.trim());

        // add the end seperator
        if (inPath.charAt(inPath.length() - 1) != IOUtils.DIR_SEPARATOR) {
            inPath = inPath + IOUtils.DIR_SEPARATOR;
        }

        // verify the path is valid if this has any parents.
        if (!verifyPath(inPath)) {
            throw new IllegalArgumentException("inPath is : " + inPath + " but should equal parent path "
                    + " plus parents name which = " + parent.getPath());
        }

        String basePath = fileDatabase.getFullPath();
        path = inPath.substring(basePath.length());
    }
}

From source file:S3DataManagerTest.java

@Test
public void testTrimPrefixBaseWithTrailingSlash() throws Exception {
    String prefixWithSlash = FilenameUtils.separatorsToSystem("/tmp/dir/"); // "/tmp/dir/" in Linux, "\tmp\dir\" in Windows.
    String path = FilenameUtils.separatorsToSystem("/tmp/dir/folder/file.txt");

    assertEquals(FilenameUtils.separatorsToSystem("folder/file.txt"),
            S3DataManager.trimPrefix(path, prefixWithSlash));
}

From source file:S3DataManagerTest.java

@Test
public void testGetRelativePathStringBaseDirWithoutTrailingSlash() throws Exception {
    String prefixNoSlash = FilenameUtils.separatorsToSystem("/tmp/dir"); // "/tmp/dir" in Linux, "\tmp\dir" in Windows.
    String path = FilenameUtils.separatorsToSystem("/tmp/dir/folder/file.txt");

    assertEquals(FilenameUtils.separatorsToSystem("folder/file.txt"),
            S3DataManager.trimPrefix(path, prefixNoSlash));
}

From source file:dynamicrefactoring.RefactoringPlugin.java

/**
 * Obtiene la ruta raz del "bundle" asociado al plugin.
 * /*from w ww  . jav  a  2s .c o m*/
 * La ruta termina en el smbolo separador del sistema operativo.
 * 
 * @return la ruta raz del "bundle" asociado al plugin.
 */
public String getBundleRootDir() {
    Bundle pluginBundle = Platform.getBundle(BUNDLE_NAME);

    String pluginRoot = "";

    if (pluginBundle == null) {
        pluginRoot = "." + File.separatorChar + "";
    } else {
        String pluginLocation = pluginBundle.getLocation();
        if (pluginLocation.startsWith("update@")) {
            // La localizacin tiene el formato update@directorio.
            // Hay que eliminar el primer fragmento de la localizacin.
            pluginRoot = pluginLocation.substring(pluginLocation.indexOf('@') + 1);
        } else {
            //pluginRoot = pluginLocation.substring(pluginLocation.indexOf('/') + 1);
            pluginRoot = pluginLocation.substring(pluginLocation.indexOf('/'));
        }
    }

    return FilenameUtils.separatorsToSystem(pluginRoot);
}

From source file:io.cloudslang.lang.tools.build.SlangBuildMain.java

private static String parseProjectPathArg(ApplicationArgs args) {
    String repositoryPath;//from  w  ww .j a  v a 2 s  . c o m

    if (args.getProjectRoot() != null) {
        repositoryPath = args.getProjectRoot();
        // if only one parameter was passed, we treat it as the project root
        // i.e. './cslang-builder some/path/to/project'
    } else if (args.getParameters().size() == 1) {
        repositoryPath = args.getParameters().get(0);
    } else {
        repositoryPath = System.getProperty("user.dir");
    }

    repositoryPath = FilenameUtils.separatorsToSystem(repositoryPath);

    Validate.isTrue(new File(repositoryPath).isDirectory(),
            "Directory path argument \'" + repositoryPath + "\' does not lead to a directory");

    return repositoryPath;
}

From source file:au.org.ala.delta.util.Utils.java

/**
 * Return a file object for the file at the supplied path (may be a relative
 * path)//from   w  w w  . jav a 2s. c o m
 * 
 * @param filePath
 *            the path of the file - may be a relative path
 * @param defaultDirectory
 *            the default parent directory - this directory will be used as
 *            the parent directory if the filePath is not absolute
 * @return
 */
public static File createFileFromPath(String filePath, File defaultDirectory) {
    File file = null;
    // If the supplied file path starts with one of the file system
    // roots, then it is absolute. Otherwise, assume that
    // it is relative to the directory in which the dataset is located.
    filePath = FilenameUtils.separatorsToSystem(filePath);
    boolean fileAbsolute = false;
    for (File root : File.listRoots()) {
        if (filePath.toLowerCase().startsWith(root.getAbsolutePath().toLowerCase())) {
            fileAbsolute = true;
            break;
        }
    }

    if (fileAbsolute) {
        file = new File(filePath);
    } else {
        file = new File(defaultDirectory, filePath);
    }

    return file;
}

From source file:org.apache.flex.compiler.clients.ASC.java

/**
 * Minimally modifies the directory name read from the command line to make
 * a directory name we can use to write an output file.
 * /*from ww  w  .  j a  v a2  s .  c o m*/
 * @param inputDirectoryName directory name from the command line.
 * @return Directory name that is ends with {@link File#separator}.
 */
private static String normalizeDirectoryName(String inputDirectoryName) {
    final String normalizedSeparators = FilenameUtils.separatorsToSystem(inputDirectoryName);
    if (inputDirectoryName.endsWith(File.separator))
        return normalizedSeparators;
    else
        return normalizedSeparators + File.separator;
}

From source file:org.apache.flex.compiler.internal.projects.LibraryPathManager.java

/**
 * Computes the qualified name of a properties file that is in a swc and 
 * creates a compilation unit for that.//w  w w .  jav  a  2s  .  c  o  m
 * 
 * Example: For a properties file located at
 * "locale/en_US/foo/bar/core.properties" in a swc, the qualified name is
 * computed as "foo.bar.core".
 * 
 * @param swc swc that contains the properties file
 * @param fileEntry file entry that points to the properties file in the swc
 * @return {@link ResourceBundleCompilationUnit} for the specified swc file entry.
 */
private ICompilationUnit createResourceBundleCompilationUnit(ISWC swc, ISWCFileEntry fileEntry) {
    String path = FilenameUtils.separatorsToSystem(fileEntry.getPath());
    String[] segments = Iterables.toArray(Splitter.on(File.separator).split(path), String.class);

    //the pattern used in SWC files to store resource bundles is 'locale/{locale}/..", 
    //therefore the segment count needs to be at least 2.
    if (segments.length > 2 && ResourceBundleCompilationUnit.LOCALE.equals(segments[0])) {
        StringBuilder qName = new StringBuilder();
        for (int i = 2; i < segments.length - 1; i++) {
            qName.append(segments[i]);
            qName.append('.');
        }
        qName.append(FilenameUtils.getBaseName(segments[segments.length - 1]));

        return new ResourceBundleCompilationUnit(flashProject, fileEntry, qName.toString(), segments[1]);
    }

    return null;
}

From source file:org.apache.sanselan.formats.png.PngMultipleRoundtripTest.java

public void test() throws IOException, ImageReadException, ImageWriteException {
    String imagesFolderPath = FilenameUtils.separatorsToSystem("src\\test\\data\\images\\png\\3");
    File imagesFolder = new File(imagesFolderPath);
    assertTrue(imagesFolder.exists() && imagesFolder.isDirectory());

    File files[] = imagesFolder.listFiles();
    for (int i = 0; i < files.length; i++) {
        File imageFile = files[i];
        if (!imageFile.isFile())
            continue;
        if (!imageFile.getName().toLowerCase().endsWith(".png"))
            continue;

        Debug.debug();/*from  ww  w  .j  a  v a 2 s.  c o m*/
        Debug.debug("imageFile", imageFile);

        File lastFile = imageFile;
        for (int j = 0; j < 10; j++) {
            Map readParams = new HashMap();
            // readParams.put(SanselanConstants.BUFFERED_IMAGE_FACTORY,
            // new RgbBufferedImageFactory());
            BufferedImage image = Sanselan.getBufferedImage(lastFile, readParams);
            assertNotNull(image);

            File tempFile = createTempFile(imageFile.getName() + "." + j + ".", ".png");
            Debug.debug("tempFile", tempFile);

            Map writeParams = new HashMap();
            Sanselan.writeImage(image, tempFile, ImageFormat.IMAGE_FORMAT_PNG, writeParams);

            lastFile = tempFile;
        }
    }
}

From source file:org.apache.sanselan.SanselanGuessFormatTest.java

public void testGuess(ImageFormat expectedFormat, String imagePath) throws IOException, ImageReadException {
    imagePath = FilenameUtils.separatorsToSystem(imagePath);
    File imageFile = new File(TEST_IMAGE_FOLDER, imagePath);

    assertTrue(imageFile.exists());//from  w  ww . j  av  a  2s  . c  om
    assertTrue(imageFile.isFile());
    ImageFormat guessedFormat = Sanselan.guessFormat(imageFile);
    assertNotNull(guessedFormat);
    assertEquals(guessedFormat, expectedFormat);
}