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

String[]readContentsToArray(URL url)
read Contents To Array
List<String> lines = readContentsToList(url);
return lines.toArray(new String[lines.size()]);
ListreadContentsToList(URL url)
Reads the contents of the website at the specified URL
LineNumberReader reader = new LineNumberReader(new InputStreamReader(url.openStream()));
List<String> lines = new ArrayList<String>();
String line;
while ((line = reader.readLine()) != null)
    lines.add(line);
reader.close();
return lines;
StringreadContentsToString(URL url)
read Contents To String
LineNumberReader reader = new LineNumberReader(new InputStreamReader(url.openStream()));
StringBuilder content = new StringBuilder();
String line;
while ((line = reader.readLine()) != null)
    content.append(line);
return content.toString();
StringreadData(String url)
read Data
StringBuilder data = new StringBuilder();
try {
    BufferedReader in = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
    String line;
    while ((line = in.readLine()) != null) {
        data.append(line);
    in.close();
...
StringreadFile(URL file)
read File
BufferedReader in = null;
try {
    in = new BufferedReader(new InputStreamReader(file.openStream()), DEFAULT_FILE_SIZE);
    StringBuffer buffer = new StringBuffer(DEFAULT_FILE_SIZE);
    char[] readBuffer = new char[2048];
    int n = in.read(readBuffer);
    while (n > 0) {
        buffer.append(readBuffer, 0, n);
...
StringreadFile(URL url)
read File
InputStream in = url.openStream();
ByteArrayDataOutput bout = ByteStreams.newDataOutput();
int b;
while ((b = in.read()) != -1) {
    bout.writeByte(b);
in.close();
return new String(bout.toByteArray());
...
StringreadFile(URL url)
read File
try {
    return readFile(url.openStream());
} catch (IOException e) {
    throw new RuntimeException(e);
StringreadFileContent(URL file)
read File Content
String content = null;
BufferedReader br = null;
try {
    br = new BufferedReader(new InputStreamReader(file.openStream()));
    String line = null;
    StringBuilder contentBuilder = new StringBuilder();
    while (null != (line = br.readLine())) {
        contentBuilder.append(line).append("\n");
...
StringreadFileFromURL(URL url)
Reads the content of the file at the given url and returns it.
String result = ""; 
InputStream openStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
try {
    openStream = url.openStream();
} catch (IOException e) {
if (openStream != null) {
    inputStreamReader = new InputStreamReader(openStream);
    bufferedReader = new BufferedReader(inputStreamReader);
    StringBuilder stringBuilder = new StringBuilder();
    String line = null;
    try {
        while ((line = bufferedReader.readLine()) != null) {
            stringBuilder.append(line);
    } catch (IOException e) {
        e.printStackTrace();
    try {
        bufferedReader.close();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            inputStreamReader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                openStream.close();
            } catch (IOException e) {
                e.printStackTrace();
    result = stringBuilder.toString();
return result;
MapreadFileIntoMap(URL url)
Reads a text file with KVP content into a map.
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String line = null;
Map<String, String> params = new HashMap<String, String>();
while ((line = reader.readLine()) != null) {
    if (line.contains("=")) {
        String[] parts = line.split("=");
        if (parts[0].equalsIgnoreCase("FILTER")) {
            params.put("FILTER", URLDecoder.decode(line.substring(7), "UTF-8"));
...