如何使用环境API存储byte []数组

时间:2018-08-12 05:46:09

标签: java xodus

这是我的代码:

@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数组怎么样?

1 个答案:

答案 0 :(得分:1)

使用openAPI中的ArrayByteIterable类:

store.put(txn, StringBinding.stringToEntry(key), new ArrayByteIterable(value));