Example usage for android.util Base64 DEFAULT

List of usage examples for android.util Base64 DEFAULT

Introduction

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

Prototype

int DEFAULT

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

Click Source Link

Document

Default values for encoder/decoder flags.

Usage

From source file:Main.java

public static String convertBase64(String str) {
    byte[] data;//from   w  ww .  j av  a  2s. c  o m
    try {
        data = str.getBytes("UTF-8");
        String base64 = Base64.encodeToString(data, Base64.DEFAULT);
        return base64.trim();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static Bitmap decodeImageBase64(String bitmapString) {
    byte[] bytes = Base64.decode(bitmapString.getBytes(), Base64.DEFAULT);
    return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
}

From source file:Main.java

public static String base64decode(String base64) {
    String decoded = "";
    if (base64 != null) {
        try {/*w  w  w  .  j  av  a 2  s  .co m*/
            decoded = new String(Base64.decode(base64, Base64.DEFAULT), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
    return decoded;
}

From source file:Main.java

public static String encodeBase64(String str) throws UnsupportedEncodingException, Base64DataException {
    return Base64.encodeToString(str.getBytes("UTF-8"), Base64.DEFAULT).replace("\n", "");
}

From source file:Main.java

public static Bitmap convertBase64ToBitmap(String strBase64) {
    byte[] imageAsBytes = Base64.decode(strBase64.getBytes(), Base64.DEFAULT);
    Bitmap result = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
    return result;
}

From source file:Main.java

public static void decoderBase64File(String base64Code, String savePath) throws Exception {
    //byte[] buffer = new BASE64Decoder().decodeBuffer(base64Code);
    byte[] buffer = Base64.decode(base64Code, Base64.DEFAULT);
    FileOutputStream out = new FileOutputStream(savePath);
    out.write(buffer);/*w w  w  . ja  v a 2s . c om*/
    out.close();
}

From source file:Main.java

public static Object deSerialization(String str) throws IOException, ClassNotFoundException {
    byte[] mobileBytes = Base64.decode(str.getBytes(), Base64.DEFAULT);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(mobileBytes);
    ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
    Object object = (Object) objectInputStream.readObject();
    objectInputStream.close();/* w ww  . j a va 2 s . co  m*/

    return object;
}

From source file:Main.java

/**
 * Metodo che decifra la password proveniente dalla sorgente dati
 * @param string = password in Base64//from  ww  w.ja  va  2s  . c o  m
 * @return password in chiaro
 */
public static String decodePassword(String string) {
    byte[] data = Base64.decode(string, Base64.DEFAULT);
    return new String(data);
}

From source file:Main.java

public static Bitmap convertStringToIcon(String st) {
    Bitmap bitmap = null;/*from w  ww. j a va2  s . c o  m*/
    try {
        byte[] bitmapArray;
        bitmapArray = Base64.decode(st, Base64.DEFAULT);
        bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
        return bitmap;
    } catch (Exception e) {
        return null;
    }
}

From source file:Main.java

public static Bitmap getBitmap(Context context, String str) {
    if (str != null && str.length() > 0) {
        byte[] decode = Base64.decode(str, Base64.DEFAULT);
        return BitmapFactory.decodeByteArray(decode, 0, decode.length);
    }//from ww  w  .j  a  v  a2  s.c  om
    return null;
}