/// <summary>
        /// Retrieve Avro Hearder from a stream
        /// </summary>
        /// <param name="avroStream">The stream that contains the avro header</param>
        /// <returns>Avro Header Object</returns>
        public static ObjectContainerHeader GetAvroHeader <TSchema>(Stream avroStream)
        {
            ObjectContainerHeader avroHeader = null;

            avroStream.Seek(0, SeekOrigin.Begin);
            using (var decoder = new BinaryDecoder(avroStream, true))
            {
                avroHeader = ObjectContainerHeader.Read(decoder);
            }
            avroStream.Dispose();
            return(avroHeader);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StreamReader{T}"/> class for Avro records.
        /// </summary>
        /// <param name="readerSchema">The reader schema.</param>
        /// <param name="stream">The input stream.</param>
        /// <param name="leaveOpen">If set to <c>true</c> leaves the input stream open.</param>
        /// <param name="codecFactory">The codec factory.</param>
        public StreamReader(string readerSchema, Stream stream, bool leaveOpen, CodecFactory codecFactory)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (codecFactory == null)
            {
                throw new ArgumentNullException("codecFactory");
            }

            this.stream     = stream;
            this.decoder    = new BinaryDecoder(stream, leaveOpen);
            this.header     = ObjectContainerHeader.Read(this.decoder);
            this.codec      = codecFactory.Create(this.header.CodecName);
            this.serializer = (IAvroSerializer <T>)AvroSerializer.CreateGenericDeserializerOnly(this.header.Schema, readerSchema ?? this.header.Schema);
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StreamReader{T}"/> class for static types.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="leaveOpen">If set to <c>true</c> leaves the input stream open.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="codecFactory">The codec factory.</param>
        public StreamReader(Stream stream, bool leaveOpen, AvroSerializerSettings settings, CodecFactory codecFactory)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (codecFactory == null)
            {
                throw new ArgumentNullException("codecFactory");
            }

            this.stream     = stream;
            this.decoder    = new BinaryDecoder(stream, leaveOpen);
            this.header     = ObjectContainerHeader.Read(this.decoder);
            this.codec      = codecFactory.Create(this.header.CodecName);
            this.serializer = AvroSerializer.CreateDeserializerOnly <T>(this.header.Schema, settings);
        }