Urls { public static String mergePaths(String ...items) { List<String> parts = Arrays.asList(items); if (parts.contains(null)) { throw new NullPointerException(String.format("Unable to reliably merge path from parts: %s; input contains null values", parts)); } StringBuilder result = new StringBuilder(); for (String part: parts) { boolean trimThisMerge = result.length()>0 && !result.toString().endsWith(": if (trimThisMerge) { while (result.length()>0 && result.charAt(result.length()-1)=='/') result.deleteCharAt(result.length()-1); result.append('/'); } int i = result.length(); result.append(part); if (trimThisMerge) { while (result.length()>i && result.charAt(i)=='/') result.deleteCharAt(i); } } return result.toString(); }  static Function<String,URI> stringToUriFunction(); static Function<String,URL> stringToUrlFunction(); static final URL toUrl(@Nullable String url); static final URL toUrl(@Nullable URI uri); static final URI toUri(@Nullable String uri); static final URI toUri(@Nullable URL url); static boolean isUrlWithProtocol(String x); static boolean isUrlWithProtocol(String x, boolean allowSpacesAfterCharAfterColon, boolean allowMultiline); static String mergePaths(String ...items); static String encode(String text); static String decode(String text); static String getProtocol(String url); static String getBasename(String url); static boolean isDirectory(String fileUrl); static File toFile(String fileUrl); static String asDataUrlBase64(String data); static String asDataUrlBase64(MediaType type, byte[] bytes);  }
@Test public void testMergePaths() throws Exception { assertEquals(Urls.mergePaths("a","b"), "a/b"); assertEquals(Urls.mergePaths("/a assertEquals(Urls.mergePaths("foo: assertEquals(Urls.mergePaths("/","a","b","/"), "/a/b/"); }
@Test(expectedExceptions = NullPointerException.class) public void testMergePathsNPEsOnNulls() { Urls.mergePaths(null, "too"); }