GenericDatumWriter datum = new GenericDatumWriter(schema);
DataFileWriter writer = new DataFileWriter(datum);
writer.setMeta("Meta-Key0", "Meta-Value0");
writer.setMeta("Meta-Key1", "Meta-Value1");
ByteArrayOutputStream bout = new ByteArrayOutputStream();
writer.create(schema, bout);
for (GenericData.Record record : records) {
writer.append(record);
}
writer.flush();
writer.close();