List of usage examples for java.net MalformedURLException printStackTrace
public void printStackTrace()
From source file:au.edu.anu.portal.portlets.rss.FeedParser.java
/** * Parse the given feed url and return the raw type * @param feedUrl//from ww w . j av a 2 s . c om * @return */ public SyndFeed parseFeed(String feedUrl) { URL url; XmlReader reader; SyndFeed feed; try { //load the feed url = new URL(feedUrl); reader = new XmlReader(url); feed = input.build(reader); return feed; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (FeedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:it.openyoureyes.test.panoramio.Panoramio.java
private Bitmap downloadFile(String url) { Bitmap bmImg = null;/*w ww . j a va 2s . c o m*/ URL myFileUrl = null; if (Util.isEmpty(url)) return 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(); // BitmapFactory.Options op=new BitmapFactory.Options(); // op.inSampleSize = 3; bmImg = BitmapFactory.decodeStream(is);// ,null,op); conn.disconnect(); } catch (IOException e) { e.printStackTrace(); } return bmImg; }
From source file:de.thecamper.android.androidtools.UpdateChecker.java
protected Boolean doInBackground(Void... params) { try {/*from w w w . ja v a2s.c o m*/ // get the version code from a Get-Request URL url = new URL(versionURL); URLConnection con = url.openConnection(); InputStream is = con.getInputStream(); String encoding = con.getContentEncoding(); encoding = encoding == null ? "UTF-8" : encoding; int versionNumber = Integer.parseInt(IOUtils.toString(is, encoding)); // if it is a newer version out there return true if (versionNumber > context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode) { if (buildNumberIncluded) appURL = appURL.replace("#", String.valueOf(versionNumber)); return true; } else return false; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } catch (NameNotFoundException e) { e.printStackTrace(); } return false; }
From source file:org.imaginationforpeople.android2.model.Picture.java
public void setThumbBitmap(Bitmap thumbBitmap) { try {/*from ww w . j av a 2 s . c o m*/ String path = new URL(thumbUrl).getPath(); FileOutputStream file = DataHelper.openFileOutput( DataHelper.FILE_PREFIX_PROJECT_THUMB + path.substring(path.lastIndexOf('/') + 1)); thumbBitmap.compress(Bitmap.CompressFormat.PNG, 90, file); } catch (MalformedURLException e) { e.printStackTrace(); } this.thumbBitmap = thumbBitmap; }
From source file:org.imaginationforpeople.android2.model.Picture.java
public void setImageBitmap(Bitmap imageBitmap) { try {// w ww . j av a2 s .c o m String path = new URL(imageUrl).getPath(); FileOutputStream file = DataHelper.openFileOutput( DataHelper.FILE_PREFIX_PROJECT_IMAGE + path.substring(path.lastIndexOf('/') + 1)); imageBitmap.compress(Bitmap.CompressFormat.PNG, 90, file); } catch (MalformedURLException e) { e.printStackTrace(); } this.imageBitmap = imageBitmap; }
From source file:com.neudesic.mobile.pulse.ui.drawable.DrawableManager.java
public Bitmap fetchBitmapImage(String imageUrl) throws FileNotFoundException { InputStream is = null;//from w w w. ja v a 2 s. c o m BufferedInputStream buf = null; try { is = (InputStream) fetchImage(imageUrl); buf = new BufferedInputStream(is); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Bitmap bmp = null; BitmapFactory.Options ops = new BitmapFactory.Options(); ops.inJustDecodeBounds = false; bmp = BitmapFactory.decodeStream(buf, null, ops); return bmp; }
From source file:com.acc.util.InstagramClient.java
public String getProfilePicOfUser(final String code) { String profilePic = null;/* w ww . j a v a 2 s. c o m*/ // final String inputJson = "client_id=e580d04d0687403189f86d49545b69a4&client_secret=a2943297f601402d894f8d21400bdfd5&grant_type=authorization_code&redirect_uri=http://electronics.local:9001/yacceleratorstorefront/electronics/en/facerecognitionpage&code=" // + code; //String inputJson1 = "{\"Identities\": [{\"Score\": \"99.99986\",\"IdentityDetails\": {\"BiographicData\": [{\"Key\": \"Name\",\"Value\": \"Ravi\"},{\"Key\": \"ID\",\"Value\": \"DRIVING_LICENSE_ID\"}],\"BiometricDatas\": [{\"Base64Data\": \"/9j/4AAQSkZJ\",\"Modality\": \"Face_Face2D\",\"Type\": \"Image\"}],\"IdentityId\": \"BiometricDev[1:S:58840];\"}}],\"InWatchList\": false}"; // System.out.println(inputJson); // Make Web Service Call // final Client client = ClientBuilder.newClient(); // final String instagramOutputJson = client.target("https://api.instagram.com/oauth/access_token").request() // .method("POST", Entity.entity(inputJson, MediaType.APPLICATION_JSON), String.class); try { final URL url = new URL("https://api.instagram.com/oauth/access_token"); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); final String urlParameters = "client_id=e580d04d0687403189f86d49545b69a4" + "&client_secret=a2943297f601402d894f8d21400bdfd5" + "&grant_type=authorization_code" + "&redirect_uri=http://electronics.local:9001/yacceleratorstorefront/electronics/en/facerecognitionpage" + "&code=" + code; connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("charset", "utf-8"); connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)); final DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); final BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream())); final StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } System.out.println(result.toString()); System.out.println("Output Json from Instagram is " + result); profilePic = processJson(result.toString()); } catch (final MalformedURLException e) { // YTODO Auto-generated catch block e.printStackTrace(); } catch (final IOException e) { // YTODO Auto-generated catch block e.printStackTrace(); } return profilePic; }
From source file:fyp.project.uploadFile.UploadFile.java
public int upLoad2Server(String sourceFileUri) { String upLoadServerUri = "http://vbacdu.ddns.net:8080/WBS/newjsp.jsp"; // String [] string = sourceFileUri; String fileName = sourceFileUri; int serverResponseCode = 0; HttpURLConnection conn = null; DataOutputStream dos = null;/* www.j a v a 2 s . c om*/ DataInputStream inStream = null; String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1 * 1024 * 1024; String responseFromServer = ""; File sourceFile = new File(sourceFileUri); if (!sourceFile.isFile()) { return 0; } try { // open a URL connection to the Servlet FileInputStream fileInputStream = new FileInputStream(sourceFile); URL url = new URL(upLoadServerUri); conn = (HttpURLConnection) url.openConnection(); // Open a HTTP connection to the URL conn.setDoInput(true); // Allow Inputs conn.setDoOutput(true); // Allow Outputs conn.setUseCaches(false); // Don't use a Cached Copy conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("ENCTYPE", "multipart/form-data"); conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary); conn.setRequestProperty("file", fileName); dos = new DataOutputStream(conn.getOutputStream()); dos.writeBytes(twoHyphens + boundary + lineEnd); dos.writeBytes("Content-Disposition: form-data; name=\"file\";filename=\"" + fileName.substring(fileName.lastIndexOf("/")) + "\"" + lineEnd); m_log.log(Level.INFO, "Content-Disposition: form-data; name=\"file\";filename=\"{0}\"{1}", new Object[] { fileName.substring(fileName.lastIndexOf("/")), lineEnd }); dos.writeBytes(lineEnd); bytesAvailable = fileInputStream.available(); // create a buffer of maximum size bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; // read file and write it into form... bytesRead = fileInputStream.read(buffer, 0, bufferSize); while (bytesRead > 0) { dos.write(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } // send multipart form data necesssary after file data... dos.writeBytes(lineEnd); dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd); // Responses from the server (code and message) serverResponseCode = conn.getResponseCode(); String serverResponseMessage = conn.getResponseMessage(); m_log.log(Level.INFO, "Upload file to server" + "HTTP Response is : {0}: {1}", new Object[] { serverResponseMessage, serverResponseCode }); // close streams m_log.log(Level.INFO, "Upload file to server{0} File is written", fileName); fileInputStream.close(); dos.flush(); dos.close(); } catch (MalformedURLException ex) { ex.printStackTrace(); m_log.log(Level.ALL, "Upload file to server" + "error: " + ex.getMessage(), ex); } catch (Exception e) { e.printStackTrace(); } //this block will give the response of upload link return serverResponseCode; // like 200 (Ok) }
From source file:com.github.pemapmodder.pocketminegui.gui.startup.installer.FetchVersionsThread.java
private void fetchJenkinsBuilds(String urlPath, String buildPrefix, ReleaseType releaseType) { try {/*from w w w . jav a 2s . c o m*/ URL url = new URL(urlPath); String jsonString = IOUtils.toString(url); JSONObject object = new JSONObject(jsonString); JSONArray array = object.getJSONArray("builds"); for (Object arrayObject : array) { JSONObject build = (JSONObject) arrayObject; if (!build.getString("result").equals("SUCCESS")) { continue; } String artifactName = null; for (Object artifactObject : build.getJSONArray("artifacts")) { JSONObject artifact = (JSONObject) artifactObject; if (artifact.getString("fileName").endsWith(".phar")) { artifactName = artifact.getString("relativePath"); } } if (artifactName == null) { continue; } Release release = new Release(buildPrefix + "-" + build.getInt("number"), releaseType, build.getLong("timestamp"), build.getString("url") + "artifact/" + artifactName); synchronized (releases) { releases.add(release); } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException | JSONException | NullPointerException | ClassCastException e) { if (e.getMessage().startsWith("Server returned HTTP response code: 521")) { System.err.println("Jenkins server is down!"); return; } System.err.println("Jenkins API returned invalid value, resulting in this error: "); e.printStackTrace(); } }
From source file:data.engine.request.builder.RequestBuilder.java
@Override public BufferedReader makeRequest(String query, String format, boolean diagnosticValue) { String diagnostic = "&diagnostic="; BufferedReader br = null;/*from w w w. j av a 2s . c om*/ if (diagnosticValue) { diagnostic += true; } else { diagnostic += false; } if (query.length() > 10) { baseURL += EncodeQuery(query) + format + diagnostic; try { URL url = new URL(baseURL); br = getResponse(url); } catch (MalformedURLException e) { System.out.println("Unable to parse URL"); e.printStackTrace(); } } else { System.out.println("Error occured while making the request"); } return br; }