code: public static <T> void writeAvroEntity(T entity, Encoder encoder,
        DatumWriter<T> writer) {
      try {
        writer.write(entity, encoder);
        encoder.flush();
      } catch (IOException e) {
        throw new SerializationException("Could not serialize Avro entity", e);
      }
    }
docs: Given an entity, an avro schema, and an encoder, write the entity to the
  encoder's underlying output stream.
  
  @param entity
  The entity we want to encode.
  @param encoder
  The Avro Encoder we will write to.
  @param writer
  The DatumWriter we'll use to encode the entity to the encoder.