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:Main.java

public static Bitmap getBitmapFromBase64(String base64Str) {

    if (TextUtils.isEmpty(base64Str)) {
        return null;
    }//from   w ww.  ja va2  s .  c  o m

    byte[] bytes = Base64.decode(base64Str, Base64.NO_WRAP);
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

public static Bitmap bitmapFromBase64(String base64Str) {
    if (TextUtils.isEmpty(base64Str)) {
        return null;
    } else {/*from  www .  j av  a2  s .  c  om*/
        byte[] bytes = Base64.decode(base64Str, Base64.NO_WRAP);
        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    }
}

From source file:Main.java

/**
 * Generate HTTP Basic Authorization Header
 * //from   w ww  . ja va2s  . co  m
 * @param username username
 * @param password password
 * @return Generated header
 */
public static String getPasswordDigest(String username, String password) {
    String authString = username + ":" + password;
    return Base64.encodeToString(authString.getBytes(), Base64.NO_WRAP);
}

From source file:Main.java

public static String base64Encode(String s) {
    byte[] data = new byte[0];
    try {/*from w  ww.ja v  a2 s  .  co m*/
        data = s.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } finally {
        return Base64.encodeToString(data, Base64.NO_WRAP);
    }
}

From source file:Main.java

public static String encodeToFile(File file) {
    try {/*from w  w w .j  ava 2 s .  c o m*/
        FileInputStream inputFile = new FileInputStream(file);
        byte[] buffer = new byte[(int) file.length()];
        inputFile.read(buffer);
        inputFile.close();
        return Base64.encodeToString(buffer, Base64.NO_WRAP);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

static public byte[] decodeToByte(byte[] code) {
    if (code == null || code.length == 0) {
        return null;
    }/*from   w  ww .  j  a va  2s. c  o m*/
    return Base64.decode(code, Base64.NO_WRAP);
}

From source file:Main.java

public static RSAPublicKey buildPublicKeyFromBase64String(String key)
        throws InvalidKeySpecException, NoSuchAlgorithmException {
    byte[] byteKey = Base64.decode(key.getBytes(), Base64.NO_WRAP | Base64.URL_SAFE);
    X509EncodedKeySpec X509publicKey = new X509EncodedKeySpec(byteKey);
    KeyFactory kf = KeyFactory.getInstance("RSA");

    return (RSAPublicKey) kf.generatePublic(X509publicKey);
}

From source file:Main.java

private static byte[] base64Encode(byte[] input) {
    return Base64.encode(input, Base64.NO_WRAP);
}

From source file:Main.java

static public String decodeToSgtring(byte[] code) {
    if (code == null || code.length == 0) {
        return "";
    }//from w w w.  j  a va 2s  .  com
    return new String(Base64.decode(code, Base64.NO_WRAP));
}

From source file:Main.java

public static String encodeUrlSafe64(byte[] array) {
    int flags = Base64.NO_PADDING | Base64.NO_WRAP | Base64.URL_SAFE;
    return Base64.encodeToString(array, flags);
}