Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / 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: BruceMac: 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. //------------------------------------------------------------------------------ // //// 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; 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
- EventHandlerList.cs
- TextEditorLists.cs
- SQLBinaryStorage.cs
- ClientProxyGenerator.cs
- RepeaterCommandEventArgs.cs
- InheritanceUI.cs
- SystemSounds.cs
- ProviderUtil.cs
- DriveInfo.cs
- HandleRef.cs
- PresentationSource.cs
- EventLogTraceListener.cs
- BinaryObjectReader.cs
- FormsAuthenticationUserCollection.cs
- ManualResetEvent.cs
- ToolbarAUtomationPeer.cs
- XmlStreamStore.cs
- CanExpandCollapseAllConverter.cs
- ImageSource.cs
- TypeDefinition.cs
- ValidationSummary.cs
- BitmapEffectInputConnector.cs
- StackOverflowException.cs
- XPathParser.cs
- InputBuffer.cs
- PrivateFontCollection.cs
- SoapObjectWriter.cs
- PersonalizableAttribute.cs
- CustomAttributeBuilder.cs
- StringReader.cs
- ExpressionConverter.cs
- OleDbMetaDataFactory.cs
- DuplicateWaitObjectException.cs
- _NTAuthentication.cs
- RefreshPropertiesAttribute.cs
- Number.cs
- SuppressMergeCheckAttribute.cs
- SafeSystemMetrics.cs
- ParallelActivityDesigner.cs
- XmlQueryContext.cs
- ControlValuePropertyAttribute.cs
- XmlAnyAttributeAttribute.cs
- DesignerEventService.cs
- DataMisalignedException.cs
- ModifiableIteratorCollection.cs
- Item.cs
- SelectionWordBreaker.cs
- XhtmlBasicCalendarAdapter.cs
- followingquery.cs
- WebSysDisplayNameAttribute.cs
- CryptoApi.cs
- TransformGroup.cs
- XmlRawWriterWrapper.cs
- PostBackOptions.cs
- UdpReplyToBehavior.cs
- SurrogateChar.cs
- LowerCaseStringConverter.cs
- ToolStripPanelRenderEventArgs.cs
- Table.cs
- DataControlFieldCollection.cs
- ErrorActivity.cs
- figurelengthconverter.cs
- SymmetricSecurityProtocol.cs
- StringUtil.cs
- CodeDirectoryCompiler.cs
- SmiContext.cs
- ComplexType.cs
- ObservableCollectionDefaultValueFactory.cs
- SingleResultAttribute.cs
- MetadataSerializer.cs
- DocumentXmlWriter.cs
- SqlExpressionNullability.cs
- WebBrowserSiteBase.cs
- Operand.cs
- ConfigXmlCDataSection.cs
- EarlyBoundInfo.cs
- TraceRecord.cs
- SerializerDescriptor.cs
- ChangePassword.cs
- PointF.cs
- shaper.cs
- AdobeCFFWrapper.cs
- SinglePageViewer.cs
- FieldBuilder.cs
- TdsParameterSetter.cs
- DataGridCellItemAutomationPeer.cs
- ToolStripDropDownClosingEventArgs.cs
- UIPermission.cs
- Parameter.cs
- DashStyles.cs
- HttpCapabilitiesSectionHandler.cs
- SqlDataSourceAdvancedOptionsForm.cs
- ISAPIWorkerRequest.cs
- DesignerProperties.cs
- ApplicationServiceManager.cs
- FormViewPagerRow.cs
- HttpHandlerActionCollection.cs
- TypeDescriptorFilterService.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- TraceContext.cs