private void Initialize(Stream stream, string contentType, XmlDictionaryReaderQuotas quotas, int maxBufferSize) { string str; string str2; string str3; if (stream == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream"); } this.maxBufferSize = maxBufferSize; this.bufferRemaining = maxBufferSize; if (contentType == null) { MimeMessageReader reader = new MimeMessageReader(stream); MimeHeaders headers = reader.ReadHeaders(this.maxBufferSize, ref this.bufferRemaining); this.ReadMessageMimeVersionHeader(headers.MimeVersion); this.ReadMessageContentTypeHeader(headers.ContentType, out str, out str2, out str3); stream = reader.GetContentStream(); if (stream == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.Runtime.Serialization.SR.GetString("MtomMessageInvalidContent"))); } } else { this.ReadMessageContentTypeHeader(new ContentTypeHeader(contentType), out str, out str2, out str3); } this.mimeReader = new MimeReader(stream, str); this.mimeParts = null; this.readingBinaryElement = false; MimePart part = (str2 == null) ? this.ReadRootMimePart() : this.ReadMimePart(this.GetStartUri(str2)); byte[] buffer = part.GetBuffer(this.maxBufferSize, ref this.bufferRemaining); int length = (int) part.Length; Encoding encoding = this.ReadRootContentTypeHeader(part.Headers.ContentType, this.encodings, str3); this.CheckContentTransferEncodingOnRoot(part.Headers.ContentTransferEncoding); IXmlTextReaderInitializer xmlReader = this.xmlReader as IXmlTextReaderInitializer; if (xmlReader != null) { xmlReader.SetInput(buffer, 0, length, encoding, quotas, null); } else { this.xmlReader = XmlDictionaryReader.CreateTextReader(buffer, 0, length, encoding, quotas, null); } }
void Initialize(Stream stream, string contentType, XmlDictionaryReaderQuotas quotas, int maxBufferSize) { if (stream == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("stream"); this.maxBufferSize = maxBufferSize; this.bufferRemaining = maxBufferSize; string boundary, start, startInfo; if (contentType == null) { MimeMessageReader messageReader = new MimeMessageReader(stream); MimeHeaders messageHeaders = messageReader.ReadHeaders(this.maxBufferSize, ref this.bufferRemaining); ReadMessageMimeVersionHeader(messageHeaders.MimeVersion); ReadMessageContentTypeHeader(messageHeaders.ContentType, out boundary, out start, out startInfo); stream = messageReader.GetContentStream(); if (stream == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.MtomMessageInvalidContent))); } else { ReadMessageContentTypeHeader(new ContentTypeHeader(contentType), out boundary, out start, out startInfo); } this.mimeReader = new MimeReader(stream, boundary); this.mimeParts = null; this.readingBinaryElement = false; MimePart infosetPart = (start == null) ? ReadRootMimePart() : ReadMimePart(GetStartUri(start)); byte[] infosetBytes = infosetPart.GetBuffer(this.maxBufferSize, ref this.bufferRemaining); int infosetByteCount = (int)infosetPart.Length; Encoding encoding = ReadRootContentTypeHeader(infosetPart.Headers.ContentType, this.encodings, startInfo); CheckContentTransferEncodingOnRoot(infosetPart.Headers.ContentTransferEncoding); IXmlTextReaderInitializer initializer = xmlReader as IXmlTextReaderInitializer; if (initializer != null) initializer.SetInput(infosetBytes, 0, infosetByteCount, encoding, quotas, null); else xmlReader = XmlDictionaryReader.CreateTextReader(infosetBytes, 0, infosetByteCount, encoding, quotas, null); }