How can I write and read ListMultimap to file using Properties?
I have an index as follows:
ListMultimap<Object, Object> index = ArrayListMultimap.create();
and writing index to file using Properties as follows:
writeIndexToFile(ListMultimap<Object, Object> listMultimap, String fileName) {
Properties properties = new Properties();
properties = MapUtils.toProperties(toMap(listMultimap));
properties.store(new FileOutputStream(fileName),null);
}
where, toMap() method is:
Map<Object, Object> toMap(ListMultimap<Object, Object> multiMap) {
if (multiMap == null) {
return null;
}
Map<Object, Object> map = new HashMap<Object, Object>();
for (Object key : multiMap.keySet()) {
map.put(key, multiMap.get(key));
}
return map;
}
After running this code, I found the output file is empty. Why nothing is getting written into file?
in above code I cannot call directly as:
MapUtils.toProperties(listMultimap);
because listMultimap is not of type Map. So I converted it to Map using method toMap(). But still it seems that Properties is unable to get map correctly.
Note:
I tried printing listMultimap by converting it to JSON using Gson, but this also failed to convert to string. No Exception occured, but it returned empty string. Actual listMultimap is something like:

where, index == listMultimap.
I'm not getting where am I going wrong.