Example usage for android.util Base64 decode

List of usage examples for android.util Base64 decode

Introduction

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

Prototype

public static byte[] decode(byte[] input, int flags) 

Source Link

Document

Decode the Base64-encoded data in input and return the data in a new byte array.

Usage

From source file:Main.java

public static Bitmap getBitmapFromBase64(String string) {
    byte[] bitmapArray = null;
    try {/*www  .j  a  v a  2  s. com*/
        bitmapArray = Base64.decode(string, Base64.DEFAULT);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
}

From source file:Main.java

public static Bitmap base64ToBitmap(String base64) {
    if (base64 != null && !base64.isEmpty()) {
        byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        return decodedByte;
    }/*from  ww w  .  j a  va2  s  .  com*/
    return null;
}

From source file:Main.java

public static String base64decode(String base64) {
    String decoded = "";
    if (base64 != null) {
        try {/*  ww  w  .  j a  v  a  2s  .  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 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  .  j  a  v  a  2 s.  c o m
    out.close();
}

From source file:Main.java

public static String decodeToFile(File desFile, String encodedString) {
    try {//from   w ww  .  j  ava 2  s.c  om
        byte[] decodeBytes = Base64.decode(encodedString.getBytes(), Base64.NO_WRAP);
        FileOutputStream fos = new FileOutputStream(desFile);
        fos.write(decodeBytes);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String base64Decode(String originalString) {
    if (TextUtils.isEmpty(originalString))
        return "";

    return new String(Base64.decode(originalString, 0));
}

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();/*from  www  .jav a2 s.co m*/

    return object;
}

From source file:Main.java

public static Bitmap getBitmapByString(String imgSrc) {
    if (imgSrc != null) {
        byte[] buf = Base64.decode(imgSrc, Base64.NO_WRAP);
        ByteArrayInputStream bas = new ByteArrayInputStream(buf);
        Bitmap pic = BitmapFactory.decodeStream(bas);
        return pic;
    } else/*from   ww  w  .  j  a  va2  s. c  o  m*/
        return null;
}

From source file:Main.java

public static Bitmap getBitmapFromBase64encodedImage(String base64EncodedImage) {
    byte[] byteArray = Base64.decode(base64EncodedImage, Base64.DEFAULT);
    Bitmap image = null;// w w  w.j  a  v a  2s.  c o m
    try {
        image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return image;
}

From source file:Main.java

static public String decodeToSgtring(String code) {
    if (code == null || code.length() == 0) {
        return "";
    }/*  w w w.ja v a 2 s. co  m*/
    try {
        return new String(Base64.decode(code.getBytes(), Base64.NO_WRAP));
    } catch (Exception e) {
        e.printStackTrace();
        return code;
    }

}