Java Directory Clean cleanPath(String loc)

Here you can find the source of cleanPath(String loc)

Description

clean Path

License

Open Source License

Declaration

public static String cleanPath(String loc) 

Method Source Code


//package com.java2s;
/*//from w w w .  j  a v  a 2s . c o  m
 * Copyright (c) 2012 Diamond Light Source Ltd.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.io.File;
import java.util.Locale;

public class Main {
    public static String cleanPath(String loc) {

        // Remove reference:file: from the start. TODO find a better way,
        // and test that this works on windows (it might have ///)
        if (loc.startsWith("reference:file:")) {
            loc = loc.substring(15);
        } else if (loc.startsWith("file:")) {
            loc = loc.substring(5);
        } else {
            return loc;
        }

        loc = loc.replace("//", "/");
        loc = loc.replace("\\\\", "\\");

        boolean isWindows = System.getProperty("os.name").toUpperCase(Locale.ENGLISH).contains("WINDOWS")
                && (File.separatorChar == '\\');

        if (isWindows && loc.startsWith("/")) {
            loc = loc.substring(1);
        }

        return loc;
    }
}

Related

  1. cleanDir(final String luceneDir)
  2. cleanDir(String dir)
  3. cleanDir(String directory)
  4. cleanDir(String path)
  5. cleanDirectory(File currentDir)
  6. cleanPath(String path)
  7. cleanPaths(String root, String rel, String name)
  8. clearDir(File dir, boolean clearsubdirs)
  9. clearDir(String dirPath)