public static <T> byte[] encodeAvroSpecificRecord(Class<T> clazz, T record) throws IOException {
    DatumWriter<T> msgDatumWriter = new SpecificDatumWriter<>(clazz);
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Encoder encoder = EncoderFactory.get().binaryEncoder(os, null);
    msgDatumWriter.write(record, encoder);
    encoder.flush();
    return os.toByteArray();
  }
Encode an Avro record into byte array

@param clazz The class type of the avro record
@param record the instance of the avro record
@param <T> The type of the avro record.
@return encoded bytes
@throws IOException on I/O errors encoding the avro record
samza-tools/src/main/java/org/apache/samza/tools/GenerateKafkaEvents.java