List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:Main.java
public static Drawable photo_fetch(String img) { Drawable image = null;/*from www . j av a 2 s . c o m*/ try { System.out.println("Inside Run !"); java.net.URL u = new java.net.URL(img); Object content = u.getContent(); InputStream is = (InputStream) content; image = Drawable.createFromStream(is, "src"); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Returning ffrom heew !"); return image; }
From source file:com.jeffy.hdfs.HDFSReadFile.java
/** * java.net.URL?HDFS??//w ww . j a v a2 s. c o m * * @param path hdfs://master:8020/tmp/user.csv */ public static void readDataUseURL(String path) { try (InputStream in = new URL(path).openStream()) { IOUtils.copy(in, System.out); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static String readFile(String link) { try {/*from ww w . j a v a2s . c om*/ // Create a URL for the desired page URL url = new URL(link); // Read all the text returned by the server BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String text = ""; String str; while ((str = in.readLine()) != null) text += str + "\n"; in.close(); return text; } catch (MalformedURLException e) { e.printStackTrace(); return e.getMessage(); } catch (IOException e) { e.printStackTrace(); return e.getMessage(); } }
From source file:Main.java
public static Bitmap getBitMap(String url) { URL myFileUrl = null;/*from ww w .j a va2s. com*/ Bitmap bitmap = null; try { myFileUrl = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection(); 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:Main.java
public static Bitmap getHttpBitmap(String url) { URL myFileUrl = null;/*from w w w.j a v a2s .c o m*/ 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:Main.java
public static Bitmap returnBitMap(String url) { URL myFileUrl = null;/*from w ww. j ava2 s .c om*/ Bitmap bitmap = null; try { myFileUrl = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); bitmap = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { e.printStackTrace(); } // Log.v(tag, bitmap.toString()); return bitmap; }
From source file:com.ln.methods.Getcalendar.java
public static void Main() { //TODO store file locally and check if file changed == redownload try {/*from ww w .ja va 2 s .c o m*/ //Get source // System.setProperty("http.agent", "lnrev2"); URL calendar = new URL(Calendarurl); HttpURLConnection getsource = (HttpURLConnection) calendar.openConnection(); InputStream in = new BufferedInputStream(getsource.getInputStream()); //Write source Writer sw = new StringWriter(); char[] b = new char[1024]; Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); int n; while ((n = reader.read(b)) != -1) { sw.write(b, 0, n); } //Source == String && Send source for parsing Parser.source = sw.toString(); Betaparser.source = sw.toString(); //String lol = sw.toString(); //lol = StringUtils.substringBetween(lol, "<month year=\"2012\" num=\"2\">", "</month>"); //Parser.parse(); Betaparser.parse(); } catch (MalformedURLException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e.getStackTrace(), "Error", JOptionPane.WARNING_MESSAGE); } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, e.getStackTrace(), "Error", JOptionPane.WARNING_MESSAGE); } }
From source file:Main.java
public static Bitmap returnBitmap(String url) { URL fileUrl = null;/*from w w w .ja va 2 s . c o m*/ Bitmap bitmap = null; try { fileUrl = new URL(url); } catch (MalformedURLException e) { e.printStackTrace(); } try { HttpURLConnection conn = (HttpURLConnection) fileUrl.openConnection(); 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:Main.java
public static byte[] fetchUrlToByte(String urlStr) { try {//from www . jav a 2 s.com URL url = new URL(urlStr); URLConnection urlConnection = url.openConnection(); InputStream is = urlConnection.getInputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = is.read(buffer)) != -1) { baos.write(buffer, 0, len); } return baos.toByteArray(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static void downloadResource(final String fileUrl) { new Thread(new Runnable() { @Override/*from ww w . j av a 2s . c om*/ public void run() { inStream = null; isOver = false; try { URL url = new URL(fileUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(5000); inStream = conn.getInputStream(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } isOver = true; } }).start(); }