@Test public void stringArrayGetsStoredAsUtf8() throws Exception { String[] array = new String[] {"first", "second"}; Collection<DynamicRecord> records = arrayStore.allocateRecords(arrayStore.nextBlockId(), array); Pair<byte[], byte[]> loaded = loadArray(records); assertStringHeader(loaded.first(), array.length); ByteBuffer buffer = ByteBuffer.wrap(loaded.other()); for (String item : array) { byte[] expectedData = UTF8.encode(item); assertEquals(expectedData.length, buffer.getInt()); byte[] loadedItem = new byte[expectedData.length]; buffer.get(loadedItem); assertTrue(Arrays.equals(expectedData, loadedItem)); } }
private long nextArrayBlockId() { return arrayPropertyStore.nextBlockId(); }
private Collection<DynamicRecord> storeArray(Object array) { Collection<DynamicRecord> records = arrayStore.allocateRecords(arrayStore.nextBlockId(), array); for (DynamicRecord record : records) arrayStore.updateRecord(record); return records; }