Java Utililty Methods Path Normalize

List of utility methods to do Path Normalize

Description

The list of methods to do Path Normalize are organized into topic(s).

Method

StringnormalizePath(String path)
Normalize path removing ".."
if (path.length() == 0 || path.equals("/")) {
    return path;
StringBuilder rc = new StringBuilder();
String[] pc = path.split("/");
int count = 0;
int startBacks = 0;
int[] pci = new int[pc.length];
...
StringnormalizePath(String path)
normalize Path
return normalizePath(path, false);
StringnormalizePath(String path)
normalize Path
return path.endsWith(FORWARD_SLASH) ? path.substring(0, path.length() - 1) : path;
StringnormalizePath(String path)
normalize Path
char[] array = path.toCharArray();
StringBuffer sb = new StringBuffer();
boolean skipNextPathChar = false;
int idx = 0;
for (int i = 0; i < array.length; i++) {
    char c = array[i];
    boolean isPathChar = isPathChar(c);
    if (isPathChar) {
...
StringnormalizePath(String path)
normalize Path
assert path != null;
StringBuilder buf = new StringBuilder();
int offset = 0;
for (int i = 0, n = path.length(); i < n; i++) {
    if (path.charAt(i) == '/') {
        offset = i + 1;
    } else {
        break;
...
StringnormalizePath(String path)
normalize / to \ and remove trailing slashes from a path
if (path == null)
    return path;
String normalizedPath = path.replaceAll("\\\\", FILE_SEPARATOR);
while (normalizedPath.endsWith("\\") || normalizedPath.endsWith(FILE_SEPARATOR)) {
    normalizedPath = normalizedPath.substring(0, normalizedPath.length() - 1);
return normalizedPath;
StringnormalizePath(String path)
normalize Path
String[] comps = path.split("/");
String[] ap = new String[comps.length];
int j = 0;
boolean absolute = comps[0].length() == 0;
for (int i = 0; i < comps.length; ++i) {
    String s = comps[i];
    if (s.equals(".") || s.length() == 0)
        continue;
...
StringnormalizePath(String path)
normalize Path
int len = path.length();
if (len == 0 || path.equals("..") || path.equals(".")) {
    return "";
if (path.indexOf("/. ") < 0 && path.indexOf("./ ") < 0) {
    return path;
StringBuilder builder = new StringBuilder();
...
StringnormalizePath(String path)
normalize Path
String normalizedPath = removeTrailingSlashes(removeLeadingSlashes(nullToEmpty(path)));
return normalizedPath.isEmpty() ? "" : "/" + normalizedPath;
StringnormalizePath(String path)
normalize Path
if (path.indexOf("~") >= 0) {
    String usr = System.getProperty("user.name");
    String tild = "/Users/" + usr;
    path = path.replace("~", tild);
path = path.replace("\\", "\\\\\\\\");
return path;