public XmlByteStreamWriter(Stream stream, bool ownsStream) { Fx.Assert(stream != null, "stream is null"); this.stream = stream; this.ownsStream = ownsStream; this.state = ByteStreamWriterState.Start; }
void InternalWriteEndElement() { ThrowIfClosed(); if (this.state != ByteStreamWriterState.StartElement && this.state != ByteStreamWriterState.Content) { throw FxTrace.Exception.AsError( new InvalidOperationException(SR.XmlUnexpectedEndElement)); } this.state = ByteStreamWriterState.EndElement; }
public override void WriteStartElement(string prefix, string localName, string ns) { ThrowIfClosed(); if (this.state != ByteStreamWriterState.Start) { throw FxTrace.Exception.AsError( new InvalidOperationException(SR.ByteStreamWriteStartElementAlreadyCalled)); } if (!string.IsNullOrEmpty(prefix) || !string.IsNullOrEmpty(ns) || localName != ByteStreamMessageUtility.StreamElementName) { throw FxTrace.Exception.AsError( new XmlException(SR.XmlStartElementNameExpected(ByteStreamMessageUtility.StreamElementName, localName))); } this.state = ByteStreamWriterState.StartElement; }
public override void Close() { if (this.state != ByteStreamWriterState.Closed) { try { if (ownsStream) { this.stream.Close(); } this.stream = null; } finally { this.state = ByteStreamWriterState.Closed; } } }
static WriteState ByteStreamWriterStateToWriteState(ByteStreamWriterState byteStreamWriterState) { // Converts the internal ByteStreamWriterState to an Xml WriteState switch (byteStreamWriterState) { case ByteStreamWriterState.Start: return(WriteState.Start); case ByteStreamWriterState.StartElement: return(WriteState.Element); case ByteStreamWriterState.Content: return(WriteState.Content); case ByteStreamWriterState.EndElement: return(WriteState.Element); case ByteStreamWriterState.Closed: return(WriteState.Closed); default: return(WriteState.Error); } }
static WriteState ByteStreamWriterStateToWriteState(ByteStreamWriterState byteStreamWriterState) { // Converts the internal ByteStreamWriterState to an Xml WriteState switch (byteStreamWriterState) { case ByteStreamWriterState.Start: return WriteState.Start; case ByteStreamWriterState.StartElement: return WriteState.Element; case ByteStreamWriterState.Content: return WriteState.Content; case ByteStreamWriterState.EndElement: return WriteState.Element; case ByteStreamWriterState.Closed: return WriteState.Closed; default: return WriteState.Error; } }
public override void WriteBase64(byte[] buffer, int index, int count) { EnsureWriteBase64State(buffer, index, count); this.stream.Write(buffer, index, count); this.state = ByteStreamWriterState.Content; }