List of usage examples for android.util Base64 NO_WRAP
int NO_WRAP
To view the source code for android.util Base64 NO_WRAP.
Click Source Link
From source file:com.liato.bankdroid.banking.banks.avanza.Avanza.java
public Urllib login() throws LoginException, BankException { urlopen = new Urllib(context, CertificateReader.getCertificates(context, R.raw.cert_avanza)); urlopen.addHeader("ctag", "1122334455"); urlopen.addHeader("Authorization", "Basic " + Base64.encodeToString(new String(username + ":" + password).getBytes(), Base64.NO_WRAP)); try {//from w w w. j av a 2s . co m HttpResponse httpResponse = urlopen.openAsHttpResponse(API_URL + "account/overview/all", new ArrayList<NameValuePair>(), false); if (httpResponse.getStatusLine().getStatusCode() == 401) { throw new LoginException(context.getText(R.string.invalid_username_password).toString()); } ObjectMapper vObjectMapper = new ObjectMapper(); AccountOverview r = vObjectMapper.readValue(httpResponse.getEntity().getContent(), AccountOverview.class); for (com.liato.bankdroid.banking.banks.avanza.model.Account account : r.getAccounts()) { Account a = new Account(account.getAccountName(), new BigDecimal(account.getOwnCapital()), account.getAccountId()); if (!account.getCurrencyAccounts().isEmpty()) { a.setCurrency(account.getCurrencyAccounts().get(0).getCurrency()); } if (!account.getPositionAggregations().isEmpty()) { Date now = new Date(); ArrayList<Transaction> transactions = new ArrayList<Transaction>(); for (PositionAggregation positionAgList : account.getPositionAggregations()) { if (positionAgList.getPositions().isEmpty()) { continue; } List<Position> positions = positionAgList.getPositions(); transactions.add(new Transaction(Helpers.formatDate(now), "\u2014 " + positionAgList.getInstrumentTypeName() + " " + positionAgList.getTotalProfitPercent() + "% \u2014", BigDecimal.valueOf(positionAgList.getTotalValue()), a.getCurrency())); for (Position p : positions) { Transaction t = new Transaction(Helpers.formatDate(now), p.getInstrumentName(), BigDecimal.valueOf(p.getProfit()), a.getCurrency()); transactions.add(t); } } a.setTransactions(transactions); } accounts.add(a); } } catch (JsonParseException e) { e.printStackTrace(); throw new BankException(e.getMessage()); } catch (ClientProtocolException e) { e.printStackTrace(); throw new BankException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new BankException(e.getMessage()); } return urlopen; }
From source file:de.audioattack.yacy32c3search.activity.SettingsDialog.java
public static String load(final Context context, final String key, String dflt) { final SharedPreferences sharedPreferences = context.getSharedPreferences("settings", Context.MODE_PRIVATE); final String base64Value = sharedPreferences.getString(key, ""); final String value; if (base64Value.length() == 0) { value = dflt;/*from w w w . j a v a 2 s. c om*/ } else { value = new String(Base64.decode(base64Value, Base64.NO_WRAP)); } return value; }
From source file:com.example.androidthings.doorbell.DoorbellEntryAdapter.java
@Override protected void populateViewHolder(DoorbellEntryViewHolder viewHolder, DoorbellEntry model, int position) { // Display the timestamp CharSequence prettyTime = DateUtils.getRelativeDateTimeString(mApplicationContext, model.getTimestamp(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0); viewHolder.time.setText(prettyTime); // Display the image if (model.getImage() != null) { // Decode image data encoded by the Cloud Vision library byte[] imageBytes = Base64.decode(model.getImage(), Base64.NO_WRAP | Base64.URL_SAFE); Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); if (bitmap != null) { viewHolder.image.setImageBitmap(bitmap); } else {//from w w w. j a v a 2 s. c o m Drawable placeholder = ContextCompat.getDrawable(mApplicationContext, R.drawable.ic_image); viewHolder.image.setImageDrawable(placeholder); } } // Display the metadata if (model.getAnnotations() != null) { ArrayList<String> keywords = new ArrayList<>(model.getAnnotations().keySet()); int limit = Math.min(keywords.size(), 3); viewHolder.metadata.setText(TextUtils.join("\n", keywords.subList(0, limit))); } else { viewHolder.metadata.setText("no annotations yet"); } }
From source file:de.knufficast.flattr.FlattrApi.java
private void login() { try {/*from ww w . ja v a 2 s . c o m*/ JSONObject json = new JSONObject(); json.put("code", config.getAuthCode()); json.put("grant_type", "authorization_code"); json.put("redirect_uri", "knufficastoauth://"); // the client ID and secret are used as username and password // encode username and password using base64 user:password (BASIC auth for // http) String userPassword = "Basic " + new String(Base64.encode( (CONSTANTS.getClientId() + ":" + CONSTANTS.getClientSecret()).getBytes(), Base64.NO_WRAP)); JSONObject response = postAuthorized(LOGIN_URL, json, userPassword); if (response.getString("access_token") != null) { config.setAccessToken(response.getString("access_token")); config.setFlattrStatus(FlattrStatus.AUTHENTICATED); } else { config.resetAuthentication(); } } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { config.resetAuthentication(); } }
From source file:net.networksaremadeofstring.cyllell.Authentication.java
private String SignHeaders(String dataToSign) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException, NoSuchProviderException { PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(Base64.decode(this.PrivateKey.getBytes(), 0)); KeyFactory kf = KeyFactory.getInstance("RSA"); PrivateKey pk = kf.generatePrivate(spec); Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING"); cipher.init(Cipher.ENCRYPT_MODE, pk); byte[] EncryptedStream = new byte[cipher.getOutputSize(dataToSign.length())]; try {/*from w w w . j a v a2s . c o m*/ cipher.doFinal(dataToSign.getBytes(), 0, dataToSign.length(), EncryptedStream, 0); } catch (ShortBufferException e) { // TODO Auto-generated catch block e.printStackTrace(); } return Base64.encodeToString(EncryptedStream, Base64.NO_WRAP); }
From source file:com.tapcentive.sdk.service.CouponStatusService.java
/** * Execute.//from ww w . ja v a2 s .c o m * * @param coupon the coupon */ public void execute(byte[] coupon) { Map<String, String> headers = new HashMap<String, String>(); JSONObject jsonCoupon = new JSONObject(); if (isConnectedToNetwork()) { try { headers.put("User-Agent", "consumer"); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this.context); String msiURLString = sharedPref.getString("pref_key_msi_url", ""); if ((msiURLString != null) && (!msiURLString.equals(""))) { String url = msiURLString + "/reward/status"; jsonCoupon.put("timestamp", (long) System.currentTimeMillis() / 1000); jsonCoupon.put("apdu", Base64.encodeToString(coupon, Base64.NO_WRAP)); Log.d(TAG, "Coupon Data: " + Base64.encodeToString(coupon, Base64.NO_WRAP)); CustomJsonObjectRequest jsonRequest = new CustomJsonObjectRequest(Method.POST, url, jsonCoupon, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.d(TAG, "Redeemable" + response.toString()); callback.isValid(true); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "Error " + error.toString()); if (error == null || error.networkResponse == null) { callback.isValid(true); return; } if (error.networkResponse.statusCode == 400 || error.networkResponse.statusCode == 204 || error.networkResponse.statusCode == 403) { Response<JSONObject> response = CustomJsonObjectRequest.parseError(error); try { int detailcode = response.result.getInt("detailcode"); String extraDetails = response.result.getString("details"); Log.d(TAG, "Got an error: " + error.networkResponse.statusCode + " Detail Code from MSI: " + detailcode + " Extra Details: " + extraDetails); } catch (JSONException e) { e.printStackTrace(); } callback.isValid(false); /*TapcentiveConfig config = TapcentiveLibrary.getInstance().getConfig(); if(config.getCallback() != null) { config.getCallback().onTapcentiveError(new TapcentiveError(TapcentiveErrorType.TapcentiveUnexpectedError)); }*/ return; } } }, headers); // Add the request to the queue and execute getRequestQueue().add(jsonRequest); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); Log.d(TAG, "Exception" + e.toString()); callback.isValid(true); TapcentiveConfig config = TapcentiveLibrary.getInstance().getConfig(); if (config.getCallback() != null) { config.getCallback().onTapcentiveError( new TapcentiveError(this.context, TapcentiveErrorType.TapcentiveUnexpectedError)); } } } else { TapcentiveConfig config = TapcentiveLibrary.getInstance().getConfig(); if (config.getCallback() != null) { config.getCallback().onTapcentiveError( new TapcentiveError(this.context, TapcentiveErrorType.TapcentiveNetworkUnavailable)); } } }
From source file:com.mimo.service.api.MimoHttpConnection.java
/** * Function for Making HTTP "post" request and getting server response. * /*from w ww . j a v a 2 s . c o m*/ * @param p_url * - Http Url * @throws ClientProtocolException * @throws IOException * @return HttpResponse- Returns the HttpResponse. */ public static synchronized HttpResponse getHttpTransferUrlConnection(String p_url) throws ClientProtocolException, IOException // throws // CustomException { DefaultHttpClient m_httpClient = new DefaultHttpClient(); HttpPost m_post = new HttpPost(p_url); String m_authString = MimoAPIConstants.USERNAME + ":" + MimoAPIConstants.PASSWORD; String m_authStringEnc = Base64.encodeToString(m_authString.getBytes(), Base64.NO_WRAP); m_post.addHeader(MimoAPIConstants.HEADER_TEXT_AUTHORIZATION, MimoAPIConstants.HEADER_TEXT_BASIC + m_authStringEnc); HttpResponse m_response = null; try { m_response = m_httpClient.execute(m_post); } catch (IllegalStateException e) { if (MimoAPIConstants.DEBUG) { Log.e(TAG, e.getMessage()); } } return m_response; }
From source file:edu.umich.eecs.lab11.summon.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.init(); wv = ((WebView) appView.getEngine().getView()); wv.addJavascriptInterface(new JavaScriptInterface(getPackageManager()), "gateway"); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setSupportMultipleWindows(false); wv.getSettings().setNeedInitialFocus(false); wv.getSettings().setSupportZoom(false); wv.getSettings().setAllowFileAccess(true); wv.getSettings().setAppCacheEnabled(true); wv.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); wv.getSettings().setAppCachePath(wv.getContext().getCacheDir().getAbsolutePath()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) setTaskDescription(new TaskDescription(null, null, Color.parseColor("#FFC107"))); loadUrl(launchUrl);/*from w w w . j a va2 s.c om*/ try { InputStream is = getAssets().open("www/summon.android.js"); byte[] buffer = new byte[is.available()]; is.read(buffer); is.close(); js = "javascript:(function(){ " + "s=document.createElement('script');" + "s.innerHTML = atob('" + Base64.encodeToString(buffer, Base64.NO_WRAP) + "'); " + "document.querySelector('head').appendChild(s); " + "})()"; } catch (Exception e) { e.printStackTrace(); } }
From source file:com.parse.ParseDecoder.java
public Object decode(Object object) { if (object instanceof JSONArray) { return convertJSONArrayToList((JSONArray) object); }//from w w w . ja v a2 s . c om if (!(object instanceof JSONObject)) { return object; } JSONObject jsonObject = (JSONObject) object; String opString = jsonObject.optString("__op", null); if (opString != null) { try { return ParseFieldOperations.decode(jsonObject, this); } catch (JSONException e) { throw new RuntimeException(e); } } String typeString = jsonObject.optString("__type", null); if (typeString == null) { return convertJSONObjectToMap(jsonObject); } if (typeString.equals("Date")) { String iso = jsonObject.optString("iso"); return ParseDateFormat.getInstance().parse(iso); } if (typeString.equals("Bytes")) { String base64 = jsonObject.optString("base64"); return Base64.decode(base64, Base64.NO_WRAP); } if (typeString.equals("Pointer")) { return decodePointer(jsonObject.optString("className"), jsonObject.optString("objectId")); } if (typeString.equals("File")) { return new ParseFile(jsonObject, this); } if (typeString.equals("GeoPoint")) { double latitude, longitude; try { latitude = jsonObject.getDouble("latitude"); longitude = jsonObject.getDouble("longitude"); } catch (JSONException e) { throw new RuntimeException(e); } return new ParseGeoPoint(latitude, longitude); } if (typeString.equals("Object")) { return ParseObject.fromJSON(jsonObject, null, true, this); } if (typeString.equals("Relation")) { return new ParseRelation<>(jsonObject, this); } if (typeString.equals("OfflineObject")) { throw new RuntimeException("An unexpected offline pointer was encountered."); } return null; }
From source file:com.liferay.mobile.android.util.PortraitUtil.java
protected static void appendToken(StringBuilder sb, String uuid) { if (Validator.isNull(uuid)) { return;// ww w.ja va 2s . co m } try { MessageDigest digest = MessageDigest.getInstance("SHA-1"); digest.update(uuid.getBytes()); byte[] bytes = digest.digest(); String token = null; try { token = Base64.encodeToString(bytes, Base64.NO_WRAP); } catch (RuntimeException re) { if ("Stub!".equals(re.getMessage())) { token = org.apache.commons.codec.binary.Base64.encodeBase64String(bytes); } } if (token != null) { sb.append("&img_id_token="); sb.append(URLEncoder.encode(token, "UTF8")); } } catch (Exception e) { Log.e(_CLASS_NAME, "Couldn't generate portrait image token", e); } }