List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:bakuposter.gcm.server.POST2GCMessage.java
public static void post(String apiKey, Content content) { try {/*w w w .j av a2 s . c o m*/ URL url = new URL("https://android.googleapis.com/gcm/send"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Authorization", "key=" + apiKey); conn.setDoOutput(true); ObjectMapper mapper = new ObjectMapper(); System.out.println(content.getRegistration_ids().get(0)); DataOutputStream wr = new DataOutputStream(conn.getOutputStream()); mapper.writeValue(wr, content); wr.flush(); wr.close(); int responseCode = conn.getResponseCode(); System.out.println("responseCode = " + responseCode); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static byte[] downloadImage(String imageUrl) { if (imageUrl.endsWith(".jpg") || imageUrl.endsWith(".bmp") || imageUrl.endsWith(".png") || imageUrl.endsWith(".gif")) { try {//from ww w . j a va2s. c o m URL url = new URL(imageUrl); URLConnection urlConn = url.openConnection(); InputStream is = urlConn.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } return baf.toByteArray(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:Main.java
public static String getServerResponse(String urlRequest) { Log.d("urlRequest", urlRequest); String response = ""; HttpURLConnection conn = null; try {/*from w w w . j av a 2 s .c o m*/ conn = (HttpURLConnection) new URL(urlRequest).openConnection(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { response = read(conn.getInputStream()); } catch (IOException e) { e.printStackTrace(); } Log.d("response", response); return response.trim(); }
From source file:Main.java
/** * Parses the M3U file and returns the first file name. * /*from w ww .j a v a 2 s . co m*/ * @param inputUrl * The input M3U file. * @return The first file name in the M3U play list. */ public static String parseM3U(String inputUrl) { String inputFile = ""; try { String plsContents = readTextFromUrl(new URL(inputUrl)); for (String line : plsContents.split("\n")) { if (!line.trim().isEmpty() && !line.trim().startsWith("#")) { inputFile = line.trim(); break; } } } catch (MalformedURLException e) { e.printStackTrace(); } return inputFile; }
From source file:com.dx.ss.plugins.ptree.utils.ClassloaderUtility.java
public static ClassLoader getCustomClassloader(String classpathEntry) { File file = null;/*from www .j a va 2s.c o m*/ try { if (StringUtils.isNotBlank(classpathEntry)) { file = new File(classpathEntry); if (file.exists()) { ClassLoader parent = Thread.currentThread().getContextClassLoader(); URLClassLoader ucl = new URLClassLoader(new URL[] { file.toURI().toURL() }, parent); return ucl; } } } catch (MalformedURLException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static byte[] getHtmlByteArray(final String url) { URL htmlUrl = null;//from w w w.j a v a 2s . com InputStream inStream = null; try { htmlUrl = new URL(url); URLConnection connection = htmlUrl.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection) connection; int responseCode = httpConnection.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { inStream = httpConnection.getInputStream(); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } byte[] data = inputStreamToByte(inStream); return data; }
From source file:com.hazelcast.example.mapreduce.downloader.ImageDownloaderMapper.java
public static Long saveImage(String sourceUrl, String destUrl) { File file = new File(destUrl); URL url;/*from ww w . j a v a 2 s.c o m*/ try { //url = new URL(URLEncoder.encode(sourceUrl, "UTF-8")); url = new URL(sourceUrl); FileUtils.copyURLToFile(url, file); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return file.length(); }
From source file:Main.java
public static URL getConsoleUrl() { try {/*ww w. ja v a 2s .c om*/ URL url = new URL("http://localhost:8080/jbpm-console/"); return url; } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:Main.java
public static String getPathFromUrl(String url) { URL iurl;// w w w. ja v a 2 s . com try { iurl = new URL(url); return iurl.getPath(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return ""; } }
From source file:Main.java
public static String loadImageFromUrl(Context context, String imageURL, File file) { try {// w ww . j av a2 s . com URL url = new URL(imageURL); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setConnectTimeout(5 * 1000); con.setDoInput(true); con.connect(); if (con.getResponseCode() == 200) { InputStream inputStream = con.getInputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024 * 20]; int length = -1; while ((length = inputStream.read(buffer)) != -1) { byteArrayOutputStream.write(buffer, 0, length); } byteArrayOutputStream.close(); inputStream.close(); FileOutputStream outputStream = new FileOutputStream(file); outputStream.write(byteArrayOutputStream.toByteArray()); outputStream.close(); return file.getPath(); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; }