List of utility methods to do URL Download nio
void | downloadFromHttpUrl(String destPkgUrl, FileOutputStream outputStream) download From Http Url URL website = new URL(destPkgUrl);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
outputStream.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
void | downloadFromInternet(URL url, File downloadTo) download From Internet ReadableByteChannel rbc = null; FileOutputStream fos = null; try { rbc = Channels.newChannel(url.openStream()); fos = new FileOutputStream(downloadTo); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } finally { closeQuietly(rbc); ... |
Path | downloadImage(String src, Path saveFolder) download Image Path saveFilePath = srcImageToSavePath(src, saveFolder); URL url = new URL(src); try (InputStream in = url.openStream(); OutputStream out = Files.newOutputStream(saveFilePath)) { for (int b; (b = in.read()) != -1;) { out.write(b); return saveFilePath; ... |
void | downloadToFile(String filename, String urlString) Downloads data from the given URL and saves it to the given file downloadToFile(new URL(urlString), new File(filename)); |
void | downloadToFile(URL url, File file) download To File file.getParentFile().mkdirs();
ReadableByteChannel rbc = Channels.newChannel(url.openStream());
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, 1 << 24);
fos.close();
|
String | downloadToString(String url) download To String InputStream inputStream = openStream(url); if (inputStream == null) { return null; return new String(streamToByteArray(inputStream), Charset.forName("UTF-8")); |
boolean | downloadUrl(String urlstring, File file) download Url try { URL url = new URL(urlstring); ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream(file); fos.getChannel().transferFrom(rbc, 0, 1 << 24); return true; } catch (Exception e) { e.printStackTrace(); ... |