Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Channels / StreamBodyWriter.cs / 1305376 / StreamBodyWriter.cs
//---------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------------------- namespace System.ServiceModel.Channels { using System; using System.IO; using System.Runtime; using System.ServiceModel; using System.Xml; using DiagnosticUtility = System.ServiceModel.DiagnosticUtility; public abstract class StreamBodyWriter : BodyWriter { protected StreamBodyWriter(bool isBuffered) : base(isBuffered) { } internal static StreamBodyWriter CreateStreamBodyWriter(ActionstreamAction) { if (streamAction == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("actionOfStream"); } return new ActionOfStreamBodyWriter(streamAction); } protected abstract void OnWriteBodyContents(Stream stream); protected override BodyWriter OnCreateBufferedCopy(int maxBufferSize) { using (BufferManagerOutputStream bufferedStream = new BufferManagerOutputStream(SR2.MaxReceivedMessageSizeExceeded, maxBufferSize)) { this.OnWriteBodyContents(bufferedStream); int size; byte[] bytesArray = bufferedStream.ToArray(out size); return new BufferedBytesStreamBodyWriter(bytesArray, size); } } protected override void OnWriteBodyContents(XmlDictionaryWriter writer) { using (XmlWriterBackedStream stream = new XmlWriterBackedStream(writer)) { OnWriteBodyContents(stream); } } class XmlWriterBackedStream : Stream { XmlWriter writer; public XmlWriterBackedStream(XmlWriter writer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } this.writer = writer; } public override bool CanRead { get { return false; } } public override bool CanSeek { get { return false; } } public override bool CanWrite { get { return true; } } public override void Flush() { this.writer.Flush(); } public override long Length { get { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamPropertyGetNotSupported, "Length"))); } } public override long Position { get { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamPropertyGetNotSupported, "Position"))); } set { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamPropertySetNotSupported, "Position"))); } } public override int Read(byte[] buffer, int offset, int count) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "Read"))); } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "BeginRead"))); } public override int EndRead(IAsyncResult asyncResult) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "EndRead"))); } public override int ReadByte() { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "ReadByte"))); } public override long Seek(long offset, SeekOrigin origin) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "Seek"))); } public override void SetLength(long value) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(new InvalidOperationException(SR2.GetString(SR2.XmlWriterBackedStreamMethodNotSupported, "SetLength"))); } public override void Write(byte[] buffer, int offset, int count) { this.writer.WriteBase64(buffer, offset, count); } } class BufferedBytesStreamBodyWriter : StreamBodyWriter { byte[] array; int size; public BufferedBytesStreamBodyWriter(byte[] array, int size) : base(true) { this.array = array; this.size = size; } protected override void OnWriteBodyContents(Stream stream) { stream.Write(this.array, 0, this.size); } } class ActionOfStreamBodyWriter : StreamBodyWriter { Action actionOfStream; public ActionOfStreamBodyWriter(Action actionOfStream) : base(false) { this.actionOfStream = actionOfStream; } protected override void OnWriteBodyContents(Stream stream) { actionOfStream(stream); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Literal.cs
- SparseMemoryStream.cs
- SafeProcessHandle.cs
- OleTxTransactionInfo.cs
- ActivityCodeDomSerializer.cs
- SecurityException.cs
- ConnectionManagementElement.cs
- ExtensionFile.cs
- WindowsFormsLinkLabel.cs
- SecurityRuntime.cs
- ContentPlaceHolder.cs
- HttpRuntimeSection.cs
- CharacterBufferReference.cs
- TextSyndicationContentKindHelper.cs
- FormViewInsertedEventArgs.cs
- TextPointerBase.cs
- SmtpFailedRecipientException.cs
- MembershipUser.cs
- BamlReader.cs
- ActivityExecutionFilter.cs
- Maps.cs
- DPTypeDescriptorContext.cs
- AnimationClockResource.cs
- MetadataPropertyCollection.cs
- FunctionMappingTranslator.cs
- PointLightBase.cs
- OrderPreservingPipeliningMergeHelper.cs
- DataGridViewRowStateChangedEventArgs.cs
- TreeViewHitTestInfo.cs
- BuildProviderAppliesToAttribute.cs
- DefaultBinder.cs
- SqlCharStream.cs
- DocumentPaginator.cs
- AdapterUtil.cs
- DeflateStream.cs
- Icon.cs
- MachineKeyConverter.cs
- StringAnimationUsingKeyFrames.cs
- DiagnosticTrace.cs
- BasePropertyDescriptor.cs
- ProfileService.cs
- ObjectItemNoOpAssemblyLoader.cs
- Metafile.cs
- SQLMoneyStorage.cs
- RegexCharClass.cs
- LocalValueEnumerator.cs
- MachineKeySection.cs
- TypefaceMap.cs
- ToolStripDropDownButton.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- Thickness.cs
- ReaderContextStackData.cs
- ImageSourceConverter.cs
- PartialTrustHelpers.cs
- MatchSingleFxEngineOpcode.cs
- HttpCookiesSection.cs
- OutOfProcStateClientManager.cs
- CommandHelpers.cs
- PersistenceTypeAttribute.cs
- XsltCompileContext.cs
- EmptyElement.cs
- WebServicesSection.cs
- SystemSounds.cs
- EntryWrittenEventArgs.cs
- RangeValidator.cs
- GeometryDrawing.cs
- XmlReader.cs
- FactoryId.cs
- DataServiceRequest.cs
- TraceContextEventArgs.cs
- TreeNodeBindingCollection.cs
- SqlCaseSimplifier.cs
- NavigationFailedEventArgs.cs
- BaseTemplateBuildProvider.cs
- SchemaLookupTable.cs
- CommandPlan.cs
- FileDialog_Vista_Interop.cs
- PopOutPanel.cs
- UserInitiatedNavigationPermission.cs
- Timeline.cs
- OleDbStruct.cs
- AnnotationAdorner.cs
- SqlProfileProvider.cs
- CachedBitmap.cs
- Site.cs
- ReflectionUtil.cs
- QuaternionAnimation.cs
- AssemblyBuilder.cs
- FieldBuilder.cs
- XPathChildIterator.cs
- RuntimeVariableList.cs
- DynamicResourceExtension.cs
- ArglessEventHandlerProxy.cs
- NumberFormatter.cs
- DataGridCellAutomationPeer.cs
- MatchAllMessageFilter.cs
- EventListenerClientSide.cs
- FontDifferentiator.cs
- XmlDataSourceDesigner.cs
- ResourceDescriptionAttribute.cs