Converts a Base64 string into an object - Android File Input Output

Android examples for File Input Output:Object Serialization

Description

Converts a Base64 string into an object

Demo Code


//package com.java2s;
import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.ObjectInputStream;

import java.io.StreamCorruptedException;
import android.util.Base64;

public class Main {
    /**//from   w  w  w  . j av a  2 s  .  com
     * Converts a Base64 string into an object
     *
     * @param s The Base64 encoded string
     * @return The converted object
     * @throws StreamCorruptedException
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public static Object stringToObject(String s)
            throws StreamCorruptedException, IOException,
            ClassNotFoundException {
        byte[] data = Base64.decode(s, Base64.DEFAULT);
        ObjectInputStream ois = new ObjectInputStream(
                new ByteArrayInputStream(data));
        Object o = ois.readObject();
        ois.close();
        return o;
    }
}

Related Tutorials