@Test public void canonicalizeURL_file_escaped() throws MalformedURLException { logger.debug("[{}]canonicalizeURL_file_escaped: entered.", Integer.toHexString(identityHashCode(this))); final String fileString = "file:/tmp/asdf/qwer/\\#Yxcv"; final URL input = new URL(fileString); assertEquals(input.toExternalForm(), fileString); final URL result = UrlUtil.canonicalizeURL(input); assertEquals(input, result); }
public static URL canonicalizeURL(final URL url) { if (url == null) return null; URL result = url; String query = url.getQuery(); if (query != null && query.isEmpty()) { query = null; result = null; } String path = url.getPath(); while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); result = null; } int duplicateSlashIndex = path.indexOf(" while (duplicateSlashIndex >= 0) { path = path.substring(0, duplicateSlashIndex) + path.substring(duplicateSlashIndex + 1); duplicateSlashIndex = path.indexOf(" result = null; } if (result == null) { String file = query == null ? path : path + '?' + query; if (isEmpty(url.getHost()) && isEmpty(file)) file = "/"; try { result = new URL(url.getProtocol(), url.getHost(), url.getPort(), file); } catch (final MalformedURLException e) { throw new RuntimeException(e); } } return result; }
UrlUtil { public static URL canonicalizeURL(final URL url) { if (url == null) return null; URL result = url; String query = url.getQuery(); if (query != null && query.isEmpty()) { query = null; result = null; } String path = url.getPath(); while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); result = null; } int duplicateSlashIndex = path.indexOf(" while (duplicateSlashIndex >= 0) { path = path.substring(0, duplicateSlashIndex) + path.substring(duplicateSlashIndex + 1); duplicateSlashIndex = path.indexOf(" result = null; } if (result == null) { String file = query == null ? path : path + '?' + query; if (isEmpty(url.getHost()) && isEmpty(file)) file = "/"; try { result = new URL(url.getProtocol(), url.getHost(), url.getPort(), file); } catch (final MalformedURLException e) { throw new RuntimeException(e); } } return result; } }
UrlUtil { public static URL canonicalizeURL(final URL url) { if (url == null) return null; URL result = url; String query = url.getQuery(); if (query != null && query.isEmpty()) { query = null; result = null; } String path = url.getPath(); while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); result = null; } int duplicateSlashIndex = path.indexOf(" while (duplicateSlashIndex >= 0) { path = path.substring(0, duplicateSlashIndex) + path.substring(duplicateSlashIndex + 1); duplicateSlashIndex = path.indexOf(" result = null; } if (result == null) { String file = query == null ? path : path + '?' + query; if (isEmpty(url.getHost()) && isEmpty(file)) file = "/"; try { result = new URL(url.getProtocol(), url.getHost(), url.getPort(), file); } catch (final MalformedURLException e) { throw new RuntimeException(e); } } return result; } private  UrlUtil(); }
UrlUtil { public static URL canonicalizeURL(final URL url) { if (url == null) return null; URL result = url; String query = url.getQuery(); if (query != null && query.isEmpty()) { query = null; result = null; } String path = url.getPath(); while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); result = null; } int duplicateSlashIndex = path.indexOf(" while (duplicateSlashIndex >= 0) { path = path.substring(0, duplicateSlashIndex) + path.substring(duplicateSlashIndex + 1); duplicateSlashIndex = path.indexOf(" result = null; } if (result == null) { String file = query == null ? path : path + '?' + query; if (isEmpty(url.getHost()) && isEmpty(file)) file = "/"; try { result = new URL(url.getProtocol(), url.getHost(), url.getPort(), file); } catch (final MalformedURLException e) { throw new RuntimeException(e); } } return result; } private  UrlUtil(); static URL canonicalizeURL(final URL url); static File getFile(final URL url); static URL appendEncodedPath(final URL url, final String path); static URL appendNonEncodedPath(final URL url, final String path); static final URI urlToUri(final URL url); static File getFileFromJarUrl(final URL url); static URL getFileUrlFromJarUrl(final URL url); }
UrlUtil { public static URL canonicalizeURL(final URL url) { if (url == null) return null; URL result = url; String query = url.getQuery(); if (query != null && query.isEmpty()) { query = null; result = null; } String path = url.getPath(); while (path.endsWith("/")) { path = path.substring(0, path.length() - 1); result = null; } int duplicateSlashIndex = path.indexOf(" while (duplicateSlashIndex >= 0) { path = path.substring(0, duplicateSlashIndex) + path.substring(duplicateSlashIndex + 1); duplicateSlashIndex = path.indexOf(" result = null; } if (result == null) { String file = query == null ? path : path + '?' + query; if (isEmpty(url.getHost()) && isEmpty(file)) file = "/"; try { result = new URL(url.getProtocol(), url.getHost(), url.getPort(), file); } catch (final MalformedURLException e) { throw new RuntimeException(e); } } return result; } private  UrlUtil(); static URL canonicalizeURL(final URL url); static File getFile(final URL url); static URL appendEncodedPath(final URL url, final String path); static URL appendNonEncodedPath(final URL url, final String path); static final URI urlToUri(final URL url); static File getFileFromJarUrl(final URL url); static URL getFileUrlFromJarUrl(final URL url); static final String PROTOCOL_FILE; static final String PROTOCOL_JAR; }