private static int startPositionWithoutWindowsDrive(String path) { if (hasWindowsDrive(path)) { return path.charAt(0) == SEPARATOR_CHAR ? 3 : 2; } else { return 0; } }
@Override public String toString() { // we can't use uri.toString(), which escapes everything, because we want // illegal characters unescaped in the string, for glob processing, etc. StringBuilder buffer = new StringBuilder(); if (uri.getScheme() != null) { buffer.append(uri.getScheme()); buffer.append(":"); } if (uri.getAuthority() != null) { buffer.append("//"); buffer.append(uri.getAuthority()); } if (uri.getPath() != null) { String path = uri.getPath(); if (path.indexOf('/')==0 && hasWindowsDrive(path) && // has windows drive uri.getScheme() == null && // but no scheme uri.getAuthority() == null) // or authority path = path.substring(1); // remove slash before drive buffer.append(path); } if (uri.getFragment() != null) { buffer.append("#"); buffer.append(uri.getFragment()); } return buffer.toString(); }
/** * Normalize a path string to use non-duplicated forward slashes as * the path separator and remove any trailing path separators. * * @param scheme the URI scheme. Used to deduce whether we * should replace backslashes or not * @param path the scheme-specific part * @return the normalized path string */ private static String normalizePath(String scheme, String path) { // Remove double forward slashes. path = StringUtils.replace(path, "//", "/"); // Remove backslashes if this looks like a Windows path. Avoid // the substitution if it looks like a non-local URI. if (WINDOWS && (hasWindowsDrive(path) || (scheme == null) || (scheme.isEmpty()) || (scheme.equals("file")))) { path = StringUtils.replace(path, "\\", "/"); } // trim trailing slash from non-root path (ignoring windows drive) int minLength = startPositionWithoutWindowsDrive(path) + 1; if (path.length() > minLength && path.endsWith(SEPARATOR)) { path = path.substring(0, path.length()-1); } return path; }
/** * Construct a Path from components. * * @param scheme the scheme * @param authority the authority * @param path the path */ public Path(String scheme, String authority, String path) { checkPathArg( path ); // add a slash in front of paths with Windows drive letters if (hasWindowsDrive(path) && path.charAt(0) != '/') { path = "/" + path; } // add "./" in front of Linux relative paths so that a path containing // a colon e.q. "a:b" will not be interpreted as scheme "a". if (!WINDOWS && path.charAt(0) != '/') { path = "./" + path; } initialize(scheme, authority, path, null); }
if (hasWindowsDrive(pathString) && pathString.charAt(0) != '/') { pathString = "/" + pathString;
private static int startPositionWithoutWindowsDrive(String path) { if (hasWindowsDrive(path)) { return path.charAt(0) == SEPARATOR_CHAR ? 3 : 2; } else { return 0; } }
private static int startPositionWithoutWindowsDrive(String path) { if (hasWindowsDrive(path)) { return path.charAt(0) == SEPARATOR_CHAR ? 3 : 2; } else { return 0; } }
private static int startPositionWithoutWindowsDrive(String path) { if (hasWindowsDrive(path)) { return path.charAt(0) == SEPARATOR_CHAR ? 3 : 2; } else { return 0; } }
private static int startPositionWithoutWindowsDrive(String path) { if (hasWindowsDrive(path)) { return path.charAt(0) == SEPARATOR_CHAR ? 3 : 2; } else { return 0; } }
/** True if the directory of this path is absolute. */ public boolean isAbsolute() { int start = hasWindowsDrive(uri.getPath(), true) ? 3 : 0; return uri.getPath().startsWith(SEPARATOR, start); }
/** True if the directory of this path is absolute. */ public boolean isAbsolute() { int start = hasWindowsDrive(uri.getPath(), true) ? 3 : 0; return uri.getPath().startsWith(SEPARATOR, start); }
private String normalizePath(String path) { // remove double slashes & backslashes path = path.replace("//", "/"); path = path.replace("\\", "/"); // trim trailing slash from non-root path (ignoring windows drive) int minLength = hasWindowsDrive(path, true) ? 4 : 1; if (path.length() > minLength && path.endsWith("/")) { path = path.substring(0, path.length()-1); } return path; }
private String normalizePath(String path) { // remove double slashes & backslashes path = path.replace("//", "/"); path = path.replace("\\", "/"); // trim trailing slash from non-root path (ignoring windows drive) int minLength = hasWindowsDrive(path, true) ? 4 : 1; if (path.length() > minLength && path.endsWith("/")) { path = path.substring(0, path.length()-1); } return path; }
/** Returns the parent of a path or null if at root. */ public Path getParent() { String path = uri.getPath(); int lastSlash = path.lastIndexOf('/'); int start = hasWindowsDrive(path, true) ? 3 : 0; if ((path.length() == start) || // empty path (lastSlash == start && path.length() == start+1)) { // at root return null; } String parent; if (lastSlash==-1) { parent = CUR_DIR; } else { int end = hasWindowsDrive(path, true) ? 3 : 0; parent = path.substring(0, lastSlash==end?end+1:lastSlash); } return new Path(uri.getScheme(), uri.getAuthority(), parent); }
/** Returns the parent of a path or null if at root. */ public Path getParent() { String path = uri.getPath(); int lastSlash = path.lastIndexOf('/'); int start = hasWindowsDrive(path, true) ? 3 : 0; if ((path.length() == start) || // empty path (lastSlash == start && path.length() == start+1)) { // at root return null; } String parent; if (lastSlash==-1) { parent = CUR_DIR; } else { int end = hasWindowsDrive(path, true) ? 3 : 0; parent = path.substring(0, lastSlash==end?end+1:lastSlash); } return new Path(uri.getScheme(), uri.getAuthority(), parent); }
public String toString() { // we can't use uri.toString(), which escapes everything, because we want // illegal characters unescaped in the string, for glob processing, etc. StringBuffer buffer = new StringBuffer(); if (uri.getScheme() != null) { buffer.append(uri.getScheme()); buffer.append(":"); } if (uri.getAuthority() != null) { buffer.append("//"); buffer.append(uri.getAuthority()); } if (uri.getPath() != null) { String path = uri.getPath(); if (path.indexOf('/')==0 && hasWindowsDrive(path, true) && // has windows drive uri.getScheme() == null && // but no scheme uri.getAuthority() == null) // or authority path = path.substring(1); // remove slash before drive buffer.append(path); } return buffer.toString(); }
/** Construct a Path from components. */ public Path(String scheme, String authority, String path) { checkPathArg( path ); // add a slash in front of paths with Windows drive letters if (hasWindowsDrive(path) && path.charAt(0) != '/') { path = "/" + path; } // add "./" in front of Linux relative paths so that a path containing // a colon e.q. "a:b" will not be interpreted as scheme "a". if (!WINDOWS && path.charAt(0) != '/') { path = "./" + path; } initialize(scheme, authority, path, null); }
/** Construct a Path from components. */ public Path(String scheme, String authority, String path) { checkPathArg( path ); // add a slash in front of paths with Windows drive letters if (hasWindowsDrive(path) && path.charAt(0) != '/') { path = "/" + path; } // add "./" in front of Linux relative paths so that a path containing // a colon e.q. "a:b" will not be interpreted as scheme "a". if (!WINDOWS && path.charAt(0) != '/') { path = "./" + path; } initialize(scheme, authority, path, null); }
/** Construct a Path from components. */ public Path(String scheme, String authority, String path) { checkPathArg( path ); // add a slash in front of paths with Windows drive letters if (hasWindowsDrive(path) && path.charAt(0) != '/') { path = "/" + path; } // add "./" in front of Linux relative paths so that a path containing // a colon e.q. "a:b" will not be interpreted as scheme "a". if (!WINDOWS && path.charAt(0) != '/') { path = "./" + path; } initialize(scheme, authority, path, null); }
/** * Construct a Path from components. * * @param scheme the scheme * @param authority the authority * @param path the path */ public Path(String scheme, String authority, String path) { checkPathArg( path ); // add a slash in front of paths with Windows drive letters if (hasWindowsDrive(path) && path.charAt(0) != '/') { path = "/" + path; } // add "./" in front of Linux relative paths so that a path containing // a colon e.q. "a:b" will not be interpreted as scheme "a". if (!WINDOWS && path.charAt(0) != '/') { path = "./" + path; } initialize(scheme, authority, path, null); }