使用ByteBuffer作为ChronicleMap的键的ClassCastException

时间:2019-05-18 18:12:37

标签: chronicle-map

我尝试了一个非常简单的示例,其中我尝试编写int-> ByteBuffer并在从映射中读取值的同时重用数组。

┌─────────┬───────────┐
│ Qwerty1 │ "!NOTICE" │
└─────────┴───────────┘

不幸的是,我遇到了一个意外的 try (ChronicleMap<Integer, ByteBuffer> map = ChronicleMap .of(Integer.class, ByteBuffer.class) .entries(1) .averageValueSize(30) .createPersistedTo(new File("e:/temp/test.obj"))) { byte[] out = new byte[] { 1, 2, 3}; map.put(1, ByteBuffer.wrap(out)); // ClassCastException ByteBuffer buff = ByteBuffer.allocate(30); ByteBuffer in = map.getUsing(1, buff); // hoping that 'ByteBuffer in' // is redundant } ,因为纪事报曾预期会有一个ClassCastException

byte[]

我在做什么错?尝试Exception in thread "main" java.lang.ClassCastException: ChronicleMap{name=null, file=E:\temp\test.obj, identityHashCode=809762318}: Value must be a [B but was a class java.nio.HeapByteBuffer at net.openhft.chronicle.map.VanillaChronicleMap.checkValue(VanillaChronicleMap.java:190) at net.openhft.chronicle.map.VanillaChronicleMap.put(VanillaChronicleMap.java:707) at test.SerTest.main(SerTest.java:28) 可以,但是byte[]没有使用我的输入数组,该数组仍然为空。

0 个答案:

没有答案
相关问题