@Test public void getLocalPath() throws IOException { Map<String, String> empty = Collections.emptyMap(); assertNull(FileUtil.getLocalPath(null, empty, null, null)); File tmp = File.createTempFile("ply-test", ".tmp"); URL url = tmp.toURI().toURL(); String path = FileUtil.getLocalPath(url, empty, "ply-test", "tmp location"); assertNotNull(path); assertEquals(tmp.getPath(), path); String expectedPath = "/Users/ply/test.tmp"; url = URI.create("file:" + expectedPath).toURL(); path = FileUtil.getLocalPath(url, empty, "ply-test", "tmp location"); assertNotNull(path); assertEquals(expectedPath, path); url = URI.create("http: assertNull(FileUtil.getLocalPath(url, empty, "dne", "tmp location")); url = URI.create("https: path = FileUtil.getLocalPath(url, empty, "readme", "tmp location"); assertNotNull(path); assertTrue(path.contains("ply-")); assertTrue(path.endsWith(".tmp")); }
public static String getLocalPath(URL url, Map<String, String> headers, String name, String intoName) { if (url == null) { return null; } String protocol = url.getProtocol(); if ("file".equals(protocol)) { return url.getFile(); } else { try { File tmp = File.createTempFile("ply-", ".tmp"); if (download(url, headers, tmp, name, intoName, true)) { return tmp.getPath(); } else { return null; } } catch (IOException ioe) { return null; } } }
FileUtil { public static String getLocalPath(URL url, Map<String, String> headers, String name, String intoName) { if (url == null) { return null; } String protocol = url.getProtocol(); if ("file".equals(protocol)) { return url.getFile(); } else { try { File tmp = File.createTempFile("ply-", ".tmp"); if (download(url, headers, tmp, name, intoName, true)) { return tmp.getPath(); } else { return null; } } catch (IOException ioe) { return null; } } } }
FileUtil { public static String getLocalPath(URL url, Map<String, String> headers, String name, String intoName) { if (url == null) { return null; } String protocol = url.getProtocol(); if ("file".equals(protocol)) { return url.getFile(); } else { try { File tmp = File.createTempFile("ply-", ".tmp"); if (download(url, headers, tmp, name, intoName, true)) { return tmp.getPath(); } else { return null; } } catch (IOException ioe) { return null; } } } private  FileUtil(); }
FileUtil { public static String getLocalPath(URL url, Map<String, String> headers, String name, String intoName) { if (url == null) { return null; } String protocol = url.getProtocol(); if ("file".equals(protocol)) { return url.getFile(); } else { try { File tmp = File.createTempFile("ply-", ".tmp"); if (download(url, headers, tmp, name, intoName, true)) { return tmp.getPath(); } else { return null; } } catch (IOException ioe) { return null; } } } private  FileUtil(); static boolean copyDir(File fromDir, File toDir); static boolean copyDir(File fromDir, File toDir, FilenameFilter excluding); static boolean copy(File from, File to); static boolean copy(URL from, File to); static boolean copy(InputStream from, File to); static String getLocalPath(URL url, Map<String, String> headers, String name, String intoName); static boolean download(URL remoteUrl, Map<String, String> headers, File into, String name, String intoName, boolean ignoreFNF); static URL getUrl(String path); static InputStream downloadToStream(URL remoteUrl, Map<String, String> headers); static String pathFromParts(String ... parts); static File fromParts(String ... parts); static String resolveUnixTilde(String path); static String reverseUnixTilde(String path); static boolean isLocalPath(String path); static String encodeForURI(String filePath); static void delete(File file); static String getCanonicalPath(File file); static String stripFileUriPrefix(String path); static String getSha1Hash(File file); }
FileUtil { public static String getLocalPath(URL url, Map<String, String> headers, String name, String intoName) { if (url == null) { return null; } String protocol = url.getProtocol(); if ("file".equals(protocol)) { return url.getFile(); } else { try { File tmp = File.createTempFile("ply-", ".tmp"); if (download(url, headers, tmp, name, intoName, true)) { return tmp.getPath(); } else { return null; } } catch (IOException ioe) { return null; } } } private  FileUtil(); static boolean copyDir(File fromDir, File toDir); static boolean copyDir(File fromDir, File toDir, FilenameFilter excluding); static boolean copy(File from, File to); static boolean copy(URL from, File to); static boolean copy(InputStream from, File to); static String getLocalPath(URL url, Map<String, String> headers, String name, String intoName); static boolean download(URL remoteUrl, Map<String, String> headers, File into, String name, String intoName, boolean ignoreFNF); static URL getUrl(String path); static InputStream downloadToStream(URL remoteUrl, Map<String, String> headers); static String pathFromParts(String ... parts); static File fromParts(String ... parts); static String resolveUnixTilde(String path); static String reverseUnixTilde(String path); static boolean isLocalPath(String path); static String encodeForURI(String filePath); static void delete(File file); static String getCanonicalPath(File file); static String stripFileUriPrefix(String path); static String getSha1Hash(File file);  }