Exemplo n.º 1
0
        public Stream GetContentWriteStream()
        {
            this.AssertOpen();
            if (this.contentWritten)
            {
                throw new InvalidOperationException(Strings.ContentAlreadyWritten);
            }
            if (this.partContent != null)
            {
                throw new InvalidOperationException(Strings.PartContentIsBeingWritten);
            }
            Stream rawContentWriteStream = this.GetRawContentWriteStream();

            if (this.contentTransferEncoding == ContentTransferEncoding.SevenBit || this.contentTransferEncoding == ContentTransferEncoding.EightBit || this.contentTransferEncoding == ContentTransferEncoding.Binary)
            {
                return(rawContentWriteStream);
            }
            if (this.contentTransferEncoding == ContentTransferEncoding.BinHex)
            {
                throw new NotSupportedException(Strings.BinHexNotSupportedForThisMethod);
            }
            ByteEncoder byteEncoder = MimePart.CreateEncoder(null, this.contentTransferEncoding);

            if (byteEncoder == null)
            {
                throw new NotSupportedException(Strings.UnrecognizedTransferEncodingUsed);
            }
            this.encodedPartContent = new EncoderStream(rawContentWriteStream, byteEncoder, EncoderStreamAccess.Write);
            return(new SuppressCloseStream(this.encodedPartContent));
        }