[
]
宙飒zhousa.om FireflyKV API
FireflyKV 对象,主要用于 KV 存储的初始化,存、取等操作,是主要的类。
初始化
FireFlyKV需调用init方法进行初始化,返回FireFlyKV实例对象,进而完成读写等操作,下文增删改查等操作,默认已初始化完成, 返回FireFlyKV的实例对象为fireFlyKV。
默认初始化
FireFlyKV init(Context context); 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| context | Context | 上下文 |
示例:
FireFlyKV fireFlyKV = FireFlyKV.init(this); 加密时初始化
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| context | Context | 上下文 |
| path | String | KV 存储库路径 |
| encryptType | int | 加密类型:0-不加密;1-chacha20加密 |
| key | String | 秘钥 |
| mode | Int | 是否开启多进程访问:0-不开启;1-开启 |
示例:
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 存储数据
存储 String 类型数值
以 key 作为键存储 String 类型数值。
boolean putString(String key, String value); 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 值 |
| value | String | value 键 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 插入数据是否成功 |
示例:
boolean result = fireFlyKV.putString("key", "value"); 存储 byte 类型数值
以 key 作为键存储 byte 类型数值。
boolean putByte(String key, byte value); 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 值 |
| value | byte | value 键 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 添加数据是否成功 |
示例:
boolean result = fireFlyKV.putByte("byte", 127); 存储 short 类型数值
以 key 作为键存储 short 类型数值。
boolean putShort(String key, short value); 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 值 |
| value | short | value 键 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 添加数据是否成功 |
示例:
boolean result = fireFlyKV.putShort("short", 130); 存储 int 类型数值
以 key 作为键存储 int 类型数值。
FireFlyKV fireFlyKV = FireFlyKV.init(this); 0 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 值 |
| value | int | value 键 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 添加数据是否成功 |
示例:
FireFlyKV fireFlyKV = FireFlyKV.init(this); 1 存储 long 类型数值
以 key 作为键存储 long 类型数值。
FireFlyKV fireFlyKV = FireFlyKV.init(this); 2 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 值 |
| value | long | value 键 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 添加数据是否成功 |
示例:
FireFlyKV fireFlyKV = FireFlyKV.init(this); 3 存储 float 类型数值
以 key 作为键存储 float 类型数值。
FireFlyKV fireFlyKV = FireFlyKV.init(this); 4 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 值 |
| value | float | value 键 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 添加数据是否成功 |
示例:
FireFlyKV fireFlyKV = FireFlyKV.init(this); 5 存储 double 类型数值
以 key 作为键存储 double 类型数值。
FireFlyKV fireFlyKV = FireFlyKV.init(this); 6 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 值 |
| value | double | value 键 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 添加数据是否成功 |
示例:
FireFlyKV fireFlyKV = FireFlyKV.init(this); 7 存储 char 类型数值
以 key 作为键存储 char 类型数值。
FireFlyKV fireFlyKV = FireFlyKV.init(this); 8 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 值 |
| value | char | value 键 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 添加数据是否成功 |
示例:
FireFlyKV fireFlyKV = FireFlyKV.init(this); 9 存储 boolean 类型数值
以 key 作为键存储 boolean 类型数值。
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 0 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 值 |
| value | boolean | value 键 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 添加数据是否成功 |
示例:
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 1 获取数据
获取 String 类型数值
通过 key 取 String 值,默认是 null
普通
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 2 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
示例:
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 3 带默认值
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 4 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
| defaultValue | String | 默认值 |
返回值:
示例:
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 5 获取 byte 类型数值
通过 key 取 byte 值,默认是 0
普通
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 6 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
示例:
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 7 带默认值
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 8 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
| defaultValue | byte | 默认值 |
返回值:
示例:
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 9 获取 short 类型数值
通过 key 取 short 值,默认是 0
普通
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 0 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
示例:
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 1 带默认值
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 2 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
| defaultValue | short | 默认值 |
返回值:
示例:
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 3获取 int 类型数值
通过 key 取 int 值,默认是 0
普通
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 4 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
示例:
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 5 带默认值
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 6 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
| defaultValue | int | 默认值 |
返回值:
示例:
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 7 获取 long 类型数值
通过 key 取 long 值,默认是 0L
普通
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 8 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
示例:
public static final int NONE_ENCRYPT = 0; // 默认不加密 public static final int CC20_ENCRYPT = 1; // chacha20 加密 String path = context.getFilesDir().getAbsolutePath() + "/ffkv"; String key = "chacha20"; FireFlyKV fireFlyKV = FireFlyKV.init(path, CC20_ENCRYPT, key); 9 带默认值
boolean putString(String key, String value); 0 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
| defaultValue | long | 默认值 |
返回值:
示例:
boolean putString(String key, String value); 1 获取 float 类型数值
通过 key 取 float 值,默认是 0f
普通
boolean putString(String key, String value); 2 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
示例:
boolean putString(String key, String value); 3 带默认值
boolean putString(String key, String value); 4 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
| defaultValue | float | 默认值 |
返回值:
示例:
boolean putString(String key, String value); 5 获取 double 类型数值
通过 key 取 double 值,默认是 0.00
普通
boolean putString(String key, String value); 6 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
示例:
boolean putString(String key, String value); 7 带默认值
boolean putString(String key, String value); 8 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
| defaultValue | double | 默认值 |
返回值:
示例:
boolean putString(String key, String value); 9 获取 char 类型数值
通过 key 取 char 值,默认是 0
普通
boolean result = fireFlyKV.putString("key", "value"); 0 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
示例:
boolean result = fireFlyKV.putString("key", "value"); 1 带默认值
boolean result = fireFlyKV.putString("key", "value"); 2 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
| defaultValue | char | 默认值 |
返回值:
示例:
boolean result = fireFlyKV.putString("key", "value"); 3 获取 boolean 类型数值
通过 key 取 boolean 值,默认是 false
普通
boolean result = fireFlyKV.putString("key", "value"); 4 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
示例:
boolean result = fireFlyKV.putString("key", "value"); 5 带默认值
boolean result = fireFlyKV.putString("key", "value"); 6 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
| defaultValue | boolean | 默认值 |
返回值:
示例:
boolean result = fireFlyKV.putString("key", "value"); 7 是否包含 key 值
boolean result = fireFlyKV.putString("key", "value"); 8 参数
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
返回值
| 类型 |
|---|
| boolean |
示例:
boolean result = fireFlyKV.putString("key", "value"); 9 删除 key 值
移除 KV 库中的为 key 的数据
boolean putByte(String key, byte value); 0 参数
| 属性 | 类型 | 说明 |
|---|---|---|
| key | String | key 键 |
返回值
| 类型 |
|---|
| boolean |
示例:
boolean putByte(String key, byte value); 1 清除 KV 库数据
boolean putByte(String key, byte value); 2 参数
无
返回值
无
示例:
boolean putByte(String key, byte value); 3 多进程访问
处理多个进程间的数据同步问题,需要在FireflyKV初始化时,指定为多进程模式即可。
FireFlyKV init(Context context, String path, int encryptType,String key, int mode); 参数:
| 属性 | 类型 | 说明 |
|---|---|---|
| context | Context | 上下文 |
| path | String | KV 存储库路径 |
| encryptType | int | 加密类型:0-不加密;1-chacha20加密 |
| key | String | 秘钥 |
| mode | Int | 是否开启多进程访问:0-不开启;1-开启 |
示例:
boolean putByte(String key, byte value); 5 



还没有评论,来说两句吧...