@Test public void download() throws IOException { Map<String, String> empty = Collections.emptyMap(); assertFalse(FileUtil.download(null, empty, null, null, null, true)); URL url = URI.create("http: assertFalse(FileUtil.download(url, empty, null, null, null, true)); File tmp = File.createTempFile("ply-test", ".tmp"); url = URI.create("https: assertTrue(FileUtil.download(url, empty, tmp, "ply-test.tmp", "tmp location", true)); }
public static boolean download(URL remoteUrl, Map<String, String> headers, File into, String name, String intoName, boolean ignoreFNF) { if (remoteUrl == null) { return false; } InputStream stream; try { stream = downloadToStream(remoteUrl, headers); } catch (FileNotFoundException fnfe) { Output.print("^dbug^ Failed to download URL [ %s ] - FileNotFoundException - %s", remoteUrl.toString(), fnfe.getMessage()); if (!ignoreFNF) { Output.print(fnfe); } return false; } catch (UnknownHostException uhe) { Output.print("^error^ Could not download %s; remote URL %s not accessible", name, intoName, remoteUrl.getHost()); Output.print(uhe); Output.print(""); return false; } catch (IOException ioe) { Output.print(ioe); return false; } Output.print("^info^ Downloading %s from %s...", name, intoName); return FileUtil.copy(stream, into); }
FileUtil { public static boolean download(URL remoteUrl, Map<String, String> headers, File into, String name, String intoName, boolean ignoreFNF) { if (remoteUrl == null) { return false; } InputStream stream; try { stream = downloadToStream(remoteUrl, headers); } catch (FileNotFoundException fnfe) { Output.print("^dbug^ Failed to download URL [ %s ] - FileNotFoundException - %s", remoteUrl.toString(), fnfe.getMessage()); if (!ignoreFNF) { Output.print(fnfe); } return false; } catch (UnknownHostException uhe) { Output.print("^error^ Could not download %s; remote URL %s not accessible", name, intoName, remoteUrl.getHost()); Output.print(uhe); Output.print(""); return false; } catch (IOException ioe) { Output.print(ioe); return false; } Output.print("^info^ Downloading %s from %s...", name, intoName); return FileUtil.copy(stream, into); } }
FileUtil { public static boolean download(URL remoteUrl, Map<String, String> headers, File into, String name, String intoName, boolean ignoreFNF) { if (remoteUrl == null) { return false; } InputStream stream; try { stream = downloadToStream(remoteUrl, headers); } catch (FileNotFoundException fnfe) { Output.print("^dbug^ Failed to download URL [ %s ] - FileNotFoundException - %s", remoteUrl.toString(), fnfe.getMessage()); if (!ignoreFNF) { Output.print(fnfe); } return false; } catch (UnknownHostException uhe) { Output.print("^error^ Could not download %s; remote URL %s not accessible", name, intoName, remoteUrl.getHost()); Output.print(uhe); Output.print(""); return false; } catch (IOException ioe) { Output.print(ioe); return false; } Output.print("^info^ Downloading %s from %s...", name, intoName); return FileUtil.copy(stream, into); } private  FileUtil(); }
FileUtil { public static boolean download(URL remoteUrl, Map<String, String> headers, File into, String name, String intoName, boolean ignoreFNF) { if (remoteUrl == null) { return false; } InputStream stream; try { stream = downloadToStream(remoteUrl, headers); } catch (FileNotFoundException fnfe) { Output.print("^dbug^ Failed to download URL [ %s ] - FileNotFoundException - %s", remoteUrl.toString(), fnfe.getMessage()); if (!ignoreFNF) { Output.print(fnfe); } return false; } catch (UnknownHostException uhe) { Output.print("^error^ Could not download %s; remote URL %s not accessible", name, intoName, remoteUrl.getHost()); Output.print(uhe); Output.print(""); return false; } catch (IOException ioe) { Output.print(ioe); return false; } Output.print("^info^ Downloading %s from %s...", name, intoName); return FileUtil.copy(stream, into); } 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 boolean download(URL remoteUrl, Map<String, String> headers, File into, String name, String intoName, boolean ignoreFNF) { if (remoteUrl == null) { return false; } InputStream stream; try { stream = downloadToStream(remoteUrl, headers); } catch (FileNotFoundException fnfe) { Output.print("^dbug^ Failed to download URL [ %s ] - FileNotFoundException - %s", remoteUrl.toString(), fnfe.getMessage()); if (!ignoreFNF) { Output.print(fnfe); } return false; } catch (UnknownHostException uhe) { Output.print("^error^ Could not download %s; remote URL %s not accessible", name, intoName, remoteUrl.getHost()); Output.print(uhe); Output.print(""); return false; } catch (IOException ioe) { Output.print(ioe); return false; } Output.print("^info^ Downloading %s from %s...", name, intoName); return FileUtil.copy(stream, into); } 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);  }