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[]readHttpBytes(String url)
read Http Bytes
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream httpIn = new URL(url).openStream();
byte[] buffer = new byte[1024];
int n;
while ((n = httpIn.read(buffer)) != -1)
    baos.write(buffer, 0, n);
httpIn.close();
return baos.toByteArray();
...
byte[]readHttpFile(final String urlStr)
Read a file from the specified URL
URL url = new URL(urlStr);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream is = null;
try {
    is = url.openStream();
    byte[] byteChunk = new byte[4096];
    int n;
    while ((n = is.read(byteChunk)) > 0) {
...
intreadInteger(URL src, int radix)
read Integer
String line = null;
InputStream stream = null;
try {
    stream = src.openStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
    line = reader.readLine();
} finally {
    closeQuietly(stream);
...
JsonObjectreadJsonFromUrl(String urlString)
Opens a buffered reader, reads the URL and closes the buffered reader.
InputStreamReader inStream = null;
try {
    URL url = new URL(urlString);
    inStream = new InputStreamReader(url.openStream());
    return gson.fromJson(inStream, JsonObject.class);
} finally {
    if (inStream != null)
        inStream.close();
...
StringreadLines(final String url)
read Lines
return readLines(new URL(url));
ListreadLines(final URL url)
Reads lines from the given URL as a list of strings.
List<String> results = new ArrayList<>();
try (InputStream is = url.openStream();
        InputStreamReader isr = new InputStreamReader(is, "UTF-8");
        BufferedReader br = new BufferedReader(isr)) {
    String line;
    while ((line = br.readLine()) != null) {
        results.add(line);
return results;
ListreadLines(URL url)
Reads the lines of the given URL.
List<String> result = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line = "";
do {
    line = reader.readLine();
    if (line != null) {
        result.add(line);
} while (line != null);
reader.close();
return result;
String[]readLinesTrimmedNoCommentFromUrl(final URL fileUrl, final String commentString)
read Lines Trimmed No Comment From Url
BufferedReader in = null;
try {
    in = new BufferedReader(new InputStreamReader(fileUrl.openStream()));
} catch (IOException e) {
    throw new IOException("IOException during reading from URL: \"" + fileUrl + "\"");
return readLinesTrimmedNoCommmentFromBufferedReader(in, commentString);
String[]readListFile(URL listFile)
Read a file and return the list of lines in an array of strings.
ArrayList<String> list = new ArrayList<String>();
InputStream stream = listFile.openStream();
try {
    InputStreamReader isr = new InputStreamReader(stream, "UTF-8");
    BufferedReader reader = new BufferedReader(isr);
    String line = reader.readLine();
    while (line != null) {
        list.add(line);
...
String[]readListFile(URL listFile)
Read a file and return the list of lines in an array of strings.
ArrayList list = new ArrayList();
InputStream stream = openInputStream(listFile);
try {
    InputStreamReader isr = new InputStreamReader(stream, "UTF-8");
    BufferedReader reader = new BufferedReader(isr);
    String line = reader.readLine();
    while (line != null) {
        list.add(line);
...