Android Open Source - android-sqlite-kvs Json K V S






From Project

Back to project page android-sqlite-kvs.

License

The source code is released under:

Apache License

If you think the Android project android-sqlite-kvs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package jp.fkmsoft.libs.sqlitekvs.json;
//from  ww w .j a va2  s  . com
import android.content.Context;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;

import jp.fkmsoft.libs.sqlitekvs.impl.KVSImpl;

/**
 * Target class
 */
public class JsonKVS extends KVSImpl<JSONObject> {
    private static final String CHARSET = "utf-8";

    protected JsonKVS(Context context, String dbName) {
        super(context, dbName);
    }

    @Override
    protected JSONObject createFromBlob(byte[] bytes) {
        try {
            String body = new String(bytes, CHARSET);
            return new JSONObject(body);
        } catch (UnsupportedEncodingException e) {
            return new JSONObject();
        } catch (JSONException e2) {
            return new JSONObject();
        }

    }

    @Override
    protected byte[] toBytes(JSONObject value) {
        try {
            return value.toString().getBytes(CHARSET);
        } catch (UnsupportedEncodingException e) {
            return new byte[0];
        }
    }
}




Java Source Code List

jp.fkmsoft.libs.sqlitekvs.KVSException.java
jp.fkmsoft.libs.sqlitekvs.KVS.java
jp.fkmsoft.libs.sqlitekvs.impl.DBHelper.java
jp.fkmsoft.libs.sqlitekvs.impl.KVSImpl.java
jp.fkmsoft.libs.sqlitekvs.json.JsonKVS.java
jp.fkmsoft.libs.sqlitekvs.json.TestJsonKVS.java
jp.fkmsoft.libs.sqlitekvs.util.DBUtils.java