Search code examples
javaxodus

How to convert a ByteIterable into a String?


When I put a key, I use StringToEntry:

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

and when I return it I get a ByteIterable:

ByteIterable result = store2.get(txn2, StringBinding.stringToEntry("bn:14271053n"));

How do I convert this into a String?


Solution

  • The Bindings section of Environments documentation says:

    All inheritors of the ComparableBinding class contain two static methods: one for getting the ByteIterable entry from a value, and another for getting value from an entry. For example, ByteBinding contains the following methods:

    public static byte entryToByte(@NotNull final ByteIterable entry);
    
    public static ArrayByteIterable byteToEntry(final byte object);
    

    Similarly, StringBinding contains two methods as well, the desired method is

    public static String entryToString(@NotNull final ByteIterable entry);