URLConnection getInputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for URLConnection getInputStream method.

This code example shows how to use the following methods:getResponseCode, getInputStream
     * the request fails. 
     */ 
    public List entries;
 
    public ListAllMyBucketsResponse(HttpURLConnection connection) throws IOException {
        super(connection);
        if (connection.getResponseCode() < 400) {
            try { 
                XMLReader xr = Utils.createXMLReader();
                ListAllMyBucketsHandler handler = new ListAllMyBucketsHandler();
                xr.setContentHandler(handler);
                xr.setErrorHandler(handler);
 
                xr.parse(new InputSource(connection.getInputStream()));
                entries = handler.getEntries();
            } catch (SAXException e) {
                throw new RuntimeException("Unexpected error parsing ListAllMyBuckets xml", e);
            } 
        } 
    } 
7
CodeRank
This code example shows how to use the following methods:getInputStream, setSSLSocketFactory
        "/echo?a=b&c<=d&e=>"))); 
  } 
 
  private static String readOut(URL url) throws Exception {
    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
    conn.setSSLSocketFactory(clientSslFactory.createSSLSocketFactory());
    InputStream in = conn.getInputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copyBytes(in, out, 1024);
    return out.toString();
  } 
 
} 
7
CodeRank
This code example shows how to use the following methods:connect, getInputStream, setDoInput
This code example shows how to use the following methods:getInputStream
   * JSON parsed. 
   */ 
  static Object jsonParse(HttpURLConnection conn) throws IOException {
    try { 
      JSONParser parser = new JSONParser();
      return parser.parse(new InputStreamReader(conn.getInputStream()));
    } catch (ParseException ex) { 
      throw new IOException("JSON parser error, " + ex.getMessage(), ex);
    } 
  } 
} 
7
CodeRank
This code example shows how to use the following methods:getInputStream, getHostnameVerifier, setSSLSocketFactory
		   
		  //HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); 
		  //for now for testing 
		  HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
		  HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection();
		  urlConnection.setSSLSocketFactory(sslContext.getSocketFactory());
		  Log.i(TAG,"hostnameverifier is: " + urlConnection.getHostnameVerifier().getClass().getName());
 
		  return urlConnection.getInputStream();
	} 
 
	public void onClick(View arg0) {
		try { 
			InputStream is = this.testHttpsUrlPinned();
			Log.i(TAG, "made SSL connection!");
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			String line = null;
			while( (line = br.readLine()) != null){
				mTextView.append(line);
				Log.i(TAG,line);
7
CodeRank
This code example shows how to use the following methods:setRequestMethod, getInputStream, setRequestProperty
	public static String useragent;
 
	/** mainly sets the User-Agent we need */ 
	private static void setUserAgent(HttpURLConnection conn) {
		if (useragent != null)
			conn.setRequestProperty("User-Agent", useragent);
	} 
 
	public static URL getRedirectedUrl(URL url) throws IOException {
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
		setUserAgent(conn);
		conn.setRequestMethod("GET");
		conn.setInstanceFollowRedirects(false);
		int rc = conn.getResponseCode();
		if (rc != REDIRECT_RESPONSE_CODE) {
			throw new IOException("code " + rc + " '" + conn.getResponseMessage() + "'");
		} 
		String location = conn.getHeaderField("Location");
		if (location == null) {
			throw new IOException("No 'Location' header found");

7
CodeRank
This code example shows how to use the following methods:getInputStream, setConnectTimeout, setReadTimeout
    try { 
      if (URIMETHOD.matcher(query).find()) url = new URL(query);
      else url = new URL(baseUrl + query);
      LOG.debug("Accessing URL: " + url.toString());
      URLConnection conn = url.openConnection();
      conn.setConnectTimeout(connectionTimeout);
      conn.setReadTimeout(readTimeout);
      return conn.getInputStream();
    } catch (Exception e) {
      LOG.error("Exception thrown while getting data", e);
      wrapAndThrow (SEVERE, e, "Exception in invoking url " + url);
      return null;//unreachable 
    } 
  } 
 
  @Override 
  public void close() { } 
 
  private String getInitPropWithReplacements(String propertyName) {
    final String expr = initProps.getProperty(propertyName);
7
CodeRank
This code example shows how to use the following methods:getInputStream, setConnectTimeout, setReadTimeout, setUseCaches
      return getWildcardStreamLocator().locateStream(uri, new File(URLDecoder.decode(url.getFile(), "UTF-8")));
    } 
    final URL url = new URL(uri);
    final URLConnection connection = url.openConnection();
    // avoid jar file locking on Windows. 
    connection.setUseCaches(false);
 
    // setting these timeouts ensures the client does not deadlock indefinitely 
    // when the server has problems. 
    connection.setConnectTimeout(timeout);
    connection.setReadTimeout(timeout);
 
    return new BufferedInputStream(connection.getInputStream());
  } 
 
  /** 
   * The read & connect timeout value (in milliseconds) used to limit wait period to a reasonable value. By default 
   * {@value WroConfiguration#DEFAULT_CONNECTION_TIMEOUT} ms is used. 
   */ 
  public void setTimeout(int timeout) {
7
CodeRank
This code example shows how to use the following methods:getInputStream
    assertTrue(getResponseAsString(client).contains("<body>"));
  } 
 
  private String getResponseAsString(URLConnection client) {
    try { 
      byte[] bytes = ByteStreams.toByteArray(client.getInputStream());
      return new String(bytes);
    } catch (IOException e) {
      throw Throwables.propagate(e);
    } 
  } 
} 
7
CodeRank
This code example shows how to use the following methods:connect, getInputStream
        return new ServerGroupDeploymentPlanBuilderImpl(this, newSet);
    } 
 
    private AddDeploymentPlanBuilder add(String name, String commonName, URL url) throws IOException, DuplicateDeploymentNameException {
        URLConnection conn = url.openConnection();
        conn.connect();
        InputStream stream = conn.getInputStream();
        try { 
            return add(name, commonName, stream);
        } 
        finally { 
            try { stream.close(); } catch (Exception ignored) {}
        } 
    } 
 
    private RemoveDeploymentPlanBuilder replace(String name, String commonName, URL url) throws IOException {
        URLConnection conn = url.openConnection();
        conn.connect();
        InputStream stream = conn.getInputStream();
        try { 
8
CodeRank

Related URLConnection getInputStream Questions & Answers:

Other URLConnection getInputStream Examples

70:	            conn.setReadTimeout(30000);
71:	            conn.setInstanceFollowRedirects(true);
72:	            InputStream is=conn.getInputStream();
73:	            OutputStream os = new FileOutputStream(f);
74:	            Utils.CopyStream(is, os);

Read More

69:	            conn.setInstanceFollowRedirects(true);
70:	            InputStream is=conn.getInputStream();
71:	            OutputStream os = new FileOutputStream(f);
72:	            Utils.CopyStream(is, os);
73:	            os.close();

Read More

getInputStream Method Overview
Returns an input stream that reads from this open connection.
See Code Examples for other Java 8 URLConnection Methods: