/// <summary> /// Creates Avro Hearder Stream without zero block. /// </summary> /// <param name="dataList">the list of input data</param> /// <param name="schema">The writer schema.</param> /// <param name="settings">The serializer settings.</param> /// <param name="codec">The codec.</param> /// <returns> A writer.</returns> /// <exception cref="System.ArgumentNullException">Thrown when any argument is null.</exception> /// <returns>The first Tuple element is the stream with header, the second tuple element is the avro header</returns> public static Tuple <Stream, ObjectContainerHeader> CreateAvroHeaderStream <TSchema>(TSchema t, string schema, AvroSerializerSettings settings, Codec codec, int syncNumberOfObjects) { ObjectContainerHeader avroHeader = null; var stream = new MemoryStream(); using (var avroWriter = (StreamWriter <TSchema>)AvroContainer.CreateWriter <TSchema>(stream, true, settings, codec, false, null)) { avroWriter.WriteHeader(); avroHeader = avroWriter.Header; } stream.Seek(0, SeekOrigin.Begin); return(new Tuple <Stream, ObjectContainerHeader>(stream, avroHeader)); }
/// <summary> /// Creates Avro Blocks stream. /// </summary> /// <param name="dataList">the list of input data</param> /// <param name="schema">The writer schema.</param> /// <param name="settings">The serializer settings.</param> /// <param name="codec">The codec.</param> /// <returns> A writer.</returns> /// <exception cref="System.ArgumentNullException">Thrown when any argument is null.</exception> /// <returns>The first Tuple element is the stream with header and blocks, the second tuple element is the avro header</returns> public static Tuple <Stream, ObjectContainerHeader> CreateAvroHeaderAndBlockStream <TSchema>(List <TSchema> dataList, string schema, AvroSerializerSettings settings, Codec codec, int syncNumberOfObjects) { ObjectContainerHeader avroHeader = null; var stream = new MemoryStream(); using (var avroWriter = (StreamWriter <TSchema>)AvroContainer.CreateWriter <TSchema>(stream, true, settings, codec, false, null)) { avroHeader = avroWriter.Header; using (var sequentialWriter = new SequentialWriter <TSchema>(avroWriter, syncNumberOfObjects)) { dataList.ToList().ForEach(sequentialWriter.Write); } } stream.Seek(0, SeekOrigin.Begin); return(new Tuple <Stream, ObjectContainerHeader>(stream, avroHeader)); }