Java Utililty Methods URL Download

List of utility methods to do URL Download

Description

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

Method

Listget(String url, int timeout, Map header)
Method to make a GET request to the specified url
return request(url, timeout, "GET", header);
Stringget(String url, Map headers)
Send a get request
return fetch("GET", url, null, headers);
Stringget(String url, Map params)
get
StringBuilder sb = new StringBuilder();
if (!params.isEmpty()) {
    sb.append("?");
int idx = 0;
for (String column : params.keySet()) {
    if (idx > 0) {
        sb.append("&");
...
Stringget(String url, String encoding)
get
return getStreamContent(new URL(url).openConnection().getInputStream());
Stringget(String urlStr)
get
try {
    URL url = new URL(urlStr);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setInstanceFollowRedirects(true);
    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    List<String> lines = in.lines().collect(Collectors.toList());
    in.close();
...
byte[]get(String urlString)
get
HttpURLConnection urlConnection = null;
try {
    URL url = new URL(urlString);
    urlConnection = (HttpURLConnection) url.openConnection();
    urlConnection.setRequestMethod("GET");
    urlConnection.setConnectTimeout(5000);
    urlConnection.setReadTimeout(3000);
    int responseCode = urlConnection.getResponseCode();
...
intget(URL host, String endpoint, String customer, String name, String version, OutputStream out)
get
int responseCode;
URL url = new URL(host, endpoint + "?customer=" + customer + "&name=" + name + "&version=" + version);
InputStream input = null;
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
try {
    responseCode = connection.getResponseCode();
    input = connection.getInputStream();
    copy(input, out);
...
Stringget(URL url)
get
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader input = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder buffer = new StringBuilder();
for (String line; (line = input.readLine()) != null;) {
    buffer.append(line);
    buffer.append("\n");
input.close();
return buffer.toString();
InputStreamget(URL url, String acceptType)
Sends HTTP GET request
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("GET");
con.setRequestProperty("accept", acceptType);
return con.getInputStream();