List of utility methods to do URL Download nio
boolean | canDownload(String filePath) can Download try { if (new File(filePath).exists()) { Files.delete(Paths.get(filePath)); return true; } catch (IOException ignored) { return false; |
boolean | download(File dist, URL src) download InputStream is = null;
ReadableByteChannel in = null;
FileOutputStream fos = null;
FileChannel out = null;
try {
URLConnection connection = src.openConnection();
is = connection.getInputStream();
in = Channels.newChannel(is);
...
|
void | download(String from, String to) download download(newURL(from), Paths.get(to)); |
boolean | download(String link, File destFile) download return download(link, destFile, false);
|
void | download(String url, File output) download URL url1 = new URL(url); ReadableByteChannel rbc = Channels.newChannel(url1.openStream()); FileOutputStream fos = new FileOutputStream(output); if (!output.exists()) { output.getParentFile().mkdirs(); output.createNewFile(); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); ... |
void | download(String url, String destPath) download InputStream downloadIn = new BufferedInputStream(new URL(url).openStream(), BUFFER); File destFile = new File(destPath); com.google.common.io.Files.createParentDirs(destFile); Files.copy(downloadIn, destFile.toPath()); |
Path | download(String url, String inputFile, String outputPath, String outputFile) download return download(url + inputFile, outputPath, outputFile);
|
void | download(URI source, File target) Downloads a file from the Internet ReadableByteChannel rbc = Channels.newChannel(source.toURL().openStream());
FileOutputStream fos = new FileOutputStream(target, false);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
void | download(URL link, File outputFile) Download a file from a specific url. if (link == null) throw new IllegalArgumentException("dl link cannot be null"); ReadableByteChannel rbc = Channels.newChannel(link.openStream()); FileOutputStream output = new FileOutputStream(outputFile); output.getChannel().transferFrom(rbc, 0, 1 << 24); output.close(); |
void | download(URL url, File out) download File parent = out.getParentFile(); if (!out.exists()) { if (parent != null) parent.mkdirs(); File tempFile = File.createTempFile(UUID.randomUUID().toString(), ".tmp", parent); tempFile.deleteOnExit(); try (InputStream is = url.openStream()) { ReadableByteChannel rbc = Channels.newChannel(is); ... |