List of usage examples for java.io UnsupportedEncodingException toString
public String toString()
From source file:com.piusvelte.sonet.core.PhotoUploadService.java
private void start(Intent intent) { if (intent != null) { String action = intent.getAction(); if (Sonet.ACTION_UPLOAD.equals(action)) { if (intent.hasExtra(Accounts.TOKEN) && intent.hasExtra(Statuses.MESSAGE) && intent.hasExtra(Widgets.INSTANT_UPLOAD)) { String place = null; if (intent.hasExtra(Splace)) place = intent.getStringExtra(Splace); String tags = null; if (intent.hasExtra(Stags)) tags = intent.getStringExtra(Stags); // upload a photo Notification notification = new Notification(R.drawable.notification, "uploading photo", System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", "uploading", PendingIntent.getActivity(PhotoUploadService.this, 0, (Sonet.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification);//from ww w . j a va2 s . c o m (new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... params) { String response = null; if (params.length > 2) { Log.d(TAG, "upload file: " + params[2]); HttpPost httpPost = new HttpPost(String.format(FACEBOOK_PHOTOS, FACEBOOK_BASE_URL, Saccess_token, mSonetCrypto.Decrypt(params[0]))); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); File file = new File(params[2]); ContentBody fileBody = new FileBody(file); entity.addPart(Ssource, fileBody); HttpClient httpClient = SonetHttpClient .getThreadSafeClient(getApplicationContext()); try { entity.addPart(Smessage, new StringBody(params[1])); if (params[3] != null) entity.addPart(Splace, new StringBody(params[3])); if (params[4] != null) entity.addPart(Stags, new StringBody(params[4])); httpPost.setEntity(entity); response = SonetHttpClient.httpResponse(httpClient, httpPost); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } } return response; } @Override protected void onPostExecute(String response) { // notify photo success String message = getString(response != null ? R.string.success : R.string.failure); Notification notification = new Notification(R.drawable.notification, "photo upload " + message, System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", message, PendingIntent.getActivity(PhotoUploadService.this, 0, (Sonet.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification); stopSelfResult(mStartId); } }).execute(intent.getStringExtra(Accounts.TOKEN), intent.getStringExtra(Statuses.MESSAGE), intent.getStringExtra(Widgets.INSTANT_UPLOAD), place, tags); } } } }
From source file:com.shafiq.myfeedle.core.PhotoUploadService.java
private void start(Intent intent) { if (intent != null) { String action = intent.getAction(); if (Myfeedle.ACTION_UPLOAD.equals(action)) { if (intent.hasExtra(Accounts.TOKEN) && intent.hasExtra(Statuses.MESSAGE) && intent.hasExtra(Widgets.INSTANT_UPLOAD)) { String place = null; if (intent.hasExtra(Splace)) place = intent.getStringExtra(Splace); String tags = null; if (intent.hasExtra(Stags)) tags = intent.getStringExtra(Stags); // upload a photo Notification notification = new Notification(R.drawable.notification, "uploading photo", System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", "uploading", PendingIntent.getActivity(PhotoUploadService.this, 0, (Myfeedle.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification);// w ww.j av a 2 s . c o m (new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... params) { String response = null; if (params.length > 2) { Log.d(TAG, "upload file: " + params[2]); HttpPost httpPost = new HttpPost(String.format(FACEBOOK_PHOTOS, FACEBOOK_BASE_URL, Saccess_token, mMyfeedleCrypto.Decrypt(params[0]))); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); File file = new File(params[2]); ContentBody fileBody = new FileBody(file); entity.addPart(Ssource, fileBody); HttpClient httpClient = MyfeedleHttpClient .getThreadSafeClient(getApplicationContext()); try { entity.addPart(Smessage, new StringBody(params[1])); if (params[3] != null) entity.addPart(Splace, new StringBody(params[3])); if (params[4] != null) entity.addPart(Stags, new StringBody(params[4])); httpPost.setEntity(entity); response = MyfeedleHttpClient.httpResponse(httpClient, httpPost); } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } } return response; } @Override protected void onPostExecute(String response) { // notify photo success String message = getString(response != null ? R.string.success : R.string.failure); Notification notification = new Notification(R.drawable.notification, "photo upload " + message, System.currentTimeMillis()); notification.setLatestEventInfo(getBaseContext(), "photo upload", message, PendingIntent.getActivity(PhotoUploadService.this, 0, (Myfeedle.getPackageIntent(PhotoUploadService.this, About.class)), 0)); ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFY_ID, notification); stopSelfResult(mStartId); } }).execute(intent.getStringExtra(Accounts.TOKEN), intent.getStringExtra(Statuses.MESSAGE), intent.getStringExtra(Widgets.INSTANT_UPLOAD), place, tags); } } } }
From source file:com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil.java
/** * Sets the user-defined fields for the specified type. * * @param name the type name * @param fields the user-defined fields * @param extensibleTypeProvider the type provider *///from ww w . jav a2 s .c o m public static void setUserFields(@Nonnull final String name, @Nonnull final Set<UserFieldDescriptor> fields, @Nonnull final ExtensibleTypeProvider extensibleTypeProvider) { // Get type builder final ExtensibleTypeBuilder builder; final ExtensibleType type = extensibleTypeProvider.getType(name); if (type == null) { builder = extensibleTypeProvider.buildType(name); } else { builder = extensibleTypeProvider.updateType(type.getId()); } // Add fields to type final String prefix = JcrMetadataAccess.USR_PREFIX + ":"; fields.forEach(field -> { // Encode field name final String systemName; try { systemName = prefix + URLEncoder.encode(field.getSystemName(), USER_PROPERTY_ENCODING); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e.toString(), e); } // Create field descriptor final FieldDescriptorBuilder fieldBuilder = builder.field(systemName); fieldBuilder.description(field.getDescription()); fieldBuilder.displayName(field.getDisplayName()); fieldBuilder.type(FieldDescriptor.Type.STRING); fieldBuilder.property(JcrUserFieldDescriptor.ORDER, Integer.toString(field.getOrder())); fieldBuilder.property(JcrUserFieldDescriptor.REQUIRED, Boolean.toString(field.isRequired())); fieldBuilder.add(); }); builder.build(); }
From source file:org.kuali.test.handlers.parameter.SelectEditDocumentLookupHandler.java
private String getDocumentIdFromColumn(Element column) { String retval = null;/*from w w w . j a v a 2 s . c om*/ Element anchor = getAnchor(column); if (anchor != null) { Node hrefatt = anchor.getAttributeNode(Constants.HTML_TAG_ATTRIBUTE_HREF); if (hrefatt != null) { try { List<NameValuePair> nvplist = Utils.getNameValueParameterListFromUrl(retval); if (nvplist != null) { for (NameValuePair nvp : nvplist) { if (isDocumentIdParameter(nvp)) { retval = nvp.getValue(); break; } } } } catch (UnsupportedEncodingException ex) { LOG.error(ex.toString(), ex); } } } return retval; }
From source file:com.QuarkLabs.BTCeClientJavaFX.networking.AuthRequest.java
public JSONObject makeRequest(String method, Map<String, String> arguments) throws UnsupportedEncodingException { if (method == null) { return null; }/*ww w. java2s.co m*/ if (arguments == null) { arguments = new HashMap<>(); } arguments.put("method", method); arguments.put("nonce", "" + ++nonce); String postData = ""; for (Iterator it = arguments.entrySet().iterator(); it.hasNext();) { Map.Entry<String, String> ent = (Map.Entry<String, String>) it.next(); if (postData.length() > 0) { postData += "&"; } postData += ent.getKey() + "=" + ent.getValue(); } try { _key = new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA512"); } catch (UnsupportedEncodingException uee) { System.err.println("Unsupported encoding exception: " + uee.toString()); return null; } try { mac = Mac.getInstance("HmacSHA512"); } catch (NoSuchAlgorithmException nsae) { System.err.println("No such algorithm exception: " + nsae.toString()); return null; } try { mac.init(_key); } catch (InvalidKeyException ike) { System.err.println("Invalid key exception: " + ike.toString()); return null; } StringBuilder out = new StringBuilder(); try { HttpURLConnection urlConnection = (HttpURLConnection) (new URL(TRADE_API_URL)).openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); urlConnection.setRequestProperty("Key", key); String sign = byteArrayToHexString(mac.doFinal(postData.getBytes("UTF-8"))); urlConnection.setRequestProperty("Sign", sign); urlConnection.setDoOutput(true); DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); wr.writeBytes(postData); wr.flush(); wr.close(); if (urlConnection.getResponseCode() == 200) { BufferedReader rd = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); String line; while ((line = rd.readLine()) != null) { out.append(line); } rd.close(); } } catch (IOException e) { e.printStackTrace(); } return new JSONObject(out.toString()); }
From source file:at.ac.tuwien.dsg.depic.depictool.generator.DaaSGenerator.java
private void configureProjectPath() { String path = DaaSGenerator.class.getProtectionDomain().getCodeSource().getLocation().getPath(); int index = path.indexOf("/classes/at/ac"); path = path.substring(0, index);/*from ww w . j a va2s. co m*/ try { path = URLDecoder.decode(path, "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.logInfo(ex.toString()); } System.out.println("Project Path: -" + path + "-"); rootPath = path; }
From source file:org.kuali.test.ui.components.dialogs.HtmlRequestDetailsDlg.java
private void initComponents(HtmlRequestOperation htmlRequestOperation) { String[] labels = { "Method", "URL", }; String url = htmlRequestOperation.getUrl(); String urlparams = null;/*from www. j a va 2 s .c om*/ int pos = url.indexOf(Constants.SEPARATOR_QUESTION); if (pos > -1) { urlparams = url.substring(pos + 1); url = url.substring(0, pos); } JComponent[] components = { new DataDisplayLabel(htmlRequestOperation.getMethod()), new DataDisplayLabel(url) }; getContentPane().add(UIUtils.buildEntryPanel(labels, components), BorderLayout.NORTH); if (StringUtils.isNotBlank(urlparams)) { try { List<NameValuePair> l = Utils.getNameValuePairsFromUrlEncodedParams(urlparams); for (NameValuePair p : l) { urlParameters.add(new UpdateableNameValuePair(p)); } } catch (UnsupportedEncodingException ex) { LOG.warn(ex.toString(), ex); } } RequestParameter param = Utils.getContentParameter(htmlRequestOperation); if (param != null) { List<NameValuePair> l = null; if (Utils.isMultipart(htmlRequestOperation)) { l = Utils.getNameValuePairsFromMultipartParams(param.getValue()); } else { try { l = Utils.getNameValuePairsFromUrlEncodedParams(param.getValue()); } catch (UnsupportedEncodingException ex) { LOG.warn(ex.toString(), ex); } } if (l != null) { for (NameValuePair p : l) { urlParameters.add(new UpdateableNameValuePair(p)); } } } getContentPane().add(new TablePanel(getParametersTable(htmlRequestOperation)), BorderLayout.CENTER); addStandardButtons(); setDefaultBehavior(); }
From source file:com.samknows.measurement.net.Connection.java
/** * Retrieve the input stream from the HTTP connection. * //from www.j a v a2s .c o m * @param httpEntity * @return String */ private String retrieveInputStream(HttpEntity httpEntity) { int length = (int) httpEntity.getContentLength(); boolean chunked = (boolean) httpEntity.isChunked(); Log.i(TAG, "Chunked: " + Boolean.toString(chunked) + " - Length: " + Integer.toString(length)); StringBuffer stringBuffer = new StringBuffer(length); try { InputStreamReader inputStreamReader = new InputStreamReader(httpEntity.getContent(), HTTP.UTF_8); char buffer[] = new char[length]; int count; while ((count = inputStreamReader.read(buffer, 0, length - 1)) > 0) { stringBuffer.append(buffer, 0, count); } } catch (UnsupportedEncodingException e) { Log.e(TAG, e.toString()); } catch (IllegalStateException e) { Log.e(TAG, e.toString()); } catch (IOException e) { Log.e(TAG, e.toString()); } return stringBuffer.toString(); }
From source file:com.lgallardo.qbittorrentclient.RSSItemActivity.java
private void onListItemClick(View v, int pos, long id) { // Log.i("Debug", "RSS Item - onListItemClick id=" + id); // Log.i("Debug", "RSS Item - onListItemClick pos=" + pos); RSSFeedItem item = myItemsAdapter.getItems().get(pos); String url = item.getTorrentUrl(); // Log.i("Debug", "RSS Item - Title =" + item.getTitle()); // Log.i("Debug", "RSS Item - Torrent URL =" + url); // Log.i("Debug", "RSS Item - PubDate =" + item.getPubDate()); // Decode url link try {//w w w . jav a2s . c o m url = URLDecoder.decode(url, "UTF-8"); } catch (UnsupportedEncodingException e) { Log.e("Debug", "RSSFeedParser - decoding error: " + e.toString()); } Uri uri = Uri.parse(url); // Send torrent to qBittorrent App Intent intent = new Intent(getBaseContext(), com.lgallardo.qbittorrentclient.MainActivity.class); // // Send torrent to generic torrent app // Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); intent.putExtra("from", "RSSItemActivity"); startActivity(intent); }
From source file:com.QuarkLabs.BTCeClient.exchangeApi.AuthRequest.java
/** * Makes any request, which require authentication * * @param method Method of Trade API//ww w.j av a2 s. co m * @param arguments Additional arguments, which can exist for this method * @return Response of type JSONObject * @throws JSONException */ @Nullable public JSONObject makeRequest(@NotNull String method, Map<String, String> arguments) throws JSONException { if (key.length() == 0 || secret.length() == 0) { return new JSONObject("{success:0,error:'No key/secret provided'}"); } if (arguments == null) { arguments = new HashMap<>(); } arguments.put("method", method); arguments.put("nonce", "" + ++nonce); String postData = ""; for (Iterator<Map.Entry<String, String>> it = arguments.entrySet().iterator(); it.hasNext();) { Map.Entry<String, String> ent = it.next(); if (postData.length() > 0) { postData += "&"; } postData += ent.getKey() + "=" + ent.getValue(); } try { _key = new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA512"); } catch (UnsupportedEncodingException uee) { System.err.println("Unsupported encoding exception: " + uee.toString()); return null; } try { mac = Mac.getInstance("HmacSHA512"); } catch (NoSuchAlgorithmException nsae) { System.err.println("No such algorithm exception: " + nsae.toString()); return null; } try { mac.init(_key); } catch (InvalidKeyException ike) { System.err.println("Invalid key exception: " + ike.toString()); return null; } HttpURLConnection connection = null; BufferedReader bufferedReader = null; DataOutputStream wr = null; try { connection = (HttpURLConnection) (new URL(TRADE_API_URL)).openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Key", key); byte[] array = mac.doFinal(postData.getBytes("UTF-8")); connection.setRequestProperty("Sign", byteArrayToHexString(array)); wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(postData); wr.flush(); InputStream response = connection.getInputStream(); StringBuilder sb = new StringBuilder(); if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { String line; bufferedReader = new BufferedReader(new InputStreamReader(response)); while ((line = bufferedReader.readLine()) != null) { sb.append(line); } return new JSONObject(sb.toString()); } } catch (IOException e) { e.printStackTrace(); } finally { if (connection != null) { connection.disconnect(); } if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } } if (wr != null) { try { wr.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }