decode Object from Base64 String - Android File Input Output

Android examples for File Input Output:Object Serialization

Description

decode Object from Base64 String

Demo Code


//package com.java2s;

import android.util.Base64;

import java.io.*;

public class Main {
    public static Object decodeObject(String base64) {
        Object ret = null;/*  w w w  .  j  av  a2  s .co  m*/
        if (!base64.equals("")) {
            ByteArrayInputStream bais = new ByteArrayInputStream(
                    Base64.decode(base64.getBytes(), Base64.DEFAULT));
            ObjectInputStream ois = null;
            try {
                ois = new ObjectInputStream(bais);
                ret = ois.readObject();
            } catch (StreamCorruptedException e1) {
                e1.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                bais.close();
                ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }
}

Related Tutorials