Search code examples
javaxodus

How to store byte[] array using Environment API


Here's my code:

@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();
}

Problem here is that the value that the ByteBinding can accept is only a byte how about Byte arrays?


Solution

  • Use ArrayByteIterable class from openAPI:

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