List of usage examples for java.net HttpURLConnection getInputStream
public InputStream getInputStream() throws IOException
From source file:com.monibox.selTestNG.utils.GetNodeIP.java
private static String httpGetJSONString(final String url) { HttpURLConnection httpCon; StringBuffer httpResponse = null; try {//from w w w. j a v a 2 s . c o m httpCon = createHttpCon(url, "GET"); final BufferedReader br = new BufferedReader(new InputStreamReader(httpCon.getInputStream())); httpResponse = new StringBuffer(); String line = ""; while (null != (line = br.readLine())) { httpResponse.append(line); } } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); } return httpResponse.toString(); }
From source file:com.compomics.colims.core.util.AccessionConverter.java
public static BufferedInputStream openStream(String aURL) throws IOException { URL myURL = new URL(aURL); HttpURLConnection c = (HttpURLConnection) myURL.openConnection(); c.setConnectTimeout(500);//from w w w .jav a 2 s . co m return new BufferedInputStream(c.getInputStream()); }
From source file:de.forsthaus.backend.util.IpLocator.java
/** * Gets the content for a given HttpURLConnection. * //from ww w. jav a 2s . c o m * @param connection * Http URL Connection. * @return HTML response * @exception IOException */ private static List<String> getContent(HttpURLConnection connection) throws IOException { final InputStream in = connection.getInputStream(); try { final List<String> result = new ArrayList<String>(5); final InputStreamReader isr = new InputStreamReader(in); final BufferedReader bufRead = new BufferedReader(isr); String aLine = null; while (null != (aLine = bufRead.readLine())) { result.add(aLine.trim()); } bufRead.close(); return result; } finally { try { in.close(); } catch (final IOException e) { } } }
From source file:Main.java
static public InputStream loadImage(String url) { HttpURLConnection connection = null; InputStream is = null;//from ww w . j ava2 s . c o m try { connection = (HttpURLConnection) new URL(url).openConnection(); connection.setConnectTimeout(15000); is = new BufferedInputStream(connection.getInputStream()); } catch (IOException ioe) { ioe.printStackTrace(); } return is; }
From source file:net.daporkchop.porkbot.util.HTTPUtils.java
private static String sendRequest(HttpURLConnection connection) throws IOException { InputStream inputStream = null; try {// www .j a va 2 s . c o m inputStream = connection.getInputStream(); final String result = IOUtils.toString(inputStream, Charsets.UTF_8); return result; } catch (final IOException e) { IOUtils.closeQuietly(inputStream); inputStream = connection.getErrorStream(); if (inputStream != null) { final String result = IOUtils.toString(inputStream, Charsets.UTF_8); return result; } else { throw e; } } finally { IOUtils.closeQuietly(inputStream); } }
From source file:Main.java
private static InputStream getHttpConnection(String urlString) throws IOException { InputStream stream = null;//from w w w .j a va 2 s.co m URL url = new URL(urlString); URLConnection connection = url.openConnection(); try { HttpURLConnection httpConnection = (HttpURLConnection) connection; httpConnection.setRequestMethod("GET"); httpConnection.connect(); if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { stream = httpConnection.getInputStream(); } } catch (Exception ex) { ex.printStackTrace(); } return stream; }
From source file:Main.java
/** * Makes HttpURLConnection and returns InputStream */// w ww . j a v a2 s.c o m private static InputStream getHttpConnection(String urlString) throws IOException { InputStream stream = null; URL url = new URL(urlString); URLConnection connection = url.openConnection(); try { HttpURLConnection httpConnection = (HttpURLConnection) connection; httpConnection.setRequestMethod("GET"); httpConnection.connect(); if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { stream = httpConnection.getInputStream(); } } catch (Exception ex) { ex.printStackTrace(); } return stream; }
From source file:Main.java
/** * Reads an XML String from an HttpURLConnection. * * @param connection//from w ww .ja va 2s . co m * @return * @throws IOException */ public static String readString(HttpURLConnection connection) throws IOException { StringBuffer buffer = new StringBuffer(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = reader.readLine()) != null) { buffer.append(line); } reader.close(); return buffer.toString(); }
From source file:com.eTilbudsavis.etasdk.network.impl.HttpURLNetwork.java
private static HttpEntity getEntity(HttpURLConnection connection) { BasicHttpEntity entity = new BasicHttpEntity(); InputStream inputStream;//from w w w . ja va 2 s. com try { inputStream = connection.getInputStream(); } catch (IOException ioe) { inputStream = connection.getErrorStream(); } entity.setContent(inputStream); entity.setContentLength(connection.getContentLength()); entity.setContentEncoding(connection.getContentEncoding()); entity.setContentType(connection.getContentType()); return entity; }
From source file:com.tnc.android.graphite.utils.GraphiteConnection.java
private static BufferedReader getReader(String urlString) throws Exception { URL url = new URL(urlString); HttpURLConnection http = (HttpURLConnection) url.openConnection(); http.setConnectTimeout(45000);// w ww. j av a 2 s.co m http.setReadTimeout(45000); BufferedReader reader = new BufferedReader(new InputStreamReader(http.getInputStream()), 8192); return reader; }