Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / MS / Internal / IO / Zip / WriteTimeStream.cs / 1305600 / 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: BruceMac: Created. // //----------------------------------------------------------------------------- using System; using System.IO; using System.Windows; using MS.Internal.WindowsBase; 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. //------------------------------------------------------------------------------ // //// 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: BruceMac: Created. // //----------------------------------------------------------------------------- using System; using System.IO; using System.Windows; using MS.Internal.WindowsBase; 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
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DodSequenceMerge.cs
- MultiPropertyDescriptorGridEntry.cs
- StickyNoteAnnotations.cs
- BinaryMethodMessage.cs
- FormatException.cs
- TextMetrics.cs
- TypefaceMetricsCache.cs
- AxDesigner.cs
- BrushMappingModeValidation.cs
- RedistVersionInfo.cs
- XPathNavigator.cs
- PictureBox.cs
- XmlSchemaObjectCollection.cs
- WSTrustDec2005.cs
- AlphaSortedEnumConverter.cs
- DesignSurfaceServiceContainer.cs
- InvokePatternIdentifiers.cs
- CodeDomComponentSerializationService.cs
- TypeDependencyAttribute.cs
- ServiceDurableInstanceContextProvider.cs
- LinqDataSource.cs
- PersianCalendar.cs
- SelectionRangeConverter.cs
- MenuItem.cs
- HybridDictionary.cs
- PrefixHandle.cs
- PublishLicense.cs
- DefaultWorkflowTransactionService.cs
- OperationContext.cs
- HelpKeywordAttribute.cs
- BrowserDefinitionCollection.cs
- LayoutUtils.cs
- KeyMatchBuilder.cs
- MultiTargetingUtil.cs
- TaskFileService.cs
- FlowchartDesigner.Helpers.cs
- ResourceReferenceExpressionConverter.cs
- DelegateSerializationHolder.cs
- ServiceDiscoveryBehavior.cs
- AssemblyBuilder.cs
- COMException.cs
- RangeContentEnumerator.cs
- SafeRightsManagementEnvironmentHandle.cs
- TrackBarRenderer.cs
- StoreItemCollection.Loader.cs
- System.Data.OracleClient_BID.cs
- xmlfixedPageInfo.cs
- GridSplitterAutomationPeer.cs
- EventData.cs
- LoginName.cs
- PartialCachingAttribute.cs
- ComplexPropertyEntry.cs
- RoutedPropertyChangedEventArgs.cs
- NumericExpr.cs
- AmbientLight.cs
- WebPermission.cs
- InternalEnumValidatorAttribute.cs
- HebrewNumber.cs
- Keyboard.cs
- StateBag.cs
- PrinterUnitConvert.cs
- SchemeSettingElementCollection.cs
- ChannelServices.cs
- PersistChildrenAttribute.cs
- ContextQuery.cs
- EventLogPermissionAttribute.cs
- CompositeControl.cs
- X509CertificateCollection.cs
- FixedBufferAttribute.cs
- SqlConnectionStringBuilder.cs
- DataQuery.cs
- WebControl.cs
- CachingHintValidation.cs
- SyndicationCategory.cs
- ProtocolViolationException.cs
- X509Utils.cs
- UnsignedPublishLicense.cs
- HwndStylusInputProvider.cs
- QueryCacheManager.cs
- AmbiguousMatchException.cs
- IntSecurity.cs
- ConfigurationStrings.cs
- XmlText.cs
- MailDefinition.cs
- ErrorsHelper.cs
- Baml2006SchemaContext.cs
- InstanceKeyCompleteException.cs
- ClaimSet.cs
- MediaSystem.cs
- Tablet.cs
- HttpChannelListener.cs
- CapabilitiesUse.cs
- InternalsVisibleToAttribute.cs
- ContextMenu.cs
- FacetEnabledSchemaElement.cs
- Container.cs
- ConsumerConnectionPoint.cs
- VirtualizingPanel.cs
- Int32.cs
- LayoutDump.cs