Example usage for android.util Base64 NO_WRAP

List of usage examples for android.util Base64 NO_WRAP

Introduction

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

Prototype

int NO_WRAP

To view the source code for android.util Base64 NO_WRAP.

Click Source Link

Document

Encoder flag bit to omit all line terminators (i.e., the output will be on one long line).

Usage

From source file:com.hujiang.restvolley.webapi.request.JsonStreamerEntity.java

private void writeToFromStream(OutputStream os, StreamWrapper entry) throws IOException {

    // Send the meta data.
    writeMetaData(os, entry.name, entry.contentType);

    int bytesRead;

    // Upload the file's contents in Base64.
    Base64OutputStream bos = new Base64OutputStream(os, Base64.NO_CLOSE | Base64.NO_WRAP);

    // Read from input stream until no more data's left to read.
    while ((bytesRead = entry.inputStream.read(buffer)) != -1) {
        bos.write(buffer, 0, bytesRead);
    }/*from  w  w w  .j a  v  a  2  s . com*/

    // Close the Base64 output stream.
    if (bos != null) {
        bos.close();
    }

    // End the meta data.
    endMetaData(os);

    // Close input stream.
    if (entry.autoClose) {
        // Safely close the input stream.
        if (entry.inputStream != null) {
            entry.inputStream.close();
        }
    }
}

From source file:com.adjust.sdk.PackageBuilder.java

private void addMapBase64(Map<String, String> parameters, String key, Map<String, String> map) {
    if (null == map) {
        return;/*ww w  .  ja  v  a  2s  .c om*/
    }

    JSONObject jsonObject = new JSONObject(map);
    byte[] jsonBytes = jsonObject.toString().getBytes();
    String encodedMap = Base64.encodeToString(jsonBytes, Base64.NO_WRAP);

    addString(parameters, key, encodedMap);
}

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

public static void putExchangeRates(Activity activity, Set<CurrencyEntity> rates) {
    SharedPreferences prefs = activity.getSharedPreferences(BRConstants.PREFS_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.remove(BRConstants.EXCHANGE_RATES);
    ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();

    ObjectOutputStream objectOutput;
    try {//w  w w .  j  a  v  a  2 s. c o m
        objectOutput = new ObjectOutputStream(arrayOutputStream);
        objectOutput.writeObject(rates);
        byte[] data = arrayOutputStream.toByteArray();
        objectOutput.close();
        arrayOutputStream.close();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Base64OutputStream b64 = new Base64OutputStream(out, Base64.NO_WRAP);
        b64.write(data);
        b64.close();
        out.close();
        editor.putString(BRConstants.EXCHANGE_RATES, new String(out.toByteArray()));

        editor.apply();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.hujiang.restvolley.webapi.request.JsonStreamerEntity.java

private void writeToFromFile(OutputStream os, FileWrapper wrapper) throws IOException {

    // Send the meta data.
    writeMetaData(os, wrapper.file.getName(), wrapper.contentType);

    int bytesRead;

    // Open the file for reading.
    FileInputStream in = new FileInputStream(wrapper.file);

    // Upload the file's contents in Base64.
    Base64OutputStream bos = new Base64OutputStream(os, Base64.NO_CLOSE | Base64.NO_WRAP);

    // Read from file until no more data's left to read.
    while ((bytesRead = in.read(buffer)) != -1) {
        bos.write(buffer, 0, bytesRead);
    }/*  w w  w .j  av  a2s  . c  o m*/

    // Close the Base64 output stream.
    if (bos != null) {
        bos.close();
    }

    // End the meta data.
    endMetaData(os);

    // Safely close the input stream.
    if (in != null) {
        in.close();
    }
}

From source file:org.openmidaas.library.MIDaaS.java

private static String getJWS(String body) throws JSONException, UnsupportedEncodingException {
    JSONObject header = new JSONObject();
    header.put("alg", "none");
    return (Base64.encodeToString(header.toString().getBytes("UTF-8"), Base64.NO_PADDING + Base64.NO_WRAP) + "."
            + Base64.encodeToString(body.getBytes("UTF-8"), Base64.NO_PADDING + Base64.NO_WRAP) + ".");
}

From source file:com.vanda.beivandalibnetwork.utils.HttpUtils.java

/**
 * /*from  w ww  . j  a v a 2  s .  c o  m*/
 * 
 * @param request
 * @param username
 * @param password
 * @return
 */
@TargetApi(Build.VERSION_CODES.FROYO)
public static HttpUriRequest authenticate(HttpUriRequest request, String username, String password) {
    request.addHeader(HEADER_AUTHORIZATION,
            AUTH_METHOD_BASIC + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP));
    return request;
}

From source file:com.cyanogenmod.account.util.CMAccountUtils.java

public static byte[] getHmacSecret(AccountManager accountManager, Account account) {
    if (account == null) {
        if (CMAccount.DEBUG)
            Log.d(TAG, "No CMAccount configured!");
        return null;
    }//from   ww  w  .  j ava  2  s.co  m
    return Base64.decode(accountManager.getUserData(account, CMAccount.ACCOUNT_EXTRA_HMAC_SECRET),
            Base64.NO_WRAP);
}

From source file:fm.krui.kruifm.TwitterManager.java

/**
 * Encodes consumer key and consumer secret using RFC 1783 and formats the result according
 * to Twitter's requirements for authorization.
 * @param consumerKey Consumer Key//from w w  w  .  ja  v  a 2s. co  m
 * @param consumerSecret Consumer Secret
 * @return Processed string
 */
private String encodeCredentials(String consumerKey, String consumerSecret) {

    // Encode credentials according to RFC 1739
    String consumerKey1379 = null;
    String consumerSecret1379 = null;
    try {
        consumerKey1379 = URLEncoder.encode(consumerKey, "UTF-8");
        consumerSecret1379 = URLEncoder.encode(consumerSecret, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "Could not encode auth credentials!");
        e.printStackTrace();
    }

    // Concatenate the encoded consumer key and secret with a colon
    String singleKey = consumerKey1379 + ":" + consumerSecret1379;

    // Encode single key using base64 and return result
    byte[] keyBytes = singleKey.getBytes();
    String finalKey = Base64.encodeToString(keyBytes, Base64.NO_WRAP);
    Log.v(TAG, "Final key created: " + finalKey);
    return finalKey;
}

From source file:io.winch.phonegap.plugin.WinchPlugin.java

private void getBase64(CallbackContext callbackContext, JSONArray args) {
    try {/*from   w  w w . j  a  v  a2 s  .  c  o  m*/
        String namespace = args.getString(0);
        String key = args.getString(1);
        byte[] value = mWinch.getNamespace(namespace).get(key);
        String base64 = Base64.encodeToString(value, Base64.NO_WRAP);

        PluginResult pr = new PluginResult(PluginResult.Status.OK, base64);
        callbackContext.sendPluginResult(pr);
    } catch (WinchError e) {
        e.printStackTrace();
        PluginResult r = buildErrorResult(e.getErrorCode(), e.getMessage());
        callbackContext.sendPluginResult(r);
    } catch (JSONException e1) {
        e1.printStackTrace();
    }
}

From source file:au.com.wallaceit.reddinator.RedditData.java

private JSONObject getJSONFromPost(String url, ArrayList<NameValuePair> data, boolean addOauthHeaders)
        throws RedditApiException {
    JSONObject jObj = new JSONObject();
    String json;//from  w  ww  . jav a  2s  .c o m
    InputStream is = null;
    // create client if null
    if (httpclient == null) {
        createHttpClient();
    }
    try {
        HttpPost httppost = new HttpPost(url);
        if (addOauthHeaders) {
            // For oauth token retrieval and refresh
            httppost.addHeader("Authorization", "Basic " + Base64
                    .encodeToString((OAUTH_CLIENTID + ":").getBytes(), Base64.URL_SAFE | Base64.NO_WRAP));
        } else if (isLoggedIn()) {
            if (isTokenExpired()) {
                refreshToken();
            }
            String tokenStr = getTokenValue("token_type") + " " + getTokenValue("access_token");
            //System.out.println("Logged In, setting token header: " + tokenStr);
            httppost.addHeader("Authorization", tokenStr);
        }
        if (data != null)
            httppost.setEntity(new UrlEncodedFormEntity(data));

        HttpResponse httpResponse = httpclient.execute(httppost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

        if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            Pattern p = Pattern.compile("<h2>(\\S+)</h2>");
            Matcher m = p.matcher(getStringFromStream(is));
            String details = "";
            if (m.find()) {
                details = m.group(1);
            }
            throw new RedditApiException(
                    String.valueOf(httpResponse.getStatusLine().getStatusCode()) + ": " + details);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    json = getStringFromStream(is);
    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        System.out.println("Error parsing data " + e.toString());
    }
    // return json response
    return jObj;
}