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

Stringread(URL file)
read
BufferedReader input = new BufferedReader(new InputStreamReader(file.openStream()));
try {
    StringWriter sw = new StringWriter();
    copy(input, sw);
    return sw.toString();
} finally {
    input.close();
Readerread(URL url, String charsetName)
read
if (url == null) {
    throw new NullPointerException();
return new InputStreamReader(url.openStream(), charsetName);
StringreadAsString(URL url)
read As String
StringBuilder response = new StringBuilder();
String line;
try (InputStreamReader isr = new InputStreamReader(url.openStream());
        BufferedReader br = new BufferedReader(isr)) {
    while ((line = br.readLine()) != null) {
        response.append(line);
} catch (IOException e) {
...
StringreadAsStringUTF8(URL url)
Reads UTF 8 from a URL into String (usable to load form file also).
StringBuffer str = new StringBuffer(10000);
String cur;
BufferedReader br = null;
try {
    br = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
    do {
        cur = br.readLine();
        if (cur != null) {
...
byte[]readBytes(URL url)
reads the content form an url into a ByteArray
InputStream in = null;
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
    in = url.openStream();
    byte[] buffer = new byte[1024];
    int count = 0;
    do {
        out.write(buffer, 0, count);
...
byte[]readBytesFromURL(String url)
read Bytes From URL
URL u = new URL(url);
InputStream in;
in = u.openStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024 * 1024 * 5);
byte[] b = new byte[1024];
int read;
while ((read = in.read(b)) > 0) {
    baos.write(b, 0, read);
...
byte[]readBytesFromUrl(URL url)
read Bytes From Url
InputStream in = url.openStream();
byte[] ret = readAllBytesFromInputStream(in);
in.close();
return ret;
StringreadContent(URL url)
read Content
if (url == null)
    throw new Exception("unable to verify a null URL");
StringBuffer buffer = new StringBuffer(128);
InputStream in = url.openStream();
byte[] buf = new byte[4096];
int nbytes;
while ((nbytes = in.read(buf)) > 0) {
    buffer.append(new String(buf, 0, nbytes));
...
StringreadContentFromFile(URL u, String encoding)
read Content From File
String content = "";
try {
    int readLength = 0;
    char[] readBuffer = new char[INTERNAL_BUFFER_SIZE];
    BufferedReader uReader = null;
    StringBuffer buf = new StringBuffer();
    char c;
    long toRead = Long.MAX_VALUE;
...
StringreadContents(URL url)
read Contents
InputStream inputStream = url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
StringBuffer contentsBuffer = new StringBuffer();
try {
    String value;
    while ((value = reader.readLine()) != null) {
        contentsBuffer.append(value);
        contentsBuffer.append("\n");
...