List of usage examples for java.net HttpURLConnection getInputStream
public InputStream getInputStream() throws IOException
From source file:com.flexdesktop.connections.restfulConnection.java
public static String postResponse(HttpURLConnection connection) { try {/* www. j a v a 2 s.co m*/ InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); while ((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); return response.toString(); } catch (IOException ex) { Logger.getLogger(com.flexdesktop.connections.restfulConnection.class.getName()).log(Level.SEVERE, null, ex); } return "fail"; }
From source file:Main.java
private static InputStream getInputStreamFromURL(String urlStr) { HttpURLConnection urlConn = null; InputStream inputStream = null; try {//w w w.j av a2 s. c om URL url = new URL(urlStr); urlConn = (HttpURLConnection) url.openConnection(); inputStream = urlConn.getInputStream(); } catch (IOException e) { return null; } return inputStream; }
From source file:Main.java
public static Bitmap getHttpBitmap(String url) { URL myFileUrl = null;//from w ww. j av a 2 s . com Bitmap bitmap = null; try { myFileUrl = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection(); conn.setConnectTimeout(0); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bitmap = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } return bitmap; }
From source file:be.roots.taconic.pricingguide.util.HttpUtil.java
public static byte[] readByteArray(String urlAsString, String userName, String password) { try {/*ww w. java 2 s. c o m*/ final HttpURLConnection con = getInputStreamFor(urlAsString, userName, password); final BufferedInputStream in = new BufferedInputStream(con.getInputStream()); final byte[] response = IOUtils.toByteArray(in); IOUtils.closeQuietly(in); return response; } catch (IOException e) { LOGGER.error(e.getLocalizedMessage(), e); } return null; }
From source file:flexpos.restfulConnection.java
public static String postResponse(HttpURLConnection connection) { try {/*from w w w.j av a 2s . c o m*/ InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuffer response = new StringBuffer(); while ((line = rd.readLine()) != null) { response.append(line); response.append('\r'); } rd.close(); return response.toString(); } catch (IOException ex) { Logger.getLogger(restfulConnection.class.getName()).log(Level.SEVERE, null, ex); } return "fail"; }
From source file:org.droidparts.http.worker.HTTPInputStream.java
public static HTTPInputStream getInstance(HttpURLConnection conn, boolean useErrorStream) throws HTTPException { try {/*from ww w .j ava 2s . c om*/ InputStream is = useErrorStream ? conn.getErrorStream() : conn.getInputStream(); is = getUnpackedInputStream(conn.getContentEncoding(), is); return new HTTPInputStream(is, conn, null); } catch (Exception e) { throw new HTTPException(e); } }
From source file:Main.java
public static final Bitmap fetchAndRescaleBitmap(String uri, int width, int height) throws IOException { URL url = new URL(uri); HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(); httpConnection.setDoInput(true);// w w w . j av a 2 s . c om httpConnection.connect(); InputStream inputStream = httpConnection.getInputStream(); int scaleFactor = findScaleFactor(width, height, inputStream); httpConnection = (HttpURLConnection) url.openConnection(); httpConnection.setDoInput(true); httpConnection.connect(); inputStream = httpConnection.getInputStream(); Bitmap bitmap = scaleBitmap(scaleFactor, inputStream); return bitmap; }
From source file:javarestart.JavaRestartLauncher.java
public static String getText(String url) throws IOException { URL website = new URL(url); HttpURLConnection connection = (HttpURLConnection) website.openConnection(); try (LineNumberReader in = new LineNumberReader(new InputStreamReader(connection.getInputStream()))) { StringBuilder response = new StringBuilder(); String inputLine;//from w w w . j ava 2s.c om while ((inputLine = in.readLine()) != null) response.append(inputLine); return response.toString(); } }
From source file:Main.java
/** * @param url// w w w . j ava 2 s .c o m * @return */ public static Bitmap getBitMapFromURL(URL url) { Bitmap mBitmap = null; try { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.connect(); conn.getContentLength(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); mBitmap = BitmapFactory.decodeStream(bis); bis.close(); is.close(); } catch (Exception e) { Log.e("Exception in MapScrollActivity.getBitmapFromURL", "" + e.getMessage()); e.printStackTrace(); } return mBitmap; }
From source file:Main.java
/** * Get image from newwork //from w ww . j a v a 2s .co m * @param path The path of image * @return InputStream * @throws Exception */ public static InputStream getImageStream(String path) throws Exception { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5 * 1000); conn.setRequestMethod("GET"); if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { return conn.getInputStream(); } return null; }