Exemple #1
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 #2
0
        /// <summary>
        /// Creates a reader of <see cref="Microsoft.Hadoop.Avro.AvroRecord" /> or primitive type.
        /// </summary>
        /// <param name="readerSchema">The reader schema.</param>
        /// <param name="stream">The stream containing Avro object container.</param>
        /// <param name="leaveOpen">If set to <c>true</c> leaves the stream open.</param>
        /// <param name="factory">The codec factory.</param>
        /// <returns> A reader. </returns>
        /// <remarks><paramref name="readerSchema"/> should be specified explicitely when the schema of the consumer/reader is different from the schema of the producer/writer.</remarks>
        public static IAvroReader <object> CreateGenericReader(string readerSchema, Stream stream, bool leaveOpen, CodecFactory factory)
        {
            if (string.IsNullOrEmpty(readerSchema))
            {
                throw new ArgumentNullException("readerSchema");
            }
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            return(new StreamReader <object>(readerSchema, stream, leaveOpen, factory));
        }
Exemple #3
0
        /// <summary>
        /// Creates a reader of <see cref="Microsoft.Hadoop.Avro.AvroRecord"/> or primitive type.
        /// </summary>
        /// <param name="stream">The stream containing Avro object container.</param>
        /// <param name="leaveOpen">If set to <c>true</c> leaves the stream open.</param>
        /// <param name="factory">The codec factory.</param>
        /// <returns> A reader. </returns>
        public static IAvroReader <object> CreateGenericReader(Stream stream, bool leaveOpen, CodecFactory factory)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            return(new StreamReader <object>(null, stream, leaveOpen, factory));
        }
Exemple #4
0
 /// <summary>
 /// Creates a reader for a static C# type.
 /// </summary>
 /// <typeparam name="T">The type of deserialized objects.</typeparam>
 /// <param name="stream">The stream containing Avro object container.</param>
 /// <param name="leaveOpen">If set to <c>true</c>, the <paramref name="stream"/> is left open.</param>
 /// <param name="settings">The serializer settings.</param>
 /// <param name="codecFactory">The codec factory.</param>
 /// <returns> A reader. </returns>
 /// <exception cref="System.ArgumentNullException">Thrown when any argument is null.</exception>
 public static IAvroReader <T> CreateReader <T>(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");
     }
     return(new StreamReader <T>(stream, leaveOpen, settings, codecFactory));
 }
        public void Container_GenericWriterUsingCodecFactoryWithNullCodecName()
        {
            const string WriterSchema =
            @"{
                 ""name"":""RecordContainingArray"",
                 ""type"":""record"",
                 ""fields"":
                           [
                                {""name"":""IntField"", ""type"":""int""},
                           ]
             }";

            var codecFactory = new CodecFactory();

            using (AvroContainer.CreateGenericWriter(WriterSchema, this.resultStream, codecFactory.Create(null)))
            {
            }
        }
Exemple #6
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);
        }