如何使用环境 API 存储 byte[] 数组
How to store byte[] array using Environment API
这是我的代码:
@Override
public void put(String instance, final String storeName, final String key, final byte[] value) {
final Environment env = Environments.newInstance(xodusRoot + instance);
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
final Store store = env.openStore(storeName, StoreConfig.WITHOUT_DUPLICATES, txn);
store.put(txn, StringBinding.stringToEntry(key), ByteBinding.byteToEntry(value));
}
});
env.close();
}
这里的问题是ByteBinding 可以接受的值只是一个字节,那么Byte 数组呢?
使用来自 openAPI 的 ArrayByteIterable
class:
store.put(txn, StringBinding.stringToEntry(key), new ArrayByteIterable(value));
这是我的代码:
@Override
public void put(String instance, final String storeName, final String key, final byte[] value) {
final Environment env = Environments.newInstance(xodusRoot + instance);
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
final Store store = env.openStore(storeName, StoreConfig.WITHOUT_DUPLICATES, txn);
store.put(txn, StringBinding.stringToEntry(key), ByteBinding.byteToEntry(value));
}
});
env.close();
}
这里的问题是ByteBinding 可以接受的值只是一个字节,那么Byte 数组呢?
使用来自 openAPI 的 ArrayByteIterable
class:
store.put(txn, StringBinding.stringToEntry(key), new ArrayByteIterable(value));