public XmlEncodedRawTextWriter(Stream stream, XmlWriterSettings settings) : this(settings) { this.stream = stream; this.encoding = settings.Encoding; this.bufChars = new char[0x1820]; this.bufBytes = new byte[this.bufChars.Length]; this.bufBytesUsed = 0; this.trackTextContent = true; this.inTextContent = false; this.lastMarkPos = 0; this.textContentMarks = new int[0x40]; this.textContentMarks[0] = 1; this.charEntityFallback = new CharEntityEncoderFallback(); this.encoding = (Encoding) settings.Encoding.Clone(); this.encoding.EncoderFallback = this.charEntityFallback; this.encoder = this.encoding.GetEncoder(); if (!stream.CanSeek || (stream.Position == 0L)) { byte[] preamble = this.encoding.GetPreamble(); if (preamble.Length != 0) { this.stream.Write(preamble, 0, preamble.Length); } } if (settings.AutoXmlDeclaration) { this.WriteXmlDeclaration(this.standalone); this.autoXmlDeclaration = true; } }
internal CharEntityEncoderFallbackBuffer(CharEntityEncoderFallback parent) { _parent = parent; }
// Construct an instance of this class that serializes to a Stream interface. public XmlEncodedRawTextWriter( Stream stream, XmlWriterSettings settings ) : this( settings ) { Debug.Assert( stream != null && settings != null ); this.stream = stream; this.encoding = settings.Encoding; // the buffer is allocated will OVERFLOW in order to reduce checks when writing out constant size markup if (settings.Async) { bufLen = ASYNCBUFSIZE; } bufChars = new char[bufLen + OVERFLOW]; bufBytes = new byte[ bufChars.Length ]; bufBytesUsed = 0; // Init escaping of characters not fitting into the target encoding trackTextContent = true; inTextContent = false; lastMarkPos = 0; textContentMarks = new int[INIT_MARKS_COUNT]; textContentMarks[0] = 1; charEntityFallback = new CharEntityEncoderFallback(); this.encoding = (Encoding)settings.Encoding.Clone(); encoding.EncoderFallback = charEntityFallback; encoder = encoding.GetEncoder(); if ( !stream.CanSeek || stream.Position == 0 ) { byte[] bom = encoding.GetPreamble(); if ( bom.Length != 0 ) { this.stream.Write( bom, 0, bom.Length ); } } // Write the xml declaration if ( settings.AutoXmlDeclaration ) { WriteXmlDeclaration( standalone ); autoXmlDeclaration = true; } }