Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Net / System / Net / Mail / DelegatedStream.cs / 1 / DelegatedStream.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net { using System; using System.Net.Sockets; using System.IO; internal class DelegatedStream : Stream { Stream stream; NetworkStream netStream; protected DelegatedStream() { } protected DelegatedStream(Stream stream) { if (stream == null) throw new ArgumentNullException("stream"); this.stream = stream; netStream = stream as NetworkStream; } protected Stream BaseStream { get { return this.stream; } } public override bool CanRead { get { return this.stream.CanRead; } } public override bool CanSeek { get { return this.stream.CanSeek; } } public override bool CanWrite { get { return this.stream.CanWrite; } } public override long Length { get { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); return this.stream.Length; } } public override long Position { get { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); return this.stream.Position; } set { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); this.stream.Position = value; } } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { if (!CanRead) throw new NotSupportedException(SR.GetString(SR.ReadNotSupported)); IAsyncResult result = null; if(netStream != null){ result = this.netStream.UnsafeBeginRead (buffer, offset, count, callback, state); } else{ result = this.stream.BeginRead (buffer, offset, count, callback, state); } return result; } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { if (!CanWrite) throw new NotSupportedException(SR.GetString(SR.WriteNotSupported)); IAsyncResult result = null; if(netStream != null){ result = this.netStream.UnsafeBeginWrite(buffer, offset, count, callback, state); } else{ result = this.stream.BeginWrite (buffer, offset, count, callback, state); } return result; } //This calls close on the inner stream //however, the stream may not be actually closed, but simpy flushed public override void Close() { this.stream.Close(); } public override int EndRead(IAsyncResult asyncResult) { if (!CanRead) throw new NotSupportedException(SR.GetString(SR.ReadNotSupported)); int read = this.stream.EndRead (asyncResult); return read; } public override void EndWrite(IAsyncResult asyncResult) { if (!CanWrite) throw new NotSupportedException(SR.GetString(SR.WriteNotSupported)); this.stream.EndWrite (asyncResult); } public override void Flush() { this.stream.Flush(); } public override int Read(byte[] buffer, int offset, int count) { if (!CanRead) throw new NotSupportedException(SR.GetString(SR.ReadNotSupported)); int read = this.stream.Read(buffer, offset, count); return read; } public override long Seek(long offset, SeekOrigin origin) { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); long position = this.stream.Seek(offset, origin); return position; } public override void SetLength(long value) { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); this.stream.SetLength(value); } public override void Write(byte[] buffer, int offset, int count) { if (!CanWrite) throw new NotSupportedException(SR.GetString(SR.WriteNotSupported)); this.stream.Write(buffer, offset, count); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net { using System; using System.Net.Sockets; using System.IO; internal class DelegatedStream : Stream { Stream stream; NetworkStream netStream; protected DelegatedStream() { } protected DelegatedStream(Stream stream) { if (stream == null) throw new ArgumentNullException("stream"); this.stream = stream; netStream = stream as NetworkStream; } protected Stream BaseStream { get { return this.stream; } } public override bool CanRead { get { return this.stream.CanRead; } } public override bool CanSeek { get { return this.stream.CanSeek; } } public override bool CanWrite { get { return this.stream.CanWrite; } } public override long Length { get { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); return this.stream.Length; } } public override long Position { get { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); return this.stream.Position; } set { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); this.stream.Position = value; } } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { if (!CanRead) throw new NotSupportedException(SR.GetString(SR.ReadNotSupported)); IAsyncResult result = null; if(netStream != null){ result = this.netStream.UnsafeBeginRead (buffer, offset, count, callback, state); } else{ result = this.stream.BeginRead (buffer, offset, count, callback, state); } return result; } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { if (!CanWrite) throw new NotSupportedException(SR.GetString(SR.WriteNotSupported)); IAsyncResult result = null; if(netStream != null){ result = this.netStream.UnsafeBeginWrite(buffer, offset, count, callback, state); } else{ result = this.stream.BeginWrite (buffer, offset, count, callback, state); } return result; } //This calls close on the inner stream //however, the stream may not be actually closed, but simpy flushed public override void Close() { this.stream.Close(); } public override int EndRead(IAsyncResult asyncResult) { if (!CanRead) throw new NotSupportedException(SR.GetString(SR.ReadNotSupported)); int read = this.stream.EndRead (asyncResult); return read; } public override void EndWrite(IAsyncResult asyncResult) { if (!CanWrite) throw new NotSupportedException(SR.GetString(SR.WriteNotSupported)); this.stream.EndWrite (asyncResult); } public override void Flush() { this.stream.Flush(); } public override int Read(byte[] buffer, int offset, int count) { if (!CanRead) throw new NotSupportedException(SR.GetString(SR.ReadNotSupported)); int read = this.stream.Read(buffer, offset, count); return read; } public override long Seek(long offset, SeekOrigin origin) { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); long position = this.stream.Seek(offset, origin); return position; } public override void SetLength(long value) { if (!CanSeek) throw new NotSupportedException(SR.GetString(SR.SeekNotSupported)); this.stream.SetLength(value); } public override void Write(byte[] buffer, int offset, int count) { if (!CanWrite) throw new NotSupportedException(SR.GetString(SR.WriteNotSupported)); this.stream.Write(buffer, offset, count); } } } // 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
- DateTimeConverter.cs
- ServiceContractGenerator.cs
- ItemCollection.cs
- BoundPropertyEntry.cs
- Rectangle.cs
- DelayedRegex.cs
- DataBinder.cs
- XsltArgumentList.cs
- EncodingInfo.cs
- TrackingLocationCollection.cs
- _OverlappedAsyncResult.cs
- MergeFilterQuery.cs
- Int16Animation.cs
- DelegateSerializationHolder.cs
- LogEntryUtils.cs
- Event.cs
- GeometryModel3D.cs
- DiscoveryClientChannelBase.cs
- ModelFactory.cs
- WindowsFormsDesignerOptionService.cs
- ObjectCloneHelper.cs
- XmlAttributeAttribute.cs
- PersistenceTypeAttribute.cs
- IApplicationTrustManager.cs
- Menu.cs
- UrlMappingsModule.cs
- EntityParameterCollection.cs
- PatternMatchRules.cs
- PeerNameResolver.cs
- HyperLinkField.cs
- RangeValidator.cs
- ProxyWebPartConnectionCollection.cs
- TextSelection.cs
- TraceListeners.cs
- EdmFunction.cs
- ContainerControl.cs
- AspProxy.cs
- InternalResources.cs
- UniqueIdentifierService.cs
- GenericsInstances.cs
- MissingSatelliteAssemblyException.cs
- FixedSOMLineCollection.cs
- Int64AnimationUsingKeyFrames.cs
- GACIdentityPermission.cs
- SupportingTokenChannel.cs
- FacetValueContainer.cs
- GeneralTransform.cs
- CharConverter.cs
- TransformerInfo.cs
- IPHostEntry.cs
- FrameSecurityDescriptor.cs
- assertwrapper.cs
- ProjectionPruner.cs
- MouseActionConverter.cs
- DataGridRelationshipRow.cs
- AppDomainAttributes.cs
- InstallerTypeAttribute.cs
- WasEndpointConfigContainer.cs
- externdll.cs
- wgx_sdk_version.cs
- Nullable.cs
- RC2.cs
- FrameworkElementFactoryMarkupObject.cs
- ICspAsymmetricAlgorithm.cs
- StoreContentChangedEventArgs.cs
- TypeRefElement.cs
- FormsAuthenticationTicket.cs
- SQLMoneyStorage.cs
- StrokeNodeOperations2.cs
- XmlSchemaObjectTable.cs
- EntityCommandCompilationException.cs
- WebPartManagerInternals.cs
- ExpandCollapsePatternIdentifiers.cs
- LinqDataSourceValidationException.cs
- InputBinder.cs
- OleDbParameterCollection.cs
- ImageEditor.cs
- SerializerDescriptor.cs
- CorrelationScope.cs
- BamlReader.cs
- ScriptingRoleServiceSection.cs
- HtmlLinkAdapter.cs
- EpmAttributeNameBuilder.cs
- DataTableMappingCollection.cs
- CryptoApi.cs
- WinCategoryAttribute.cs
- ProcessModelInfo.cs
- NetworkCredential.cs
- FragmentQueryKB.cs
- Int32Storage.cs
- AcceptorSessionSymmetricTransportSecurityProtocol.cs
- WebBrowserBase.cs
- SafeCloseHandleCritical.cs
- AnimationStorage.cs
- OdbcConnectionHandle.cs
- VoiceChangeEventArgs.cs
- ConsumerConnectionPointCollection.cs
- PolyQuadraticBezierSegment.cs
- OverflowException.cs
- GcHandle.cs