List of usage examples for java.net URL getContent
public final Object getContent() throws java.io.IOException
From source file:Main.java
/** * @param urlStr/* www .j a v a2 s . c om*/ * @return * @throws Exception */ public static Drawable loadIBitmapDrawable(String urlStr) throws Exception { Drawable drawable = null; try { URL url = new URL(urlStr); InputStream inputStream = (InputStream) url.getContent(); drawable = Drawable.createFromStream(inputStream, "src"); } catch (Exception e) { throw e; } return drawable; }
From source file:Main.java
public static Bitmap loadImageFromNet_throw(String url) throws IOException { URL m; InputStream i = null;//from w w w . j a va2 s.c o m m = new URL(url); i = (InputStream) m.getContent(); return BitmapFactory.decodeStream(i); }
From source file:Main.java
public static Bitmap loadImageFromUrl(String url) { URL m; InputStream i = null;// w ww.j a va2 s . c om try { m = new URL(url); i = (InputStream) m.getContent(); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return BitmapFactory.decodeStream(i); }
From source file:Main.java
public static Bitmap loadImageFromNet(String url) { URL m; InputStream i = null;/*ww w . j av a 2 s . c o m*/ try { m = new URL(url); i = (InputStream) m.getContent(); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return BitmapFactory.decodeStream(i); }
From source file:com.mightypocket.ashot.UpdateChecker.java
public static String check() { String version = null;//from w ww.j ava2 s .c o m try { URL url = new URL(UPDATE_URL); Object content = url.getContent(); if (content instanceof InputStream) { String text = IOUtils.toString((InputStream) content); int st = text.indexOf(VERSION); if (st >= 0) { st += VERSION.length(); int end = text.indexOf("]", st); version = text.substring(st, end); } } } catch (Exception ex) { logger.error("Cannot check for updates.", ex); } return version; }
From source file:Main.java
public static Drawable loadImageFromUrl(String url) { URL m; InputStream i = null;//from ww w . ja v a 2s . c o m try { m = new URL(url); i = (InputStream) m.getContent(); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Drawable d = Drawable.createFromStream(i, "src"); return d; }
From source file:org.iterx.util.SystemUtils.java
public static String getProperty(String key) { String value;// w w w.j av a2 s. co m if ((value = System.getProperty(key)) == null) { ClassLoader classLoader; URL url; classLoader = (SystemUtils.class).getClassLoader(); if ((url = classLoader.getResource(SERVICES + key)) != null) { try { value = (String) url.getContent(); } catch (IOException e) { LOGGER.warn("Failed to retrieve property '" + SERVICES + key + "'.", e); } } } return value; }
From source file:fi.tuukka.weather.utils.Utils.java
public static Bitmap loadBitmapFromUrl(String imageAddress) { try {/*from ww w . jav a2s . co m*/ URL url = new URL(imageAddress); Object content = url.getContent(); InputStream stream = (InputStream) content; // System.out.println("downloaded " + imageAddress); return BitmapFactory.decodeStream(stream); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } return null; }
From source file:org.easyrec.utils.Web.java
/** * This function tries to download the content from the * given Url and returns true in case of success. * * @param sUrl String//from ww w .ja v a 2s . c o m * @return boolean */ @SuppressWarnings({ "UnusedDeclaration" }) public static boolean isDownloadAbleUrl(String sUrl) { if (Security.inWhiteListDomain(sUrl)) { return true; } if (Strings.isNullOrEmpty(sUrl)) { return false; } else { if (sUrl.length() < 4) return false; try { URL url = new URL(sUrl); url.getContent(); return true; } catch (UnknownHostException e) { return false; // ("Unknown Host"); } catch (MalformedURLException e) { return false; // ("Bad URL } catch (FileNotFoundException e) { return false; // ("404 error returned"); } catch (IOException e) { return false; // ("Communication failure"); } catch (Exception e) { return false; // ("Another Shit happend"); } } }
From source file:org.easyrec.util.core.Web.java
/** * This function tries to download the content from the * given Url and returns true in case of success. * * @param sUrl String//from w w w . java 2 s. co m * @return boolean */ @SuppressWarnings({ "UnusedDeclaration" }) public static boolean isDownloadAbleUrl(String sUrl) { if (Security.inWhiteListDomain(sUrl)) { return true; } if (Strings.isNullOrEmpty(sUrl)) { return false; } else { if (sUrl.length() < 4) return false; try { URL url = new URL(sUrl); url.getContent(); return true; } catch (UnknownHostException e) { logger.warn("An error occurred!", e); return false; // ("Unknown Host"); } catch (MalformedURLException e) { logger.warn("An error occurred!", e); return false; // ("Bad URL } catch (FileNotFoundException e) { logger.warn("An error occurred!", e); return false; // ("404 error returned"); } catch (IOException e) { logger.warn("An error occurred!", e); return false; // ("Communication failure"); } catch (Exception e) { logger.warn("An error occurred!", e); return false; // ("Another Shit happend"); } } }