Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Base / MS / Internal / IO / Packaging / IgnoreFlushAndCloseStream.cs / 1 / 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
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.
//------------------------------------------------------------------------------
// 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
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
- BitmapSourceSafeMILHandle.cs
- ColumnPropertiesGroup.cs
- ResetableIterator.cs
- ClonableStack.cs
- EncodingInfo.cs
- LinkGrep.cs
- TextDecorations.cs
- HMACSHA1.cs
- DynamicResourceExtension.cs
- ModuleBuilder.cs
- categoryentry.cs
- WebPartTransformerCollection.cs
- PerformanceCounters.cs
- ChtmlCommandAdapter.cs
- Types.cs
- UnicodeEncoding.cs
- RandomNumberGenerator.cs
- GroupBox.cs
- GrammarBuilder.cs
- ListenerPerfCounters.cs
- NavigatorInput.cs
- ActivityMetadata.cs
- ObjectPropertyMapping.cs
- DocumentReference.cs
- log.cs
- DataGridGeneralPage.cs
- Grant.cs
- ArrayTypeMismatchException.cs
- WebPartDisplayModeEventArgs.cs
- ObjectStateFormatter.cs
- SessionIDManager.cs
- DataSourceHelper.cs
- ValueQuery.cs
- SoapReflectionImporter.cs
- DomainUpDown.cs
- DataGridViewLinkCell.cs
- EqualityComparer.cs
- ValidatorCompatibilityHelper.cs
- ToolStripRenderEventArgs.cs
- PermissionSet.cs
- TypeConverterHelper.cs
- SubpageParagraph.cs
- BrowserDefinitionCollection.cs
- ControlEvent.cs
- StylusDevice.cs
- XslAstAnalyzer.cs
- NativeCppClassAttribute.cs
- StorageMappingItemLoader.cs
- CachedFontFamily.cs
- StringFormat.cs
- BufferedGraphicsManager.cs
- BinaryMethodMessage.cs
- BlurEffect.cs
- TextModifier.cs
- CalendarDay.cs
- DisplayNameAttribute.cs
- RegistrySecurity.cs
- TextSpanModifier.cs
- HtmlTableRow.cs
- EntityCodeGenerator.cs
- RawStylusInputCustomDataList.cs
- NodeInfo.cs
- StdRegProviderWrapper.cs
- _ConnectionGroup.cs
- EventLogPermissionEntryCollection.cs
- DefaultPropertyAttribute.cs
- PrintDialog.cs
- CounterSampleCalculator.cs
- UnmanagedMarshal.cs
- CollectionContainer.cs
- Win32SafeHandles.cs
- XmlAnyElementAttribute.cs
- Action.cs
- VariantWrapper.cs
- EpmTargetTree.cs
- HMACSHA1.cs
- Soap.cs
- PauseStoryboard.cs
- _UriSyntax.cs
- MetadataItemSerializer.cs
- CompilerGeneratedAttribute.cs
- ProxyHelper.cs
- DataTemplateKey.cs
- recordstatescratchpad.cs
- ServerIdentity.cs
- JsonWriter.cs
- WaitForChangedResult.cs
- TableRow.cs
- PieceNameHelper.cs
- XmlDictionaryReaderQuotasElement.cs
- WorkflowElementDialogWindow.xaml.cs
- ClickablePoint.cs
- TableAdapterManagerGenerator.cs
- TypedAsyncResult.cs
- ExtensionDataObject.cs
- FontCacheUtil.cs
- SignatureHelper.cs
- RoutedPropertyChangedEventArgs.cs
- WebHeaderCollection.cs
- ProviderBase.cs