Java Utililty Methods URL Load

List of utility methods to do URL Load

Description

The list of methods to do URL Load are organized into topic(s).

Method

byte[]readURLToByteArray(URL url)
read URL To Byte Array
return readInputStreamToByteArray(url.openStream());
StringreadURLToString(URL u, String encoding)
Reads a string from a URL
return readStreamToString(u.openStream(), encoding);
voidsaveFile(final URL url, final File file)
Save binary contents of an URL into a file.
saveFile(url.openStream(), file);
voidsaveFileFromURL(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);
...
voidsaveImage(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();
longsaveImageAsFile(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()) {
...
voidsaveUrl(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)
...
voidsaveUrl(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 {
...
voidsaveURL(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);