List of usage examples for android.util Base64 decode
public static byte[] decode(byte[] input, int flags)
From source file:net.inbox.InboxMessage.java
/** * Continues the file saving process./* www .j a v a 2 s.c o m*/ * Convert attachments from BASE64 to normal. **/ public void write_attachment_from_db() { // Offline IMAP attachment file can give errors if (imap_or_pop) { Pattern pat = Pattern.compile(".*boundary=\"(.*)\".*", Pattern.CASE_INSENSITIVE); Matcher mat = pat.matcher(current.get_content_type()); if (mat.matches()) { chosen_att.set_boundary("--" + mat.group(1)); chosen_att.set_pop_indx(chosen_att.get_imap_uid()); } else { Pager.log += getString(R.string.err_imap_attachment_saving) + "\n\n"; Dialogs.dialog_error_line(getString(R.string.err_imap_attachment_saving), this); return; } } String att; if (msg_encrypted && crypto_locked) { att = Utils.mime_part_section(current.get_contents_crypto(), chosen_att.get_pop_indx(), chosen_att.get_boundary()); } else { att = Utils.mime_part_section(current.get_full_msg(), chosen_att.get_pop_indx(), chosen_att.get_boundary()); } try { FileOutputStream f_stream = new FileOutputStream( new File(chosen_folder.getAbsoluteFile() + "/" + chosen_att.get_name())); // Converting transfer encoding if (chosen_att != null) { // Parsing file download if (chosen_att.get_transfer_encoding().equalsIgnoreCase("BASE64")) { boolean CR = false; StringBuilder sb_tmp = new StringBuilder(0); for (int i = 0; i < att.length(); ++i) { if (att.charAt(i) == '\n') { if (CR) { f_stream.write(Base64.decode(sb_tmp.toString().getBytes(), Base64.DEFAULT)); sb_tmp.setLength(0); CR = false; } } else if (att.charAt(i) == '\r') { CR = true; } else if (att.charAt(i) != '=') { sb_tmp.append(att.charAt(i)); CR = false; } } if (sb_tmp.length() > 0) { f_stream.write(Base64.decode(sb_tmp.toString().getBytes(), Base64.DEFAULT)); } f_stream.close(); } else { // 7BIT, 8BIT, BINARY, QUOTED-PRINTABLE f_stream.write(att.getBytes()); f_stream.close(); } } } catch (IOException e) { Pager.log += e.getMessage() + "\n\n"; Dialogs.dialog_exception(e, this); } }
From source file:com.olacabs.customer.ui.TrackRideActivity.java
protected Bitmap m13976a(String str) { Bitmap bitmap;//from w ww . j a va 2s .c o m List<CabImages> list = Ola.f11488e; Bitmap bitmap2 = null; if (list == null || list.size() == 0 || str == null) { bitmap = null; } else { for (CabImages cabImages : list) { if (str.equalsIgnoreCase(cabImages.getId()) || (str.equalsIgnoreCase("ANY") && cabImages.getId().equalsIgnoreCase("economy_sedan"))) { byte[] decode = Base64.decode(cabImages.getData().getBytes(), 0); bitmap = BitmapFactoryInstrumentation.decodeByteArray(decode, 0, decode.length); } else { bitmap = bitmap2; } bitmap2 = bitmap; } bitmap = bitmap2; } if (bitmap != null) { return bitmap; } if ("local_taxi".equalsIgnoreCase(this.f10204k.getCategory_id())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_kp_car_front)).getBitmap(); } if ("local_auto".equalsIgnoreCase(this.f10204k.getCategory_id())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_booking_auto_map)).getBitmap(); } if (!"delivery".equalsIgnoreCase(this.f10204k.getCategory_id())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_cab_top_view)).getBitmap(); } if ("bg_style_myntra".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.style_myntra_map)).getBitmap(); } if ("bg_delivery_electronic".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.electronic_map)).getBitmap(); } if ("bg_xmas_1".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.xmas_1_map)).getBitmap(); } if ("bg_xmas_2".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.xmas_2_map)).getBitmap(); } if ("bg_movie".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.movie_map)).getBitmap(); } if ("bg_marketing_default".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_cab_top_view)).getBitmap(); } if ("bg_comicon".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.comic_map)).getBitmap(); } if ("bg_ipl".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.ipl_map)).getBitmap(); } if ("bg_fathersday".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.fathersday)).getBitmap(); } if ("bg_olanight".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.olanight)).getBitmap(); } if ("bg_envday".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.envday)).getBitmap(); } if ("bg_carshare".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_cab_top_view)).getBitmap(); } if ("bg_donorsday".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.donorsday)).getBitmap(); } if ("bg_myntra".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.myntra_map)).getBitmap(); } if ("bg_access".equalsIgnoreCase(this.f10204k.getImage_name())) { return ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_cab_top_view)).getBitmap(); } return ((BitmapDrawable) getResources().getDrawable(R.drawable.ic_cab_top_view)).getBitmap(); }
From source file:com.creativtrendz.folio.ui.FolioWebViewScroll.java
protected static String decodeBase64(final String base64) throws IllegalArgumentException, UnsupportedEncodingException { final byte[] bytes = Base64.decode(base64, Base64.DEFAULT); return new String(bytes, CHARSET_DEFAULT); }
From source file:org.apache.cordova.FileUtils.java
/** * Write contents of file./*from w w w .j a v a2s . c o m*/ * * @param filename The name of the file. * @param data The contents of the file. * @param offset The position to begin writing the file. * @param isBinary True if the file contents are base64-encoded binary data * @throws FileNotFoundException, IOException * @throws NoModificationAllowedException */ /**/ public long write(String filename, String data, int offset, boolean isBinary) throws FileNotFoundException, IOException, NoModificationAllowedException { if (filename.startsWith("content://")) { throw new NoModificationAllowedException("Couldn't write to file given its content URI"); } filename = FileHelper.getRealPath(filename, cordova); boolean append = false; if (offset > 0) { this.truncateFile(filename, offset); append = true; } byte[] rawData; if (isBinary) { rawData = Base64.decode(data, Base64.DEFAULT); } else { rawData = data.getBytes(); } ByteArrayInputStream in = new ByteArrayInputStream(rawData); try { FileOutputStream out = new FileOutputStream(filename, append); byte buff[] = new byte[rawData.length]; in.read(buff, 0, buff.length); out.write(buff, 0, rawData.length); out.flush(); out.close(); } catch (NullPointerException e) { // This is a bug in the Android implementation of the Java Stack NoModificationAllowedException realException = new NoModificationAllowedException(filename); throw realException; } return rawData.length; }
From source file:org.apache.cordova.core.FileUtils.java
/** * Write contents of file.//from w w w .j a va2 s .c o m * * @param filename The name of the file. * @param data The contents of the file. * @param offset The position to begin writing the file. * @param isBinary True if the file contents are base64-encoded binary data * @throws FileNotFoundException, IOException * @throws NoModificationAllowedException */ /**/ public long write(String filename, String data, int offset, boolean isBinary) throws FileNotFoundException, IOException, NoModificationAllowedException { if (filename.startsWith("content://")) { throw new NoModificationAllowedException("Couldn't write to file given its content URI"); } filename = FileHelper.getRealPath(filename, cordova); boolean append = false; if (offset > 0) { this.truncateFile(filename, offset); append = true; } byte[] rawData; if (isBinary) { rawData = Base64.decode(data, Base64.DEFAULT); } else { rawData = data.getBytes(); } ByteArrayInputStream in = new ByteArrayInputStream(rawData); FileOutputStream out = new FileOutputStream(filename, append); byte buff[] = new byte[rawData.length]; in.read(buff, 0, buff.length); out.write(buff, 0, rawData.length); out.flush(); out.close(); return rawData.length; }
From source file:com.ruesga.rview.fragments.FileDiffViewerFragment.java
@SuppressWarnings("ConstantConditions") private File fetchCachedContent(String changeId, String revision, String base) { String b = base == null ? "0" : base; String name = b + "_" + mFileHash + "_" + CacheHelper.CACHE_CONTENT; File fetchedFile = new File(CacheHelper.getAccountDiffCacheDir(getContext()), name); if (!fetchedFile.exists()) { try {//from w w w. j av a 2 s. co m final Context ctx = getActivity(); final GerritApi api = ModelHelper.getGerritApi(ctx); ResponseBody content = api.getChangeRevisionFileContent(changeId, revision, mFile).blockingFirst(); CacheHelper.writeAccountDiffCacheFile(getContext(), mAccount, name, Base64.decode(content.bytes(), Base64.NO_WRAP)); } catch (Exception ex) { Log.e(TAG, "Can't download file content " + mFile + "; Revision: " + revision, ex); fetchedFile = null; } } return fetchedFile; }
From source file:com.ruesga.rview.fragments.EditorFragment.java
private byte[] readEditContent(String file) throws IOException { byte[] o = CacheHelper.readAccountDiffCacheFile(getContext(), getEditCachedFileName(file)); if (o == null || o.length == 0) { return new byte[0]; }/*from w ww .j a v a 2 s.c om*/ return Base64.decode(o, Base64.NO_WRAP); }
From source file:com.imaginamos.taxisya.taxista.activities.RegisterDriverActivity.java
private void setThumbnailImageStorage(ImageView mImageView, String imageString) { // Get the dimensions of the View int targetW = mImageView.getWidth(); int targetH = mImageView.getHeight(); // Get the dimensions of the bitmap BitmapFactory.Options bmOptions = new BitmapFactory.Options(); bmOptions.inJustDecodeBounds = true; //BitmapFactory.decodeFile(imagePat, bmOptions); int photoW = bmOptions.outWidth; int photoH = bmOptions.outHeight; // Determine how much to scale down the image int scaleFactor = Math.min(photoW / targetW, photoH / targetH); // Decode the image file into a Bitmap sized to fill the View bmOptions.inJustDecodeBounds = false; bmOptions.inSampleSize = scaleFactor; bmOptions.inPurgeable = true;/*from www . j av a 2 s. co m*/ // Bitmap bitmap = decodeBase64(imageString)); byte[] b = Base64.decode(imageString, Base64.DEFAULT); InputStream is = new ByteArrayInputStream(b); //Bitmap bitmap = BitmapFactory.decodeStream(is, bmOptions); Bitmap bitmap = BitmapFactory.decodeFile(imageString, bmOptions); mImageView.setImageBitmap(bitmap); }
From source file:com.cloudant.sync.cordova.CloudantSyncPlugin.java
/** * @param docRevisionJSON - The JSONObject to transform * @return - The DocumentRevision from the converted JSONObject * @throws Exception//from ww w . j a va2s . co m */ private DocumentRevision buildDocRevision(JSONObject docRevisionJSON) throws Exception { if (docRevisionJSON == null) throw new Exception("Document revision cannot be null"); String docId = null; String docRev = null; DocumentBody body; if (docRevisionJSON.has(DOC_ID)) { docId = (String) docRevisionJSON.get(DOC_ID); } if (docRevisionJSON.has(DOC_REV)) { docRev = (String) docRevisionJSON.get(DOC_REV); } DocumentRevision revision = new DocumentRevision(docId, docRev); if (docRevisionJSON.has(DOC_DELETED) && docRevisionJSON.getBoolean(DOC_DELETED)) { revision.setDeleted(); } Map<String, Attachment> attachmentMap = null; if (docRevisionJSON.has(DOC_ATTACHMENTS)) { JSONObject attachments = docRevisionJSON.getJSONObject(DOC_ATTACHMENTS); docRevisionJSON.remove(DOC_ATTACHMENTS); attachmentMap = new HashMap<String, Attachment>(); Iterator<String> keys = attachments.keys(); while (keys.hasNext()) { String name = keys.next(); JSONObject attachment = attachments.getJSONObject(name); String contentType = attachment.getString(DOC_ATTACHMENTS_CONTENT_TYPE); String data = attachment.getString("data"); byte[] bytes = Base64.decode(data, Base64.NO_WRAP); UnsavedStreamAttachment streamAttachment = new UnsavedStreamAttachment( new ByteArrayInputStream(bytes), contentType); attachmentMap.put(name, streamAttachment); } revision.setAttachments(attachmentMap); } revision.setBody(DocumentBodyFactory.create(getMapFromJSONObject(docRevisionJSON))); return revision; }