Java Utililty Methods URL Read

List of utility methods to do URL Read

Description

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

Method

StringgetUrlTxt(String url)
get Url Txt
String sLine = "";
String sText = "";
java.io.InputStream l_urlStream;
java.net.URL l_url = new java.net.URL(url);
java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url.openConnection();
l_connection.connect();
l_urlStream = l_connection.getInputStream();
java.io.BufferedReader l_reader = new java.io.BufferedReader(new java.io.InputStreamReader(l_urlStream));
...
StringreadAsString(final URL url)
read As String
final URLConnection conn = url.openConnection();
conn.setRequestProperty("User-Agent", "Mozilla/5.0");
final StringWriter buffer = new StringWriter();
try (InputStream in = conn.getInputStream()) {
    final InputStreamReader r = new InputStreamReader(in,
            conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding());
    int ch;
    while ((ch = r.read()) >= 0) {
...
ListreadListFromURL(URL p_url)
Reads a list of lines from a url
List<String> text = new LinkedList<String>();
try {
    URLConnection urlc = p_url.openConnection();
    InputStreamReader fisr = new InputStreamReader(urlc.getInputStream());
    BufferedReader br = new BufferedReader(fisr);
    String inLine = br.readLine();
    while (inLine != null) {
        text.add(inLine);
...
String[]readPage(String url)
read Page
url = url.replaceAll(" ", "%20");
ArrayList<String> lines = new ArrayList<String>();
try {
    final URLConnection con = createURLConnection(url);
    final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String line;
    while ((line = in.readLine()) != null) {
        lines.add(line);
...
StringreadStringFromURL(String sourceURL)
readStringFromURL - read the contents of a supplied URL into a string.
StringBuilder content = new StringBuilder();
try {
    URL url = new URL(sourceURL);
    URLConnection urlConnection = url.openConnection();
    BufferedReader bufferedReader = new BufferedReader(
            new InputStreamReader(urlConnection.getInputStream()));
    String line;
    while ((line = bufferedReader.readLine()) != null) {
...
ListreadUrl(final String strUrl)
read Url
final List<String> ret = new ArrayList<String>();
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(new Runnable() {
    public void run() {
        try {
            URL url = new URL(strUrl);
            URLConnection yc = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
...
StringreadUrl(final String url)
read Url
try {
    return readUrl(new URL(url));
} catch (MalformedURLException e) {
    throw new RuntimeException("Can't get url from string " + url);
ListreadUrl(final String url_str)
read Url
final URL url = new URL(url_str);
final URLConnection urlc = url.openConnection();
final BufferedReader in = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
String line;
final List<String> result = new ArrayList<String>();
while ((line = in.readLine()) != null) {
    result.add(line);
in.close();
return result;
StringreadURL(String path)
read URL
URL url = new URL(path);
URLConnection con = url.openConnection();
Reader r = new InputStreamReader(con.getInputStream(), "UTF-8");
StringBuilder buf = new StringBuilder();
while (true) {
    int ch = r.read();
    if (ch < 0) {
        break;
...
StringreadUrl(String url_str)
read Url
String text = "";
try {
    URL url = new URL(url_str);
    URLConnection hc = url.openConnection();
    hc.setConnectTimeout(10000);
    hc.setConnectTimeout(10000);
    hc.setReadTimeout(10000);
    hc.setAllowUserInteraction(false);
...