DroidUrlFormat { public static String format(URI uri) { StringBuilder b = new StringBuilder(); if (!"file".equals(uri.getScheme())) { return uri.toString(); } b.append(uri.getScheme()).append(':'); if (uri.getPath().startsWith(WINDOWS_UNC_REFIX)) { b.append(WINDOWS_UNC_REFIX); } if (uri.getAuthority() != null) { b.append(uri.getRawAuthority()); } b.append(encodePath(uri.getPath())); if (uri.getQuery() != null) { b.append(uri.getRawQuery()); } if (uri.getFragment() != null) { b.append(uri.getRawFragment()); } return b.toString(); } private  DroidUrlFormat(); static String format(URI uri);  }
@Test public void testFromUrl() throws URISyntaxException { URI uri = new URI("file:/home/rhubner/ffmpeg_build/strange%20filenames/~~~%60%60~!@%23$%25%5E&*()_+_;:/"); String expectedURI = "file:/home/rhubner/ffmpeg_build/strange%20filenames/%7E%7E%7E%60%60%7E%21%40%23%24%25%5E%26*%28%29_%2B_%3B%3A/"; String result = DroidUrlFormat.format(uri); assertThat(result, equalTo(expectedURI)); }
@Test public void testMore() throws URISyntaxException { for(String[] pattern: TEST_PATTERNS) { URI uri = new URI(pattern[0]); String result = DroidUrlFormat.format(uri); assertThat(result, equalTo(pattern[1])); } }