// Path: core/src/main/java/com/fenlisproject/elf/core/io/KeyBasedObjectIO.java
// public interface KeyBasedObjectIO {
//     ObjectInput getObjectInput(String key) throws IOException;
// 
//     ObjectOutput getObjectOutput(String key) throws IOException;
// }
// 
// Path: core/src/main/java/com/fenlisproject/elf/core/util/SecurityUtils.java
// public class SecurityUtils {
// 
//     public static String md5(String str) {
//         try {
//             MessageDigest digest = MessageDigest.getInstance("MD5");
//             digest.update(str.getBytes());
//             byte messageDigest[] = digest.digest();
//             StringBuffer hexString = new StringBuffer();
//             for (int i = 0; i < messageDigest.length; i++) {
//                 String h = Integer.toHexString(0xFF & messageDigest[i]);
//                 while (h.length() < 2) {
//                     h = "0" + h;
//                 }
//                 hexString.append(h);
//             }
//             return hexString.toString();
// 
//         } catch (NoSuchAlgorithmException e) {
//             e.printStackTrace();
//         }
//         return "";
//     }
// 
//     public static String base64Encode(String text) {
//         try {
//             byte[] data = text.getBytes("UTF-8");
//             return Base64.encodeToString(data, Base64.NO_WRAP);
//         } catch (UnsupportedEncodingException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
//     public static String base64Decode(String text) {
//         byte[] data = Base64.decode(text, Base64.NO_WRAP);
//         try {
//             return new String(data, "UTF-8");
//         } catch (UnsupportedEncodingException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// }


import android.content.Context;
import com.fenlisproject.elf.core.io.KeyBasedObjectIO;
import com.fenlisproject.elf.core.util.SecurityUtils;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/*
* Copyright (C) 2015 Steven Lewi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.fenlisproject.elf.core.data;




public class PersistentObjectStorage implements DataStorage<Serializable>, KeyBasedObjectIO {

    protected Context mContext;

    public PersistentObjectStorage(Context context) {
        this.mContext = context.getApplicationContext();
    }

    @Override
    public Serializable get(String key) {
        return get(key, Serializable.class);
    }

    public <V extends Serializable> V get(String key, Class<V> vClass) {
        synchronized (this) {
            String hashedKey = SecurityUtils.md5(key);
            try {
                ObjectInput oi = getObjectInput(hashedKey);
                V object = (V) oi.readObject();
                oi.close();
                return object;
            } catch (ClassNotFoundException e) {
// Path: core/src/main/java/com/fenlisproject/elf/core/io/KeyBasedObjectIO.java
// public interface KeyBasedObjectIO {
//     ObjectInput getObjectInput(String key) throws IOException;
// 
//     ObjectOutput getObjectOutput(String key) throws IOException;
// }
// 
// Path: core/src/main/java/com/fenlisproject/elf/core/util/SecurityUtils.java
// public class SecurityUtils {
// 
//     public static String md5(String str) {
//         try {
//             MessageDigest digest = MessageDigest.getInstance("MD5");
//             digest.update(str.getBytes());
//             byte messageDigest[] = digest.digest();
//             StringBuffer hexString = new StringBuffer();
//             for (int i = 0; i < messageDigest.length; i++) {
//                 String h = Integer.toHexString(0xFF & messageDigest[i]);
//                 while (h.length() < 2) {
//                     h = "0" + h;
//                 }
//                 hexString.append(h);
//             }
//             return hexString.toString();
// 
//         } catch (NoSuchAlgorithmException e) {
//             e.printStackTrace();
//         }
//         return "";
//     }
// 
//     public static String base64Encode(String text) {
//         try {
//             byte[] data = text.getBytes("UTF-8");
//             return Base64.encodeToString(data, Base64.NO_WRAP);
//         } catch (UnsupportedEncodingException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// 
//     public static String base64Decode(String text) {
//         byte[] data = Base64.decode(text, Base64.NO_WRAP);
//         try {
//             return new String(data, "UTF-8");
//         } catch (UnsupportedEncodingException e) {
//             e.printStackTrace();
//         }
//         return null;
//     }
// }


// Path: core/src/main/java/com/fenlisproject/elf/core/data/PersistentObjectStorage.java
import android.content.Context;
import com.fenlisproject.elf.core.io.KeyBasedObjectIO;
import com.fenlisproject.elf.core.util.SecurityUtils;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/*
* Copyright (C) 2015 Steven Lewi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.fenlisproject.elf.core.data;




public class PersistentObjectStorage implements DataStorage<Serializable>, KeyBasedObjectIO {

    protected Context mContext;

    public PersistentObjectStorage(Context context) {
        this.mContext = context.getApplicationContext();
    }

    @Override
    public Serializable get(String key) {
        return get(key, Serializable.class);
    }

    public <V extends Serializable> V get(String key, Class<V> vClass) {
        synchronized (this) {
            String hashedKey = SecurityUtils.md5(key);
            try {
                ObjectInput oi = getObjectInput(hashedKey);
                V object = (V) oi.readObject();
                oi.close();
                return object;
            } catch (ClassNotFoundException e) {
                e.printStackTrace();