Esempio n. 1
0
        public void TestReadFeed()
        {
            MemoryStream            ms     = new MemoryStream();
            IAvroWriter <Product[]> writer = null;

            try
            {
                writer = AvroContainer.CreateWriter <Product[]>(ms, true, new AvroSerializerSettings(), Codec.Null);
                using (var seqWriter = new SequentialWriter <Product[]>(writer, 24))
                {
                    seqWriter.Write(new[] { product1, product2, product3 });
                }
            }
            finally
            {
                if (writer != null)
                {
                    writer.Dispose();
                }
            }

            ms.Seek(0, SeekOrigin.Begin);
            var entries = new List <ODataEntry>();

            using (var omr = TestHelper.CreateMessageReader(ms, "avro/binary", AvroMediaTypeResolver.Instance))
            {
                var reader = omr.CreateODataFeedReader();
                while (reader.Read())
                {
                    if (reader.State == ODataReaderState.EntryEnd)
                    {
                        entries.Add((ODataEntry)reader.Item);
                    }
                }
            }

            Assert.AreEqual(3, entries.Count);

            Assert.IsTrue(TestHelper.EntryEqual(entry1, entries[0]));
            Assert.IsTrue(TestHelper.EntryEqual(entry2, entries[1]));
            Assert.IsTrue(TestHelper.EntryEqual(entry3, entries[2]));
        }
Esempio n. 2
0
        public void TestReadEntry()
        {
            MemoryStream          ms     = new MemoryStream();
            IAvroWriter <Product> writer = null;

            try
            {
                writer = AvroContainer.CreateWriter <Product>(ms, true, new AvroSerializerSettings(), Codec.Null);
                using (var seqWriter = new SequentialWriter <Product>(writer, 24))
                {
                    seqWriter.Write(product0);
                }
            }
            finally
            {
                if (writer != null)
                {
                    writer.Dispose();
                }
            }

            ms.Seek(0, SeekOrigin.Begin);
            ODataEntry entry = null;

            using (var omr = TestHelper.CreateMessageReader(ms, "avro/binary", AvroMediaTypeResolver.Instance))
            {
                var reader = omr.CreateODataEntryReader();
                while (reader.Read())
                {
                    if (reader.State == ODataReaderState.EntryEnd)
                    {
                        entry = (ODataEntry)reader.Item;
                    }
                }
            }

            Assert.IsTrue(TestHelper.EntryEqual(entry0, entry));
        }
Esempio n. 3
0
        protected virtual void Dispose(bool finalize)
        {
            if (_isDisposed)
            {
                return;
            }

            if (_streamWriter != null)
            {
                _writer.Dispose(_streamWriter.Value);
            }

            _isDisposed = true;
            if (_closeStreamOnDispose)
            {
                if (_streamWriter != null)
                {
                    _streamWriter.Value.Dispose();
                }
            }
            else
            {
                if (_streamWriter != null)
                {
                    _streamWriter.Value.Flush();
                }
            }

            if (_avroWriter != null)
            {
                _avroWriter.Dispose();
            }

            if (!finalize)
            {
                GC.SuppressFinalize(this);
            }
        }