Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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); } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CreateCardRequest.cs
- QilList.cs
- RegistryExceptionHelper.cs
- ProtocolsConfiguration.cs
- OdbcRowUpdatingEvent.cs
- Privilege.cs
- ChooseAction.cs
- indexingfiltermarshaler.cs
- Funcletizer.cs
- ResolveMatchesApril2005.cs
- RawStylusSystemGestureInputReport.cs
- ChildTable.cs
- ToolTipAutomationPeer.cs
- _AcceptOverlappedAsyncResult.cs
- OpenTypeMethods.cs
- DbConnectionPoolOptions.cs
- ExpressionConverter.cs
- QueryExpr.cs
- CharacterBufferReference.cs
- DateTimeValueSerializerContext.cs
- SqlConnectionStringBuilder.cs
- ControlCommandSet.cs
- RSAOAEPKeyExchangeFormatter.cs
- DSASignatureDeformatter.cs
- SqlBuilder.cs
- SessionPageStateSection.cs
- ResourceReader.cs
- DesignerContextDescriptor.cs
- _AutoWebProxyScriptEngine.cs
- DoubleAnimationUsingKeyFrames.cs
- coordinator.cs
- TextEditorMouse.cs
- HttpBindingExtension.cs
- LockedBorderGlyph.cs
- DBNull.cs
- XmlSortKey.cs
- CustomErrorsSectionWrapper.cs
- SizeF.cs
- ErrorInfoXmlDocument.cs
- SchemaMapping.cs
- PageHandlerFactory.cs
- FloaterBaseParagraph.cs
- BindValidator.cs
- SiteMapNodeItem.cs
- GeneralTransform3DCollection.cs
- CngKey.cs
- DataSourceHelper.cs
- EventProperty.cs
- ThreadInterruptedException.cs
- UidManager.cs
- _BaseOverlappedAsyncResult.cs
- NavigationProperty.cs
- RoleGroupCollection.cs
- CellQuery.cs
- XsdValidatingReader.cs
- SQLInt32.cs
- LineInfo.cs
- CompilerLocalReference.cs
- InstanceValue.cs
- AnonymousIdentificationModule.cs
- XPathMultyIterator.cs
- ScrollContentPresenter.cs
- TraceSwitch.cs
- PolyBezierSegment.cs
- EncoderFallback.cs
- CounterCreationDataConverter.cs
- MsmqBindingElementBase.cs
- IxmlLineInfo.cs
- EventDescriptor.cs
- HttpConfigurationSystem.cs
- SafeNativeMethodsOther.cs
- ResourceManager.cs
- MsmqOutputChannel.cs
- PropertyConverter.cs
- RectConverter.cs
- DragAssistanceManager.cs
- DefinitionBase.cs
- QueryOutputWriter.cs
- Cast.cs
- SkipStoryboardToFill.cs
- SqlClientMetaDataCollectionNames.cs
- Clipboard.cs
- Rules.cs
- DataGridViewToolTip.cs
- AnonymousIdentificationSection.cs
- BitmapEncoder.cs
- RegistryDataKey.cs
- WebWorkflowRole.cs
- AccessViolationException.cs
- ConfigurationValue.cs
- DisplayToken.cs
- TabPanel.cs
- PageSetupDialog.cs
- OperandQuery.cs
- MobileCapabilities.cs
- StackSpiller.cs
- uribuilder.cs
- MemberHolder.cs
- Char.cs
- ContextProperty.cs