Code:
/ FX-1434 / FX-1434 / 1.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
- SecurityUtils.cs
- PolygonHotSpot.cs
- Logging.cs
- DynamicHyperLink.cs
- HtmlAnchor.cs
- DragDrop.cs
- StyleCollection.cs
- WebPartUtil.cs
- DesignerDataTable.cs
- MeasurementDCInfo.cs
- SafeNativeMethods.cs
- SafeReversePInvokeHandle.cs
- StorageComplexTypeMapping.cs
- _UriTypeConverter.cs
- StateInitialization.cs
- GridViewDeletedEventArgs.cs
- CategoryAttribute.cs
- WsdlInspector.cs
- VarRemapper.cs
- BrowserCapabilitiesCompiler.cs
- User.cs
- WebEncodingValidator.cs
- TextFormatterContext.cs
- SmtpAuthenticationManager.cs
- DataControlCommands.cs
- FunctionDetailsReader.cs
- WebServiceClientProxyGenerator.cs
- connectionpool.cs
- Pair.cs
- SpinLock.cs
- BinaryWriter.cs
- shaper.cs
- IndexedGlyphRun.cs
- HashHelper.cs
- ProfileService.cs
- Storyboard.cs
- PropertyDescriptorComparer.cs
- StylusPointPropertyInfo.cs
- SystemInformation.cs
- CroppedBitmap.cs
- GeneratedCodeAttribute.cs
- Int32KeyFrameCollection.cs
- Zone.cs
- SystemNetworkInterface.cs
- BreakRecordTable.cs
- DataProtection.cs
- SupportingTokenChannel.cs
- Operator.cs
- TableHeaderCell.cs
- Semaphore.cs
- PenContext.cs
- PopOutPanel.cs
- PingOptions.cs
- MemoryFailPoint.cs
- MobileCapabilities.cs
- LabelLiteral.cs
- AdPostCacheSubstitution.cs
- NetCodeGroup.cs
- DetailsViewInsertEventArgs.cs
- PageRequestManager.cs
- ListViewTableCell.cs
- StdValidatorsAndConverters.cs
- CodeDOMUtility.cs
- TaskFileService.cs
- Brush.cs
- SortFieldComparer.cs
- TypeInitializationException.cs
- UInt32Converter.cs
- SmiEventSink.cs
- FixedTextView.cs
- DataRow.cs
- Base64Encoder.cs
- KeyValueConfigurationElement.cs
- SpecialFolderEnumConverter.cs
- LayoutEditorPart.cs
- HttpListenerContext.cs
- DatatypeImplementation.cs
- CodeComment.cs
- MatrixKeyFrameCollection.cs
- SafeWaitHandle.cs
- Timer.cs
- ExpandSegmentCollection.cs
- X509ChainElement.cs
- ProfilePropertySettingsCollection.cs
- Int32RectConverter.cs
- ProofTokenCryptoHandle.cs
- MetadataSource.cs
- PatternMatchRules.cs
- Style.cs
- PopupRoot.cs
- RegionInfo.cs
- GB18030Encoding.cs
- WebBrowserHelper.cs
- PtsPage.cs
- EntitySqlQueryCacheKey.cs
- RequestCacheValidator.cs
- HttpConfigurationSystem.cs
- PrimarySelectionGlyph.cs
- EndpointBehaviorElementCollection.cs
- AsmxEndpointPickerExtension.cs