@Test public void testUrlToFileWindowsShareFile() throws Exception { assumeTrue("Ignoring test on non Windows OS, see GEOT-3300", SystemUtils.IS_OS_WINDOWS); URL url = new URL("file", "\\\\oehhwsfs09", "/some/path/on/the/server/filename.nds"); File windowsShareFile = URLs.urlToFile(url); assertEquals( "\\\\oehhwsfs09\\some\\path\\on\\the\\server\\filename.nds", windowsShareFile.toString()); }
public static File urlToFile(URL url) { if (!"file".equals(url.getProtocol())) { return null; } String string = url.toString(); if (url.getQuery() != null) { string = string.substring(0, string.indexOf("?")); } if (string.contains("+")) { string = string.replace("+", "%2B"); } try { string = URLDecoder.decode(string, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } String path3; String simplePrefix = "file:/"; String standardPrefix = "file: if (IS_WINDOWS_OS && string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length() - 2); File f = new File(path3); if (!f.exists()) { path3 = path3.substring(2, path3.length()); } } else if (string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length()); } else if (string.startsWith(simplePrefix)) { path3 = string.substring(simplePrefix.length() - 1); } else { String auth = url.getAuthority(); String path2 = url.getPath(); try { path2 = URLDecoder.decode(path2, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } if (auth != null && !auth.equals("")) { path3 = " } else { path3 = path2; } } return new File(path3); }
URLs { public static File urlToFile(URL url) { if (!"file".equals(url.getProtocol())) { return null; } String string = url.toString(); if (url.getQuery() != null) { string = string.substring(0, string.indexOf("?")); } if (string.contains("+")) { string = string.replace("+", "%2B"); } try { string = URLDecoder.decode(string, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } String path3; String simplePrefix = "file:/"; String standardPrefix = "file: if (IS_WINDOWS_OS && string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length() - 2); File f = new File(path3); if (!f.exists()) { path3 = path3.substring(2, path3.length()); } } else if (string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length()); } else if (string.startsWith(simplePrefix)) { path3 = string.substring(simplePrefix.length() - 1); } else { String auth = url.getAuthority(); String path2 = url.getPath(); try { path2 = URLDecoder.decode(path2, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } if (auth != null && !auth.equals("")) { path3 = " } else { path3 = path2; } } return new File(path3); } }
URLs { public static File urlToFile(URL url) { if (!"file".equals(url.getProtocol())) { return null; } String string = url.toString(); if (url.getQuery() != null) { string = string.substring(0, string.indexOf("?")); } if (string.contains("+")) { string = string.replace("+", "%2B"); } try { string = URLDecoder.decode(string, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } String path3; String simplePrefix = "file:/"; String standardPrefix = "file: if (IS_WINDOWS_OS && string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length() - 2); File f = new File(path3); if (!f.exists()) { path3 = path3.substring(2, path3.length()); } } else if (string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length()); } else if (string.startsWith(simplePrefix)) { path3 = string.substring(simplePrefix.length() - 1); } else { String auth = url.getAuthority(); String path2 = url.getPath(); try { path2 = URLDecoder.decode(path2, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } if (auth != null && !auth.equals("")) { path3 = " } else { path3 = path2; } } return new File(path3); }  }
URLs { public static File urlToFile(URL url) { if (!"file".equals(url.getProtocol())) { return null; } String string = url.toString(); if (url.getQuery() != null) { string = string.substring(0, string.indexOf("?")); } if (string.contains("+")) { string = string.replace("+", "%2B"); } try { string = URLDecoder.decode(string, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } String path3; String simplePrefix = "file:/"; String standardPrefix = "file: if (IS_WINDOWS_OS && string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length() - 2); File f = new File(path3); if (!f.exists()) { path3 = path3.substring(2, path3.length()); } } else if (string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length()); } else if (string.startsWith(simplePrefix)) { path3 = string.substring(simplePrefix.length() - 1); } else { String auth = url.getAuthority(); String path2 = url.getPath(); try { path2 = URLDecoder.decode(path2, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } if (auth != null && !auth.equals("")) { path3 = " } else { path3 = path2; } } return new File(path3); }  static URL changeUrlExt(URL url, String postfix); static URL extendUrl(URL base, String extension); static URL fileToUrl(File file); static URL getParentUrl(URL url); static File urlToFile(URL url); }
URLs { public static File urlToFile(URL url) { if (!"file".equals(url.getProtocol())) { return null; } String string = url.toString(); if (url.getQuery() != null) { string = string.substring(0, string.indexOf("?")); } if (string.contains("+")) { string = string.replace("+", "%2B"); } try { string = URLDecoder.decode(string, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } String path3; String simplePrefix = "file:/"; String standardPrefix = "file: if (IS_WINDOWS_OS && string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length() - 2); File f = new File(path3); if (!f.exists()) { path3 = path3.substring(2, path3.length()); } } else if (string.startsWith(standardPrefix)) { path3 = string.substring(standardPrefix.length()); } else if (string.startsWith(simplePrefix)) { path3 = string.substring(simplePrefix.length() - 1); } else { String auth = url.getAuthority(); String path2 = url.getPath(); try { path2 = URLDecoder.decode(path2, java.nio.charset.StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("UTF-8 encoding not supported", e); } if (auth != null && !auth.equals("")) { path3 = " } else { path3 = path2; } } return new File(path3); }  static URL changeUrlExt(URL url, String postfix); static URL extendUrl(URL base, String extension); static URL fileToUrl(File file); static URL getParentUrl(URL url); static File urlToFile(URL url);  }