Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Net / System / Net / Mail / DelegatedStream.cs / 1305376 / 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
- RbTree.cs
- SynchronizationValidator.cs
- ScrollPatternIdentifiers.cs
- HttpHandlerAction.cs
- StrokeCollectionDefaultValueFactory.cs
- GregorianCalendar.cs
- ListViewEditEventArgs.cs
- _LoggingObject.cs
- DragDropManager.cs
- APCustomTypeDescriptor.cs
- XPathNavigator.cs
- printdlgexmarshaler.cs
- HandledEventArgs.cs
- PolyLineSegment.cs
- _ListenerRequestStream.cs
- EditCommandColumn.cs
- PhysicalFontFamily.cs
- CallId.cs
- ToolStripSeparator.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- GeneratedCodeAttribute.cs
- CacheVirtualItemsEvent.cs
- PolicyStatement.cs
- NumericExpr.cs
- JsonEncodingStreamWrapper.cs
- Drawing.cs
- ObjectViewQueryResultData.cs
- EndOfStreamException.cs
- PeerName.cs
- TemplateControlParser.cs
- TdsValueSetter.cs
- SelectorAutomationPeer.cs
- ActivityCodeGenerator.cs
- SqlUserDefinedTypeAttribute.cs
- WebPartChrome.cs
- ProjectionQueryOptionExpression.cs
- ListBase.cs
- OracleException.cs
- RemotingException.cs
- ModulesEntry.cs
- baseaxisquery.cs
- IgnoreSectionHandler.cs
- EnumerableWrapperWeakToStrong.cs
- WebPartEditorOkVerb.cs
- RegexStringValidatorAttribute.cs
- FixedSOMTable.cs
- Span.cs
- ScriptControlDescriptor.cs
- DictionaryCustomTypeDescriptor.cs
- InvalidateEvent.cs
- TextEffect.cs
- WebBrowserProgressChangedEventHandler.cs
- SecurityContext.cs
- UserPreferenceChangingEventArgs.cs
- StringPropertyBuilder.cs
- Common.cs
- CalendarDesigner.cs
- UncommonField.cs
- XmlSchemaAttributeGroupRef.cs
- BamlLocalizer.cs
- EventQueueState.cs
- XmlReflectionImporter.cs
- DataGridViewControlCollection.cs
- DataComponentMethodGenerator.cs
- CommandHelper.cs
- NameTable.cs
- XPathScanner.cs
- EraserBehavior.cs
- MatrixCamera.cs
- ControlIdConverter.cs
- messageonlyhwndwrapper.cs
- ActivationArguments.cs
- XPathAncestorQuery.cs
- CapabilitiesSection.cs
- AssociationSetEnd.cs
- HwndMouseInputProvider.cs
- Error.cs
- SchemaTypeEmitter.cs
- ActivityExecutionContext.cs
- ActionItem.cs
- ElementUtil.cs
- StyleBamlTreeBuilder.cs
- WebBrowserNavigatingEventHandler.cs
- UmAlQuraCalendar.cs
- EnumerationRangeValidationUtil.cs
- Pen.cs
- ConfigXmlText.cs
- CheckableControlBaseAdapter.cs
- FileSystemEventArgs.cs
- WebException.cs
- ParseChildrenAsPropertiesAttribute.cs
- SaveFileDialogDesigner.cs
- BrushConverter.cs
- CompModSwitches.cs
- DecimalConstantAttribute.cs
- ItemCheckedEvent.cs
- TemplateEditingService.cs
- DocumentViewerConstants.cs
- SaveWorkflowAsyncResult.cs
- odbcmetadatacollectionnames.cs