PathTools { public static String getAbsolutePath(String basePath, String path) { String resolvedPath = resolvePath(basePath, path); String result = evaluatePath(resolvedPath); if(result.isEmpty() || result.charAt(0) != '/') { final Logger logger = LoggerFactory.getLogger(PathTools.class); if(logger.isDebugEnabled()) logger.debug("The evaluated path is not absolute: \"{}\". Returning null for getAbsolutePath(\"{}\", \"{}\").", result, basePath, path); return null; } return result; } private  PathTools(); static String resolvePath(String basePath, String path); static String evaluatePath(String path); static String getAbsolutePath(String basePath, String path); static String getParentPath(String path); static String getCompatiblePath(String path); static boolean isDotPattern(String s); static List<String> getPathStack(String path, boolean evaluateDots); static String getPathStackString(List<String> pathStack);  }
@Test public void getAbsolutePath() throws Exception { internalGetAbsolutePath("", "", null); internalGetAbsolutePath("/", "", "/"); internalGetAbsolutePath("/", "foo/bar", "/foo/bar"); internalGetAbsolutePath("/foobar", "foo/bar", "/foobar/foo/bar"); internalGetAbsolutePath("/foobar/", "foo/bar", "/foobar/foo/bar"); internalGetAbsolutePath("/foobar", "/foo/bar", "/foo/bar"); internalGetAbsolutePath("/foobar", "../foo/bar", "/foo/bar"); internalGetAbsolutePath("/foo/bar", "../foobar", "/foo/foobar"); internalGetAbsolutePath("/foo/bar", "..../foobar", null); internalGetAbsolutePath("bar", "foobar", null); }