Java URL Read getStreamByConnection(final HttpURLConnection con)

Here you can find the source of getStreamByConnection(final HttpURLConnection con)

Description

Returns the inputstream or errorstream via the http-connection

License

Apache License

Parameter

Parameter Description
con connection which is analyzed

Exception

Parameter Description
IOException exception which can occur in the network-task

Return

inputstream or errorstream

Declaration

private static InputStream getStreamByConnection(final HttpURLConnection con) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.io.InputStream;

import java.net.HttpURLConnection;

public class Main {
    /**// w  ww .j  a va  2  s.c  o m
     * Returns the inputstream or errorstream via the http-connection
     * 
     * @param con connection which is analyzed
     * @return inputstream or errorstream
     * @throws IOException exception which can occur in the network-task
     */
    private static InputStream getStreamByConnection(final HttpURLConnection con) throws IOException {
        InputStream stream = null;
        int responseCode = con.getResponseCode();
        if (responseCode > 399) {
            stream = con.getErrorStream();
        } else {
            stream = con.getInputStream();
        }
        return stream;
    }
}

Related

  1. getHttpResponse(String urlStr)
  2. getLastModified(HttpURLConnection conn)
  3. getLastModified(HttpURLConnection connection)
  4. getRemoteFileLength(String url)
  5. getRemoteFileSize(URL url)
  6. getStringFromConnection(HttpURLConnection connection)
  7. getStringFromURL(String URLString)
  8. getText(HttpURLConnection conn)
  9. getText(String url)