code: public ByteBuffer serializeToByteBuffer() throws IOException {
      final ByteArrayOutputStream stream = new ByteArrayOutputStream();
      final Encoder encoder = EncoderFactory.get().binaryEncoder(stream, null);
      final DatumWriter writer = new GenericDatumWriter<GenericRecord>();
      writer.setSchema(createAvroSchema());
      final AvroParquetReader<GenericRecord> reader = createAvroReader();
  
      GenericRecord record = reader.read();
      while (record != null) {
        writer.write(record, encoder);
        record = reader.read();
      }
  
      try {
        reader.close();
      } catch (IOException ex){
        LOG.log(Level.SEVERE, ex.getMessage());
        throw ex;
      }
  
      encoder.flush();
      final ByteBuffer buf = ByteBuffer.wrap(stream.toByteArray());
      buf.order(ByteOrder.LITTLE_ENDIAN);
      return buf;
    }
docs: Serialize Avro data to a in-memory ByteBuffer.
  @return A ByteBuffer that contains avro data.
  @throws IOException if the parquet file couldn't be parsed correctly.