List of utility methods to do URL Load
byte[] | readURLToByteArray(URL url) read URL To Byte Array return readInputStreamToByteArray(url.openStream());
|
String | readURLToString(URL u, String encoding) Reads a string from a URL return readStreamToString(u.openStream(), encoding);
|
void | saveFile(final URL url, final File file) Save binary contents of an URL into a file. saveFile(url.openStream(), file); |
void | saveFileFromURL(URL url, File destinationFile) Writes the contents of the entry at the given url to the given file. FileOutputStream fo = new FileOutputStream(destinationFile); InputStream is = url.openStream(); byte[] data = new byte[1024]; int bytecount = 0; do { fo.write(data, 0, bytecount); bytecount = is.read(data); } while (bytecount > 0); ... |
void | saveImage(String imageUrl, String destinationFile) save Image URL url = new URL(imageUrl); InputStream is = url.openStream(); OutputStream os = new FileOutputStream(destinationFile); byte[] b = new byte[2048]; int length; while ((length = is.read(b)) != -1) { os.write(b, 0, length); is.close(); os.close(); |
long | saveImageAsFile(String imageUrl, String destinationFile, boolean overwrite) Save an image url to the disk URL url = null; long fileSize = 0; InputStream is = null; OutputStream os = null; try { if (overwrite == false) { File file = new File(destinationFile); if (file.exists()) { ... |
void | saveUrl(String filename, String urlString) save Url BufferedInputStream in = null; FileOutputStream fout = null; try { in = new BufferedInputStream(new URL(urlString).openStream()); fout = new FileOutputStream(filename); byte data[] = new byte[1024]; int count; while ((count = in.read(data, 0, 1024)) != -1) ... |
void | saveUrl(String filename, URL url) save Url new File(filename).getParentFile().mkdirs(); BufferedInputStream in = null; FileOutputStream fout = null; try { in = new BufferedInputStream(url.openStream()); fout = new FileOutputStream(filename); copyStream(in, fout); } finally { ... |
void | saveURL(URL url, OutputStream os) Opens a buffered stream on the url and copies the contents to OutputStream InputStream is = url.openStream(); byte[] buf = new byte[1048576]; int n = is.read(buf); while (n != -1) { os.write(buf, 0, n); n = is.read(buf); |