Java URL Connection slurpStream(URLConnection conn)

Here you can find the source of slurpStream(URLConnection conn)

Description

slurp Stream

License

Open Source License

Declaration

public static String slurpStream(URLConnection conn) throws Exception 

Method Source Code

//package com.java2s;
/**/*from w  w  w .java2 s  .c  o  m*/
 * Copyright (c) 2004-2006 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   IBM - Initial API and implementation
 */

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.net.URLConnection;

public class Main {
    private static final String EMPTY = "";

    public static String slurpStream(URLConnection conn) throws Exception {
        String ret = EMPTY;
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        char[] tmp = new char[8192];
        int r;
        while ((r = in.read(tmp, 0, 8192)) != -1) {
            ret += new String(tmp, 0, r);
        }

        in.close();
        return ret;
    }
}

Related

  1. sendPost(String url, String param)
  2. setTimeout(URLConnection conn, int milliseconds)
  3. setTimeouts(URLConnection connection)
  4. shortenUrl(String url)
  5. skip(URLConnection connection, long count)
  6. slurpURL(URL u, String encoding)
  7. slurpURLNoExceptions(URL u)
  8. url2list(String sURL, String encoding)
  9. urlContents(String urlString)