Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / MS / Internal / IO / Packaging / IgnoreFlushAndCloseStream.cs / 1305600 / IgnoreFlushAndCloseStream.cs
//------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, 2005 // // File: IgnoreCloseAndFlushStream.cs // // Description: The class is used to wrap a given stream in a way that the Flush // and Close calls to the stream are Ignored. This stream class has been // created specifically for perf improvements for the ZipPackage. // // // History: 09/05/05 - SarjanaS - initial implementation //----------------------------------------------------------------------------- using System; using System.IO; using System.Windows; // for ExceptionStringTable using MS.Internal.WindowsBase; namespace MS.Internal.IO.Packaging { ////// This class ignores all calls to Flush() and Close() methods /// depending on whether the IgnoreFlushAndClose property is set to true /// or false. /// internal sealed class IgnoreFlushAndCloseStream : Stream { #region Constructor ////// Constructor /// /// internal IgnoreFlushAndCloseStream(Stream stream) { if (stream == null) throw new ArgumentNullException("stream"); _stream = stream; } #endregion Constructor #region Properties ////// Member of the abstract Stream class /// ///Bool, true if the stream can be read from, else false public override bool CanRead { get { if (_disposed) return false; else return _stream.CanRead; } } ////// Member of the abstract Stream class /// ///Bool, true if the stream can be seeked, else false public override bool CanSeek { get { if (_disposed) return false; else return _stream.CanSeek; } } ////// Member of the abstract Stream class /// ///Bool, true if the stream can be written to, else false public override bool CanWrite { get { if (_disposed) return false; else return _stream.CanWrite; } } ////// Member of the abstract Stream class /// ///Long value indicating the length of the stream public override long Length { get { ThrowIfStreamDisposed(); return _stream.Length; } } ////// Member of the abstract Stream class /// ///Long value indicating the current position in the stream public override long Position { get { ThrowIfStreamDisposed(); return _stream.Position; } set { ThrowIfStreamDisposed(); _stream.Position = value; } } #endregion Properties #region Methods ////// Member of the abstract Stream class /// /// only zero is supported /// only SeekOrigin.Begin is supported ///zero public override long Seek(long offset, SeekOrigin origin) { ThrowIfStreamDisposed(); return _stream.Seek(offset, origin); } ////// Member of the abstract Stream class /// /// public override void SetLength(long newLength) { ThrowIfStreamDisposed(); _stream.SetLength(newLength); } ////// Member of the abstract Stream class /// /// /// /// ////// /// The standard Stream.Read semantics, and in particular the restoration of the current /// position in case of an exception, is implemented by the underlying stream. /// public override int Read(byte[] buffer, int offset, int count) { ThrowIfStreamDisposed(); return _stream.Read(buffer, offset, count); } ////// Member of the abstract Stream class /// /// /// /// public override void Write(byte[] buf, int offset, int count) { ThrowIfStreamDisposed(); _stream.Write(buf, offset, count); } ////// Member of the abstract Stream class /// public override void Flush() { ThrowIfStreamDisposed(); } #endregion Methods //----------------------------------------------------- // // Protected Methods // //----------------------------------------------------- ////// Dispose(bool) /// /// protected override void Dispose(bool disposing) { try { if (!_disposed) { _stream = null; _disposed = true; } } finally { base.Dispose(disposing); } } #region Private Methods private void ThrowIfStreamDisposed() { if (_disposed) throw new ObjectDisposedException(null, SR.Get(SRID.StreamObjectDisposed)); } #endregion Private Methods #region Private Variables private Stream _stream; private bool _disposed; #endregion Private Variables } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DataRow.cs
- Coordinator.cs
- Rfc2898DeriveBytes.cs
- FormViewRow.cs
- StoreItemCollection.cs
- DocumentViewerConstants.cs
- WebConfigurationHostFileChange.cs
- InstancePersistence.cs
- WebSysDescriptionAttribute.cs
- PropertyReference.cs
- TimeManager.cs
- OutputCacheSettings.cs
- SymLanguageVendor.cs
- OdbcCommand.cs
- ListBoxChrome.cs
- ResourceDefaultValueAttribute.cs
- ReliableMessagingVersionConverter.cs
- SafeFileMappingHandle.cs
- ConditionalBranch.cs
- OptimalBreakSession.cs
- ParameterBuilder.cs
- SemaphoreFullException.cs
- Signature.cs
- MediaSystem.cs
- DesigntimeLicenseContextSerializer.cs
- ListBindableAttribute.cs
- WindowsSpinner.cs
- UIntPtr.cs
- PeerPresenceInfo.cs
- TreeNodeStyle.cs
- FixedSchema.cs
- ColumnHeader.cs
- IIS7UserPrincipal.cs
- ComplexPropertyEntry.cs
- LifetimeServices.cs
- RegexMatch.cs
- CodeEventReferenceExpression.cs
- CodeConditionStatement.cs
- ThicknessKeyFrameCollection.cs
- IMembershipProvider.cs
- Propagator.cs
- Transform.cs
- HtmlTableRowCollection.cs
- WizardForm.cs
- hresults.cs
- XmlValueConverter.cs
- ProgressBar.cs
- IncrementalReadDecoders.cs
- KeysConverter.cs
- CodeExporter.cs
- RedBlackList.cs
- QilSortKey.cs
- XmlSerializer.cs
- RemoteWebConfigurationHostServer.cs
- DefaultPropertyAttribute.cs
- webeventbuffer.cs
- CqlLexerHelpers.cs
- EntityClientCacheKey.cs
- CollectionContainer.cs
- ScriptDescriptor.cs
- EntityDataSourceSelectingEventArgs.cs
- SmtpSection.cs
- NestedContainer.cs
- DbProviderConfigurationHandler.cs
- EntityDataSourceDataSelectionPanel.cs
- UpdatableWrapper.cs
- SecurityKeyUsage.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- GreaterThan.cs
- SqlComparer.cs
- ChtmlTextWriter.cs
- RuleInfoComparer.cs
- ValuePatternIdentifiers.cs
- MonitorWrapper.cs
- Ticks.cs
- IFlowDocumentViewer.cs
- PropertyGeneratedEventArgs.cs
- PlatformNotSupportedException.cs
- StackOverflowException.cs
- DurationConverter.cs
- XmlSchema.cs
- StylusPointProperties.cs
- CopyAttributesAction.cs
- MailWriter.cs
- SecurityException.cs
- XmlSchemaSimpleTypeList.cs
- _KerberosClient.cs
- ExpressionBinding.cs
- EdmToObjectNamespaceMap.cs
- ProfileGroupSettings.cs
- ConfigurationElementCollection.cs
- BamlLocalizationDictionary.cs
- PaginationProgressEventArgs.cs
- HwndHost.cs
- WebSysDescriptionAttribute.cs
- TdsParser.cs
- ControlParameter.cs
- Size3D.cs
- TextEncodedRawTextWriter.cs
- DependencyObject.cs