* Converts a ChokeMap into an Avro-serialized byte array
*/
static protected byte[] serializeChokeMap(
Map<String, Map<String, Integer>> chokeMap) throws IOException {
DatumWriter<AvroFlumeChokeMap> datumWriter = new SpecificDatumWriter<AvroFlumeChokeMap>();
AvroFlumeChokeMap avromap = new AvroFlumeChokeMap();
Map<CharSequence, Map<CharSequence, Integer>> map = new HashMap<CharSequence, Map<CharSequence, Integer>>();
for (Entry<String, Map<String, Integer>> e : chokeMap.entrySet()) {
String name = e.getKey();
HashMap<CharSequence, Integer> tempMap = new HashMap<CharSequence, Integer>();
for (Entry<String, Integer> mape : e.getValue().entrySet()) {
tempMap.put(new String(mape.getKey()), mape.getValue());
}
map.put(name, tempMap);
}
avromap.chokemap = map;
datumWriter.setSchema(avromap.getSchema());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataFileWriter<AvroFlumeChokeMap> fileWriter = new DataFileWriter<AvroFlumeChokeMap>(
datumWriter);
fileWriter.create(avromap.getSchema(), baos);
fileWriter.append(avromap);
fileWriter.close();
return baos.toByteArray();
}