code: public static <T> byte[] writeAvroEntity(T entity, DatumWriter<T> writer) {
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      Encoder encoder = new EncoderFactory().binaryEncoder(outputStream, null);
      writeAvroEntity(entity, encoder, writer);
      return outputStream.toByteArray();
    }
docs: Given an entity and a DatumReader, encode the avro entity to a byte array.
  Encodes using the avro BinaryEncoder. Return the serialized bytes.
  
  @param entity
  The entity we want to encode.
  @param writer
  The DatumWriter we'll use to encode the entity to a byte array
  @return The avro entity encoded in a byte array.