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 / 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
- ReadOnlyNameValueCollection.cs
- ThemeableAttribute.cs
- AsyncCompletedEventArgs.cs
- StateWorkerRequest.cs
- AuthorizationSection.cs
- QilInvoke.cs
- UnsafeNativeMethods.cs
- SecurityKeyType.cs
- SHA384Managed.cs
- DataConnectionHelper.cs
- XPathEmptyIterator.cs
- PathSegmentCollection.cs
- CrossAppDomainChannel.cs
- EnumerableCollectionView.cs
- CounterCreationData.cs
- ImageSource.cs
- DependencyPropertyHelper.cs
- DesignerListAdapter.cs
- UpdateEventArgs.cs
- PolyQuadraticBezierSegment.cs
- WindowClosedEventArgs.cs
- _ChunkParse.cs
- WindowManager.cs
- MemoryPressure.cs
- ColumnPropertiesGroup.cs
- DrawingVisualDrawingContext.cs
- ExternalFile.cs
- Popup.cs
- InfoCardRSAOAEPKeyExchangeDeformatter.cs
- TemplateBuilder.cs
- versioninfo.cs
- CachedRequestParams.cs
- DataGridColumnCollection.cs
- UrlPath.cs
- ConsumerConnectionPointCollection.cs
- WindowsStatusBar.cs
- PrePrepareMethodAttribute.cs
- Storyboard.cs
- ActivityBindForm.cs
- HostedNamedPipeTransportManager.cs
- MobileCapabilities.cs
- BaseUriHelper.cs
- DynamicILGenerator.cs
- BCLDebug.cs
- TextInfo.cs
- ProfileManager.cs
- DayRenderEvent.cs
- CacheChildrenQuery.cs
- OutputCacheSettingsSection.cs
- ModelTreeManager.cs
- UnmanagedMemoryStream.cs
- XmlImplementation.cs
- PropertyGroupDescription.cs
- GroupItem.cs
- PreservationFileWriter.cs
- GridViewDeletedEventArgs.cs
- CollectionBase.cs
- IdnElement.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- LambdaCompiler.Binary.cs
- MediaTimeline.cs
- Invariant.cs
- Misc.cs
- SignedXml.cs
- DefaultBinder.cs
- CheckBox.cs
- MD5.cs
- NullableDoubleMinMaxAggregationOperator.cs
- WorkflowControlClient.cs
- HttpProfileGroupBase.cs
- Transform.cs
- FormViewDeletedEventArgs.cs
- GenericTypeParameterBuilder.cs
- HtmlInputButton.cs
- SafeFileMapViewHandle.cs
- SID.cs
- SoapClientProtocol.cs
- SubMenuStyle.cs
- ImageBrush.cs
- PropertyGridEditorPart.cs
- Rect3D.cs
- RepeatButtonAutomationPeer.cs
- EntityContainerAssociationSetEnd.cs
- ListBoxAutomationPeer.cs
- DispatcherProcessingDisabled.cs
- XmlSchemaSet.cs
- FileAuthorizationModule.cs
- TypeBrowserDialog.cs
- SupportedAddressingMode.cs
- WebServiceAttribute.cs
- PerformanceCounterPermissionAttribute.cs
- PropertyEmitterBase.cs
- JsonQueryStringConverter.cs
- FileDialogCustomPlace.cs
- InputReport.cs
- ImageDrawing.cs
- SubtreeProcessor.cs
- HttpBufferlessInputStream.cs
- WebPartVerb.cs
- SettingsContext.cs