Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Base / MS / Internal / IO / Zip / WriteTimeStream.cs / 1 / WriteTimeStream.cs
//------------------------------------------------------------------------------ // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // Description: // WriteTimeStream - wraps the ArchiveStream in Streaming generation scenarios so that we // can determine current archive stream offset even when working on a stream that is non-seekable // because the Position property is unusable on such streams. // // History: // 03/25/2002: [....]: Created. // //----------------------------------------------------------------------------- using System; using System.IO; using System.Windows; namespace MS.Internal.IO.Zip { internal class WriteTimeStream : Stream { //----------------------------------------------------- // // Public Properties // //----------------------------------------------------- ////// CanRead - never /// override public bool CanRead { get { return false; } } ////// CanSeek - never /// override public bool CanSeek{ get { return false; } } ////// CanWrite - only if we are not disposed /// override public bool CanWrite { get { return (_baseStream != null); } } ////// Same as Position /// override public long Length { get { CheckDisposed(); return _position; } } ////// Get is supported even on Write-only stream /// override public long Position { get { CheckDisposed(); return _position; } set { CheckDisposed(); IllegalAccess(); // throw exception } } //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- public override void SetLength(long newLength) { IllegalAccess(); // throw exception } override public long Seek(long offset, SeekOrigin origin) { IllegalAccess(); // throw exception return -1; // keep compiler happy } override public int Read(byte[] buffer, int offset, int count) { IllegalAccess(); // throw exception return -1; // keep compiler happy } override public void Write(byte[] buffer, int offset, int count) { CheckDisposed(); _baseStream.Write(buffer, offset, count); checked{_position += count;} } override public void Flush() { CheckDisposed(); _baseStream.Flush(); } //------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ internal WriteTimeStream(Stream baseStream) { if (baseStream == null) { throw new ArgumentNullException("baseStream"); } _baseStream = baseStream; // must be based on writable stream if (!_baseStream.CanWrite) throw new ArgumentException(SR.Get(SRID.WriteNotSupported), "baseStream"); } //----------------------------------------------------- // // Protected Methods // //------------------------------------------------------ protected override void Dispose(bool disposing) { try { if (disposing && (_baseStream != null)) { _baseStream.Close(); } } finally { _baseStream = null; base.Dispose(disposing); } } //----------------------------------------------------- // // Private Methods // //----------------------------------------------------- private static void IllegalAccess() { throw new NotSupportedException(SR.Get(SRID.WriteOnlyStream)); } private void CheckDisposed() { if (_baseStream == null) throw new ObjectDisposedException("Stream"); } // _baseStream doubles as our disposed indicator - it's null if we are disposed private Stream _baseStream; // stream we wrap - needs to only support Write private long _position; // current position } } // 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
- PerformanceCounterPermissionAttribute.cs
- InkCollectionBehavior.cs
- WorkflowViewElement.cs
- TextParagraphCache.cs
- DateTimeConverter.cs
- hebrewshape.cs
- ZipIORawDataFileBlock.cs
- ClientSettingsSection.cs
- DoubleAnimationClockResource.cs
- IsolatedStorage.cs
- StreamUpgradeInitiator.cs
- UnwrappedTypesXmlSerializerManager.cs
- AutoGeneratedField.cs
- RepeatBehavior.cs
- Point4DValueSerializer.cs
- DelayedRegex.cs
- ILGenerator.cs
- FixedTextBuilder.cs
- SyntaxCheck.cs
- XmlAttributeOverrides.cs
- ClrProviderManifest.cs
- Vector3DAnimation.cs
- Mappings.cs
- StringSorter.cs
- SqlDataSourceCache.cs
- MenuItemCollectionEditorDialog.cs
- XmlAnyAttributeAttribute.cs
- DocumentSequenceHighlightLayer.cs
- PostBackTrigger.cs
- FlagsAttribute.cs
- LongSumAggregationOperator.cs
- ThemeDirectoryCompiler.cs
- sqlpipe.cs
- MimeReturn.cs
- TextEmbeddedObject.cs
- ChannelServices.cs
- FileSystemEventArgs.cs
- RowCache.cs
- DataContractJsonSerializer.cs
- PageThemeParser.cs
- LinearGradientBrush.cs
- DataListCommandEventArgs.cs
- SafeLocalMemHandle.cs
- DiscoveryClientReferences.cs
- QueryStatement.cs
- MultipleViewPattern.cs
- AnnotationDocumentPaginator.cs
- Transactions.cs
- Vector3dCollection.cs
- InnerItemCollectionView.cs
- IntegerValidator.cs
- BoundPropertyEntry.cs
- ImageSourceValueSerializer.cs
- AssemblyName.cs
- ResourceExpression.cs
- SerializationFieldInfo.cs
- StructuredCompositeActivityDesigner.cs
- VScrollProperties.cs
- IntPtr.cs
- MenuItemBindingCollection.cs
- HtmlInputImage.cs
- Condition.cs
- GuidConverter.cs
- TextDecorationCollection.cs
- DataRelationPropertyDescriptor.cs
- EntityEntry.cs
- RepeatInfo.cs
- PropertyEntry.cs
- OperatingSystem.cs
- ContextMenuStripGroup.cs
- CommandBindingCollection.cs
- SafeReversePInvokeHandle.cs
- FixedSOMSemanticBox.cs
- DataControlPagerLinkButton.cs
- InputBinder.cs
- QuestionEventArgs.cs
- QilCloneVisitor.cs
- ToolboxDataAttribute.cs
- TraceRecord.cs
- XPathAncestorIterator.cs
- NativeMethodsOther.cs
- FontUnit.cs
- RijndaelManagedTransform.cs
- XmlDocumentFragment.cs
- ContentIterators.cs
- Cursor.cs
- ExecutionEngineException.cs
- NativeCompoundFileAPIs.cs
- EdgeProfileValidation.cs
- PeerNearMe.cs
- xmlformatgeneratorstatics.cs
- Icon.cs
- XmlHierarchyData.cs
- StorageRoot.cs
- WebEncodingValidator.cs
- SHA256.cs
- CreateUserWizardStep.cs
- ResourceAssociationTypeEnd.cs
- _NegoState.cs
- CapabilitiesUse.cs