Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / IO / UnmanagedMemoryStreamWrapper.cs / 1305376 / UnmanagedMemoryStreamWrapper.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: UnmanagedMemoryStreamWrapper ** **[....] ** ** Purpose: Create a Memorystream over an UnmanagedMemoryStream ** ===========================================================*/ using System; using System.Runtime.InteropServices; using System.Security.Permissions; using System.Diagnostics.Contracts; namespace System.IO { // Needed for backwards compatibility with V1.x usages of the // ResourceManager, where a MemoryStream is now returned as an // UnmanagedMemoryStream from ResourceReader. internal sealed class UnmanagedMemoryStreamWrapper : MemoryStream { private UnmanagedMemoryStream _unmanagedStream; internal UnmanagedMemoryStreamWrapper(UnmanagedMemoryStream stream) { _unmanagedStream = stream; } public override bool CanRead { [Pure] get { return _unmanagedStream.CanRead; } } public override bool CanSeek { [Pure] get { return _unmanagedStream.CanSeek; } } public override bool CanWrite { [Pure] get { return _unmanagedStream.CanWrite; } } protected override void Dispose(bool disposing) { try { if (disposing) _unmanagedStream.Close(); } finally { base.Dispose(disposing); } } public override void Flush() { _unmanagedStream.Flush(); } public override byte[] GetBuffer() { throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_MemStreamBuffer")); } public override int Capacity { get { return (int) _unmanagedStream.Capacity; } set { throw new IOException(Environment.GetResourceString("IO.IO_FixedCapacity")); } } public override long Length { get { return _unmanagedStream.Length; } } public override long Position { get { return _unmanagedStream.Position; } set { _unmanagedStream.Position = value; } } public override int Read([In, Out] byte[] buffer, int offset, int count) { return _unmanagedStream.Read(buffer, offset, count); } public override int ReadByte() { return _unmanagedStream.ReadByte(); } public override long Seek(long offset, SeekOrigin loc) { return _unmanagedStream.Seek(offset, loc); } [System.Security.SecuritySafeCritical] // auto-generated public unsafe override byte[] ToArray() { if (!_unmanagedStream._isOpen) __Error.StreamIsClosed(); if (!_unmanagedStream.CanRead) __Error.ReadNotSupported(); byte[] buffer = new byte[_unmanagedStream.Length]; Buffer.memcpy(_unmanagedStream.Pointer, 0, buffer, 0, (int) _unmanagedStream.Length); return buffer; } public override void Write(byte[] buffer, int offset, int count) { _unmanagedStream.Write(buffer, offset, count); } public override void WriteByte(byte value) { _unmanagedStream.WriteByte(value); } // Writes this MemoryStream to another stream. public unsafe override void WriteTo(Stream stream) { if (stream==null) throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream")); Contract.EndContractBlock(); if (!_unmanagedStream._isOpen) __Error.StreamIsClosed(); if (!CanRead) __Error.ReadNotSupported(); byte[] buffer = ToArray(); stream.Write(buffer, 0, buffer.Length); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
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
- WebEventTraceProvider.cs
- UpdateException.cs
- Int32Animation.cs
- BinaryNode.cs
- SqlDataAdapter.cs
- CallContext.cs
- DataTrigger.cs
- RedBlackList.cs
- CompleteWizardStep.cs
- EpmSyndicationContentSerializer.cs
- GrammarBuilder.cs
- WSHttpTransportSecurityElement.cs
- ImageButton.cs
- XamlPathDataSerializer.cs
- CollectionView.cs
- NotImplementedException.cs
- OdbcConnectionOpen.cs
- DataGridViewButtonCell.cs
- DataGridViewTextBoxCell.cs
- HttpFileCollection.cs
- Matrix3DStack.cs
- IDispatchConstantAttribute.cs
- DocumentPageView.cs
- SspiHelper.cs
- ProgressBar.cs
- XmlSchemaSimpleContentExtension.cs
- _SSPIWrapper.cs
- SecurityDocument.cs
- KeyPullup.cs
- WpfMemberInvoker.cs
- CustomLineCap.cs
- RawStylusInputCustomData.cs
- GenericTypeParameterBuilder.cs
- DateTimeConstantAttribute.cs
- ReaderContextStackData.cs
- RowCache.cs
- PerfCounterSection.cs
- InternalConfigRoot.cs
- VersionPair.cs
- ProfileServiceManager.cs
- SessionSwitchEventArgs.cs
- ExtensionWindow.cs
- MenuItemCollection.cs
- Gdiplus.cs
- DataGridViewBand.cs
- ExceptionRoutedEventArgs.cs
- CompModHelpers.cs
- CfgParser.cs
- ToggleProviderWrapper.cs
- WebPartHelpVerb.cs
- ResourceReferenceKeyNotFoundException.cs
- WebZoneDesigner.cs
- EntityDataSourceConfigureObjectContext.cs
- TraceContextEventArgs.cs
- ConfigurationSectionGroup.cs
- StateElement.cs
- MediaContextNotificationWindow.cs
- ContentElement.cs
- SafeSecurityHelper.cs
- ConditionalDesigner.cs
- HandlerBase.cs
- WindowsSolidBrush.cs
- ProcessThreadCollection.cs
- TextRange.cs
- PublisherMembershipCondition.cs
- MaskedTextBox.cs
- QueryGeneratorBase.cs
- HashAlgorithm.cs
- MarkedHighlightComponent.cs
- ClrProviderManifest.cs
- Popup.cs
- SamlNameIdentifierClaimResource.cs
- CodeDelegateCreateExpression.cs
- XmlTypeMapping.cs
- ReservationCollection.cs
- ExpressionVisitor.cs
- MessageQueueTransaction.cs
- NTAccount.cs
- Facet.cs
- ArgIterator.cs
- CommandLibraryHelper.cs
- FileLevelControlBuilderAttribute.cs
- PolicyValidationException.cs
- BodyWriter.cs
- Matrix3D.cs
- AuthStoreRoleProvider.cs
- CodeArrayIndexerExpression.cs
- TextAdaptor.cs
- EventManager.cs
- UseAttributeSetsAction.cs
- ImportFileRequest.cs
- FamilyMapCollection.cs
- SeekableMessageNavigator.cs
- PerformanceCounterPermissionAttribute.cs
- XpsS0ValidatingLoader.cs
- DoubleLinkListEnumerator.cs
- RepeatButton.cs
- DeploymentExceptionMapper.cs
- ViewGenerator.cs
- BaseParser.cs