private static object FromTextToHtml(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                HtmlWriteConverterStream htmlWriteConverterStream = new HtmlWriteConverterStream(bodyStream, new TextToHtml
                {
                    InputEncoding      = configuration.SourceEncoding,
                    Header             = configuration.InjectPrefix,
                    Footer             = configuration.InjectSuffix,
                    HeaderFooterFormat = configuration.InjectionHeaderFooterFormat,
                    HtmlTagCallback    = configuration.InternalHtmlTagCallback,
                    FilterHtml         = configuration.FilterHtml
                });
                stream = htmlWriteConverterStream;
                stream = new BodyCharsetDetectionStream(stream, new BodyCharsetDetectionStream.DetectCharsetCallback(htmlWriteConverterStream.SetCharset), coreItem, BodyStreamFormat.Text, configuration.SourceCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, BodyWriteDelegates.GetExtraData(configuration), false);
                obj    = BodyWriteDelegates.GetStreamOrUnicodeWriter(stream, createWriter);
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }
        private static object FromHtmlToHtml(ICoreItem coreItem, BodyWriteConfiguration configuration, Stream bodyStream, bool createWriter)
        {
            Stream stream = null;
            object obj    = null;

            try
            {
                if (!createWriter && configuration.SourceCharset == null)
                {
                    obj = bodyStream;
                }
                else
                {
                    HtmlToHtml htmlToHtml = new HtmlToHtml();
                    htmlToHtml.InputEncoding             = configuration.SourceEncoding;
                    htmlToHtml.DetectEncodingFromMetaTag = configuration.TrustHtmlMetaTag;
                    htmlToHtml.FilterHtml         = configuration.FilterHtml;
                    htmlToHtml.HtmlTagCallback    = configuration.InternalHtmlTagCallback;
                    htmlToHtml.Header             = configuration.InjectPrefix;
                    htmlToHtml.Footer             = configuration.InjectSuffix;
                    htmlToHtml.HeaderFooterFormat = configuration.InjectionHeaderFooterFormat;
                    bool canSkipConversionOnMatchingCharset           = !configuration.IsContentTransformationNeeded(coreItem);
                    HtmlWriteConverterStream htmlWriteConverterStream = new HtmlWriteConverterStream(bodyStream, htmlToHtml, canSkipConversionOnMatchingCharset);
                    stream = htmlWriteConverterStream;
                    stream = new BodyCharsetDetectionStream(htmlWriteConverterStream, new BodyCharsetDetectionStream.DetectCharsetCallback(htmlWriteConverterStream.SetCharset), coreItem, BodyStreamFormat.Html, configuration.SourceCharset, configuration.TargetCharset, configuration.TargetCharsetFlags, BodyWriteDelegates.GetExtraData(configuration), configuration.TrustHtmlMetaTag);
                    obj    = BodyWriteDelegates.GetStreamOrUnicodeWriter(stream, createWriter);
                }
            }
            finally
            {
                if (obj == null && stream != null)
                {
                    BodyWriteDelegates.SafeDisposeStream(stream);
                }
            }
            return(obj);
        }