Example usage for android.util Base64InputStream Base64InputStream

List of usage examples for android.util Base64InputStream Base64InputStream

Introduction

In this page you can find the example usage for android.util Base64InputStream Base64InputStream.

Prototype

public Base64InputStream(InputStream in, int flags) 

Source Link

Document

An InputStream that performs Base64 decoding on the data read from the wrapped stream.

Usage

From source file:Main.java

public static Object stringToObject(String encodedObject) {
    try {//  w  w  w  .j  a v  a2  s . c  o  m
        return new ObjectInputStream(
                new Base64InputStream(new ByteArrayInputStream(encodedObject.getBytes()), Base64.DEFAULT))
                        .readObject();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

/**
 * Deserialize provided string into Object
 * @param serialized String//from  w  w w .ja va2  s. com
 * @return Object
 * @throws IOException If unable to access Stream
 * @throws ClassNotFoundException If unable to find class
 */
public static Object deserialize(String serialized) throws IOException, ClassNotFoundException {
    if (serialized == null)
        return null;
    return new ObjectInputStream(new Base64InputStream(new ByteArrayInputStream(serialized.getBytes()), 0))
            .readObject();
}

From source file:com.Anderson.example.games.tanc.GameplayFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d("I", "Quase la");
    View v = inflater.inflate(R.layout.fragment_gameplay, container, false);
    mTimer = (TextView) v.findViewById(R.id.timer_field);
    Log.d("I", mTimer.getText().toString() + "WW");
    ObjectMapper mapper = new ObjectMapper();
    mCurrentQuestion = 0;/*  w  w w .j  av  a  2  s.co  m*/
    Log.d("I", "Quase la2");
    try {
        InputStream myFile = getActivity().getAssets().open("texts/" + mListener.onQuestionaryAsk());
        Log.d("I", "Quase la3");
        Base64InputStream bs = new Base64InputStream(myFile, 80);
        JsonNode actualObj = mapper.readTree(bs);
        AssignToQuestionary(actualObj);
        Log.d("I", actualObj.toString());

    } catch (IOException e) {
        e.printStackTrace();
    }
    if (mListener.onQuestionaryAsk().contains("Timer")) {
        SetTimer();
        myCDT.start();
        isTimer = true;
    }
    if (mListener.onQuestionaryAsk().contains("Multiple")) {
        isMultiple = true;
        mRequestedScore = 20;
        TextView scoreInput = ((TextView) getActivity().findViewById(R.id.score_text));
        if (scoreInput != null)
            scoreInput.setText("Score: " + 20);
    }
    ManageButtons(v);
    return v;
}

From source file:net.sourcewalker.garanbot.api.ItemService.java

public Bitmap getPicture(int id) throws ClientException {
    try {// w  w  w  . j  a  v a  2  s. c o m
        HttpResponse response = client.get("/item/" + id + "/picture");
        int statusCode = response.getStatusLine().getStatusCode();
        switch (statusCode) {
        case HttpStatus.SC_OK:
            Base64InputStream stream = new Base64InputStream(response.getEntity().getContent(), Base64.DEFAULT);
            Bitmap result = BitmapFactory.decodeStream(stream);
            if (result == null) {
                throw new ClientException("Picture could not be decoded!");
            }
            return result;
        case HttpStatus.SC_NOT_FOUND:
            return null;
        default:
            throw new ClientException("Got HTTP error: " + response.getStatusLine().toString());
        }
    } catch (IOException e) {
        throw new ClientException("IO error: " + e.getMessage(), e);
    }
}

From source file:com.breadwallet.tools.manager.SharedPreferencesManager.java

@SuppressWarnings("unchecked")
public static Set<CurrencyEntity> getExchangeRates(Activity context) {
    SharedPreferences prefs = context.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE);

    byte[] bytes = prefs.getString(BRConstants.EXCHANGE_RATES, "{}").getBytes();
    if (bytes.length == 0) {
        return null;
    }/*  w  w  w.  j  av a2  s  .  c o  m*/
    Set<CurrencyEntity> result = null;
    ByteArrayInputStream byteArray = new ByteArrayInputStream(bytes);
    Base64InputStream base64InputStream = new Base64InputStream(byteArray, Base64.NO_WRAP);
    ObjectInputStream in;
    try {
        in = new ObjectInputStream(base64InputStream);

        result = (Set<CurrencyEntity>) in.readObject();
    } catch (IOException | ClassNotFoundException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.android.email.mail.internet.MimeUtility.java

/**
 * Removes any content transfer encoding from the stream and returns a Body.
 *///from w  w w.  j a  v a 2  s.  c om
public static Body decodeBody(InputStream in, String contentTransferEncoding) throws IOException {
    /*
     * We'll remove any transfer encoding by wrapping the stream.
     */
    if (contentTransferEncoding != null) {
        contentTransferEncoding = MimeUtility.getHeaderParameter(contentTransferEncoding, null);
        if ("quoted-printable".equalsIgnoreCase(contentTransferEncoding)) {
            in = new QuotedPrintableInputStream(in);
        } else if ("base64".equalsIgnoreCase(contentTransferEncoding)) {
            in = new Base64InputStream(in, Base64.DEFAULT);
        }
    }

    BinaryTempFileBody tempBody = new BinaryTempFileBody();
    OutputStream out = tempBody.getOutputStream();
    IOUtils.copy(in, out);
    out.close();
    return tempBody;
}

From source file:com.android.emailcommon.internet.MimeUtility.java

/**
 * Given an input stream and a transfer encoding, return a wrapped input stream for that
 * encoding (or the original if none is required)
 * @param in the input stream//from w  w  w .  j  av  a  2s .com
 * @param contentTransferEncoding the content transfer encoding
 * @return a properly wrapped stream
 */
public static InputStream getInputStreamForContentTransferEncoding(InputStream in,
        String contentTransferEncoding) {
    if (contentTransferEncoding != null) {
        contentTransferEncoding = MimeUtility.getHeaderParameter(contentTransferEncoding, null);
        if ("quoted-printable".equalsIgnoreCase(contentTransferEncoding)) {
            in = new QuotedPrintableInputStream(in);
        } else if ("base64".equalsIgnoreCase(contentTransferEncoding)) {
            in = new Base64InputStream(in, Base64.DEFAULT);
        }
    }
    return in;
}

From source file:email.schaal.ocreader.ListActivity.java

private void updateUserProfile() {
    final String username = Preferences.USERNAME.getString(PreferenceManager.getDefaultSharedPreferences(this));

    User user = null;// w ww  . jav a 2s  . co  m

    if (username != null)
        user = getRealm().where(User.class).equalTo(User.USER_ID, username).findFirst();

    if (user != null) {
        profileDrawerItem.withName(user.getDisplayName());
        String encodedImage = user.getAvatar();
        if (encodedImage != null) {
            Bitmap avatarBitmap = BitmapFactory.decodeStream(
                    new Base64InputStream(new ByteArrayInputStream(encodedImage.getBytes()), Base64.DEFAULT));
            profileDrawerItem.withIcon(avatarBitmap);
        } else {
            profileDrawerItem.withIcon(R.drawable.ic_launcher);
        }
        if (accountHeader != null)
            accountHeader.updateProfile(profileDrawerItem);
    } else {
        profileDrawerItem.withIcon(R.drawable.ic_launcher);
    }
}