List of usage examples for java.net URLConnection getInputStream
public InputStream getInputStream() throws IOException
From source file:com.meetingninja.csse.database.BaseDatabaseAdapter.java
protected static String getServerResponse(URLConnection connection) throws IOException { // Read server response BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine;/*from w w w .j av a 2 s. c o m*/ StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); // return page contents return response.toString(); }
From source file:com.maxpowa.chime.util.UpdateChecker.java
public static void checkUpdate() { try {/*from w w w . ja va 2s .c om*/ URLConnection versionData = new URL("http://widget.mcf.li/223265.json").openConnection(); JsonNode object = mapper .readTree(new BufferedReader(new InputStreamReader(versionData.getInputStream()))); // Utils.log.info(object.toString()); if (object.get("versions").has(Chime.MC_VERSION)) { latest = mapper.treeToValue(object.get("versions").get(Chime.MC_VERSION).get(0), ChimeVersion.class); // Utils.log.info(object.get("versions").get(Chime.MC_VERSION).get(0).toString()); } else { Utils.log.info( "Update checker was unable to find a release for this Minecraft version, showing latest release."); // Utils.log.info(object.get("download").toString()); latest = mapper.treeToValue(object.get("download"), ChimeVersion.class); } } catch (IOException e) { Utils.log.error("Update checker failed to check for new version.", e); } }
From source file:com.asual.lesscss.ResourceUtils.java
public static byte[] readTextUrl(URL source, String encoding) throws IOException { byte[] result; try {/*from ww w . j a v a 2s . com*/ URLConnection urlc = source.openConnection(); StringBuffer sb = new StringBuffer(1024); InputStream input = urlc.getInputStream(); UnicodeReader reader = new UnicodeReader(input, encoding); try { char[] cbuf = new char[32]; int r; while ((r = reader.read(cbuf, 0, 32)) != -1) { sb.append(cbuf, 0, r); } result = sb.toString().getBytes(reader.getEncoding()); } finally { reader.close(); input.close(); } } catch (IOException e) { logger.error("Can't read '" + source.getFile() + "'."); throw e; } return result; }
From source file:com.wishlist.Utility.java
public static Bitmap getBitmap(String url) { Bitmap bm = null;//w w w.j a v a 2 s . c om try { URL aURL = new URL(url); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm = BitmapFactory.decodeStream(new FlushedInputStream(is)); bis.close(); is.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (httpclient != null) { httpclient.close(); } } return bm; }
From source file:com.github.cc007.headsinventory.locale.Translator.java
private static InputStream getTranslationsFileStream(String fileName, ClassLoader classLoader) { try {//from w w w. j a va 2s . com URL url = classLoader.getResource(fileName); if (url == null) { return null; } URLConnection connection = url.openConnection(); connection.setUseCaches(false); return connection.getInputStream(); } catch (IOException ex) { return null; } }
From source file:controlador.Red.java
/** * Get de un fichero desde el Server al Cliente Local. * @param rutaLocal Ruta en la cual se creara el fichero. * @param name Nombre con el cual se busca el fichero en el server y se crea en local. * @return Estado de la operacion.// w w w . j a v a 2 s .c o m */ public static boolean getFile(String rutaLocal, String name) { try { url = new URL(conexion + name); URLConnection urlConn = url.openConnection(); InputStream is = urlConn.getInputStream(); FileOutputStream fos = new FileOutputStream(rutaLocal + name); byte[] buffer = new byte[BUFFER_LENGTH]; int count; while ((count = is.read(buffer)) > 0) { fos.write(buffer, 0, count); } fos.flush(); is.close(); fos.close(); return true; } catch (IOException ex) { System.out.println("Problema al recibir un fichero desde el Server: " + ex.getLocalizedMessage()); } return false; }
From source file:com.example.facebook_photo.Utility.java
public static Bitmap getBitmap(String url) { Bitmap bm = null;/*from w w w .ja va2 s . c o m*/ try { URL aURL = new URL(url); URLConnection conn = aURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); bm = BitmapFactory.decodeStream(new FlushedInputStream(is)); bis.close(); is.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (httpclient != null) { httpclient.close(); } } return bm; }
From source file:mobisocial.musubi.social.FacebookFriendFetcher.java
public static byte[] getImageFromURL(String remoteUrl) { try {/*w w w. j a v a2 s . com*/ // Grab the content URL url = new URL(remoteUrl); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream(); // Read the content chunk by chunk BufferedInputStream bis = new BufferedInputStream(is, 8192); ByteArrayBuffer baf = new ByteArrayBuffer(0); byte[] chunk = new byte[CHUNK_SIZE]; int current = bis.read(chunk); while (current != -1) { baf.append(chunk, 0, current); current = bis.read(chunk); } return baf.toByteArray(); } catch (IOException e) { Log.e(TAG, "HTTP error", e); } return null; }
From source file:com.example.Utils.java
public static String getPicFromOpenWebsite2() { try {//w w w. j a va 2 s . co m URL url = new URL(CrashReportingApplication.pape); URLConnection conn = url.openConnection(); InputStream inStream = conn.getInputStream(); String data = ""; StringBuffer str2 = new StringBuffer(); InputStreamReader isr = new InputStreamReader(inStream); BufferedReader br = new BufferedReader(isr); while ((data = br.readLine()) != null) { str2.append(data); } data = str2.toString().trim(); data = data.replace("\n", ""); data = data.replace("\r", ""); return data; } catch (Exception e) { e.printStackTrace(); } return ""; }
From source file:com.tubes2.User.userPaket.java
public static ArrayList<String> readUser(String Username) throws IOException { String URLi = "https://popping-fire-1228.firebaseio.com/users/"; ArrayList<String> dataUser = new ArrayList<String>(); try {//from ww w . j ava2 s.c om URL url = new URL(URLi + Username + ".json"); URLConnection connection = url.openConnection(); JSONObject jsonUser = new JSONObject(IOUtils.toString(connection.getInputStream())); dataUser.add(0, jsonUser.getString("nama")); dataUser.add(1, jsonUser.getString("username")); dataUser.add(2, jsonUser.getString("password")); dataUser.add(3, jsonUser.getString("email")); dataUser.add(4, jsonUser.getString("status")); } catch (JSONException ex) { } catch (IOException ex) { } return dataUser; }