Beispiel #1
0
        public ConverterDecodingInput(Stream source, bool push, Encoding encoding, bool detectEncodingFromByteOrderMark, int maxParseToken, int restartMax, int inputBufferSize, bool testBoundaryConditions, IResultsFeedback resultFeedback, IProgressMonitor progressMonitor) : base(progressMonitor)
        {
            this.resultFeedback = resultFeedback;
            this.restartMax     = restartMax;
            if (push)
            {
                pushSource = (source as ConverterStream);
            }
            else
            {
                pullSource = source;
            }
            this.detectEncodingFromByteOrderMark = detectEncodingFromByteOrderMark;
            minDecodeBytes   = (testBoundaryConditions ? 1 : 64);
            originalEncoding = encoding;
            SetNewEncoding(encoding);
            maxTokenSize = ((maxParseToken == 2147483647) ? maxParseToken : (testBoundaryConditions ? maxParseToken : ((maxParseToken + 1023) / 1024 * 1024)));
            parseBuffer  = new char[testBoundaryConditions ? 55L : Math.Min(4096L, (long)maxTokenSize + (long)(minDecodeChars + 1))];
            if (pushSource != null)
            {
                readBuffer = new byte[Math.Max(minDecodeBytes * 2, 8)];
                return;
            }
            int num = Math.Max(CalculateMaxBytes(parseBuffer.Length), inputBufferSize);

            readBuffer = new byte[num];
        }
Beispiel #2
0
 public ConverterEncodingOutput(Stream destination, bool push, bool restartable, Encoding encoding, bool encodingSameAsInput, bool testBoundaryConditions, IResultsFeedback resultFeedback)
 {
     this.resultFeedback = resultFeedback;
     if (!push)
     {
         pullSink = (destination as ConverterStream);
         pullSink.SetSource(this);
     }
     else
     {
         pushSink = destination;
         if (restartable && destination.CanSeek && destination.Position == destination.Length)
         {
             restartablePushSink = true;
             restartPosition     = destination.Position;
         }
     }
     canRestart               = restartable;
     this.restartable         = restartable;
     lineBuffer               = new char[4096];
     minCharsEncode           = (testBoundaryConditions ? 1 : 256);
     this.encodingSameAsInput = encodingSameAsInput;
     originalEncoding         = encoding;
     ChangeEncoding(encoding);
     if (this.resultFeedback != null)
     {
         this.resultFeedback.Set(ConfigParameter.OutputEncoding, this.encoding);
     }
 }
Beispiel #3
0
        internal override IProducerConsumer CreatePullChain(TextReader input, ConverterStream converterStream)
        {
            this.inputEncoding = Encoding.Unicode;
            ConverterInput  input2 = new ConverterUnicodeInput(input, false, this.maxHtmlTagSize, base.TestBoundaryConditions, converterStream);
            ConverterOutput output = new ConverterEncodingOutput(converterStream, false, false, this.outputEncodingSameAsInput ? Encoding.UTF8 : this.outputEncoding, this.outputEncodingSameAsInput, base.TestBoundaryConditions, this);

            return(this.CreateChain(input2, output, converterStream));
        }
Beispiel #4
0
        internal override IProducerConsumer CreatePullChain(Stream input, ConverterStream converterStream)
        {
            if (this.inputEncoding == null)
            {
                throw new InvalidOperationException(TextConvertersStrings.InputEncodingRequired);
            }
            ConverterInput  input2 = new ConverterDecodingInput(input, false, this.inputEncoding, this.detectEncodingFromByteOrderMark, this.maxHtmlTagSize, this.testMaxHtmlRestartOffset, base.InputStreamBufferSize, base.TestBoundaryConditions, this, converterStream);
            ConverterOutput output = new ConverterEncodingOutput(converterStream, false, true, this.outputEncodingSameAsInput ? this.inputEncoding : this.outputEncoding, this.outputEncodingSameAsInput, base.TestBoundaryConditions, this);

            return(this.CreateChain(input2, output, converterStream));
        }
Beispiel #5
0
        internal override IProducerConsumer CreatePushChain(ConverterStream converterStream, TextWriter output)
        {
            if (this.inputEncoding == null)
            {
                throw new InvalidOperationException(TextConvertersStrings.InputEncodingRequired);
            }
            this.outputEncoding = Encoding.Unicode;
            ConverterInput  input   = new ConverterDecodingInput(converterStream, true, this.inputEncoding, this.detectEncodingFromByteOrderMark, this.maxHtmlTagSize, this.testMaxHtmlRestartOffset, base.InputStreamBufferSize, base.TestBoundaryConditions, this, null);
            ConverterOutput output2 = new ConverterUnicodeOutput(output, true, true);

            return(this.CreateChain(input, output2, converterStream));
        }
Beispiel #6
0
 protected override void Dispose()
 {
     if (cache != null && cache is IDisposable)
     {
         ((IDisposable)cache).Dispose();
     }
     cache       = null;
     pushSink    = null;
     pullSink    = null;
     lineBuffer  = null;
     encoding    = null;
     encoder     = null;
     codePageMap = null;
     base.Dispose();
 }
Beispiel #7
0
 protected override void Dispose()
 {
     if (restartCache != null && restartCache is IDisposable)
     {
         ((IDisposable)restartCache).Dispose();
     }
     restartCache    = null;
     pullSource      = null;
     pushSource      = null;
     parseBuffer     = null;
     readBuffer      = null;
     pushChunkBuffer = null;
     preamble        = null;
     restartConsumer = null;
     base.Dispose();
 }
Beispiel #8
0
        /// <summary>
        /// Converts the specified source reader.
        /// </summary>
        /// <param name="sourceReader">The source reader.</param>
        /// <param name="destinationStream">The destination stream.</param>
        public void Convert(TextReader sourceReader, Stream destinationStream)
        {
            if (destinationStream == null)
            {
                throw new ArgumentNullException("destinationStream");
            }
            Stream stream = new ConverterStream(sourceReader, this);

            byte[] array = new byte[this.outputBufferSize];
            while (true)
            {
                int num = stream.Read(array, 0, array.Length);
                if (num == 0)
                {
                    break;
                }
                destinationStream.Write(array, 0, num);
            }
            destinationStream.Flush();
        }
Beispiel #9
0
 /// <summary>
 /// Creates the pull chain.
 /// </summary>
 /// <param name="input">The input TextReader.</param>
 /// <param name="converterStream">The converter stream.</param>
 /// <returns>An <see cref="T:Microsoft.Exchange.Data.TextConverters.IProducerConsumer" /> for use in a chain.</returns>
 internal abstract IProducerConsumer CreatePullChain(TextReader input, ConverterStream converterStream);
Beispiel #10
0
 /// <summary>
 /// Creates the push chain.
 /// </summary>
 /// <param name="converterStream">The converter stream.</param>
 /// <param name="output">The output.</param>
 /// <returns>An <see cref="T:Microsoft.Exchange.Data.TextConverters.IProducerConsumer" /> for use in a chain.</returns>
 internal abstract IProducerConsumer CreatePushChain(ConverterStream converterStream, TextWriter output);