@VisibleForTesting
  byte[] encodeRecord(IndexedRecord record) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Schema schema = record.getSchema();
    try {
      EncoderFactory encoderfactory = new EncoderFactory();
      BinaryEncoder encoder = encoderfactory.binaryEncoder(out, null);
      DatumWriter<IndexedRecord> writer;
      if (record instanceof SpecificRecord) {
        writer = new SpecificDatumWriter<>(schema);
      } else {
        writer = new GenericDatumWriter<>(schema);
      }
      writer.write(record, encoder);
      encoder.flush(); //encoder may buffer
    } catch (Exception e) {
      throw new SamzaException("Unable to serialize Avro record using schema within the record: " + schema.toString(), e);
    }
    return out.toByteArray();
  }
This method closes all DataFileWriters and output streams associated with all the blobs created.
flush should be explicitly called before close.
{@inheritDoc}
@throws IllegalStateException when closing a closed writer
@throws SamzaException if underlying DataFileWriter.close fails
samza-azure/src/main/java/org/apache/samza/system/azureblob/avro/AzureBlobAvroWriter.java