void EnsureWriteBase64State(byte[] buffer, int index, int count) { ThrowIfClosed(); ByteStreamMessageUtility.EnsureByteBoundaries(buffer, index, count, false); if (this.state != ByteStreamWriterState.Content && this.state != ByteStreamWriterState.StartElement) { throw FxTrace.Exception.AsError( new InvalidOperationException(SR.XmlWriterMustBeInElement(ByteStreamWriterStateToWriteState(this.state)))); } }
public InternalByteStreamMessage(ByteStreamBufferedMessageData bufferedMessageData, XmlDictionaryReaderQuotas quotas, bool moveBodyReaderToContent) { // Assign both writer and reader here so that we can CreateBufferedCopy without the need to // abstract between a streamed or buffered message. We're protected here by the state on Message // preventing both a read/write. quotas = ByteStreamMessageUtility.EnsureQuotas(quotas); this.bodyWriter = new BufferedBodyWriter(bufferedMessageData); this.headers = new MessageHeaders(MessageVersion.None); this.properties = new MessageProperties(); this.reader = new XmlBufferedByteStreamReader(bufferedMessageData, quotas); this.moveBodyReaderToContent = moveBodyReaderToContent; }
public InternalByteStreamMessage(HttpResponseMessage httpResponseMessage, XmlDictionaryReaderQuotas quotas, bool moveBodyReaderToContent) { Fx.Assert(httpResponseMessage != null, "The 'httpResponseMessage' parameter should not be null."); // Assign both writer and reader here so that we can CreateBufferedCopy without the need to // abstract between a streamed or buffered message. We're protected here by the state on Message // preventing both a read/write on the same stream. quotas = ByteStreamMessageUtility.EnsureQuotas(quotas); this.bodyWriter = StreamedBodyWriter.Create(httpResponseMessage); this.headers = new MessageHeaders(MessageVersion.None); this.properties = new MessageProperties(); this.reader = XmlStreamedByteStreamReader.Create(httpResponseMessage, quotas); this.moveBodyReaderToContent = moveBodyReaderToContent; }
public override int ReadContentAsBase64(byte[] buffer, int index, int count) { EnsureInContent(); ByteStreamMessageUtility.EnsureByteBoundaries(buffer, index, count, true); if (count == 0) { return(0); } Stream stream = this.GetStream(); int numBytesRead = stream.Read(buffer, index, count); if (numBytesRead == 0) { this.position = ReaderPosition.EndElement; } return(numBytesRead); }
public override int ReadContentAsBase64(byte[] buffer, int index, int count) { EnsureInContent(); ByteStreamMessageUtility.EnsureByteBoundaries(buffer, index, count, true); if (count == 0) { return(0); } int bytesToCopy = Math.Min(bufferedMessageData.Buffer.Count - this.offset, count); if (bytesToCopy == 0) { this.position = ReaderPosition.EndElement; return(0); } Buffer.BlockCopy(this.bufferedMessageData.Buffer.Array, this.offset, buffer, index, bytesToCopy); this.offset += bytesToCopy; return(bytesToCopy); }