コード例 #1
0
        public Task <long> WriteBlockAsync(IAvroWriterBlock <T> block)
        {
            if (block == null)
            {
                throw new ArgumentNullException("block");
            }

            var taskSource = new TaskCompletionSource <long>();

            block.Flush();

            long result;

            lock (this.locker)
            {
                if (!this.isHeaderWritten)
                {
                    this.header.Write(this.encoder);
                    this.isHeaderWritten = true;
                }

                result = this.resultStream.Position;
                if (block.ObjectCount != 0)
                {
                    this.encoder.Encode(block.ObjectCount);
                    this.encoder.Encode(block.Content);
                    this.encoder.EncodeFixed(this.header.SyncMarker);
                }
            }

            taskSource.SetResult(result);
            return(taskSource.Task);
        }
コード例 #2
0
        /// <summary>
        ///     Ends current block.
        /// </summary>
        /// <returns>Last position of the block.</returns>
        public long Sync()
        {
            var position = this.writer.WriteBlock(this.current);

            this.current.Dispose();
            this.current = this.writer.CreateBlock();
            return(position);
        }
コード例 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SequentialWriter{T}"/> class.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="syncNumberOfObjects">The sync number of objects.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="writer"/> is null.</exception>
        public SequentialWriter(IAvroWriter <T> writer, int syncNumberOfObjects)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (syncNumberOfObjects <= 0)
            {
                throw new ArgumentOutOfRangeException("syncNumberOfObjects");
            }

            this.writer              = writer;
            this.metadata            = new Dictionary <string, byte[]>();
            this.metadataWritten     = false;
            this.current             = writer.CreateBlock();
            this.syncNumberOfObjects = syncNumberOfObjects;
        }
コード例 #4
0
        public Task <long> WriteBlockAsync(IAvroWriterBlock <T> block)
        {
            if (block == null)
            {
                throw new ArgumentNullException("block");
            }

            var taskSource = new TaskCompletionSource <long>();

            block.Flush();

            long result = 0;

            lock (this.locker)
            {
                if (!this.isHeaderWritten)
                {
                    // This is never used.
                    result = this.WriteHeader();
                }

                if (block.ObjectCount != 0)
                {
                    // Replace this with a MemoryStream, as we will be limited to the size of an Azure Blob Block
                    using (var stream = new MemoryStream())
                    {
                        using (var encoder = new BinaryEncoder(stream, true))
                        {
                            encoder.Encode(block.ObjectCount);
                            encoder.Encode(block.Content);
                            encoder.EncodeFixed(this.header.SyncMarker);
                            stream.Seek(0, SeekOrigin.Begin);
                            this.WriteStreamToBlobAsync(stream);
                        }
                    }
                }
            }

            taskSource.SetResult(result);
            return(taskSource.Task);
        }
コード例 #5
0
 public long WriteBlock(IAvroWriterBlock <T> block)
 {
     return(this.WriteBlockAsync(block).Result);
 }