Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / clr / src / BCL / System / IO / UnmanagedMemoryStreamWrapper.cs / 1 / 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; 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 { get { return _unmanagedStream.CanRead; } } public override bool CanSeek { get { return _unmanagedStream.CanSeek; } } public override bool CanWrite { 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); } 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 (!_unmanagedStream._isOpen) __Error.StreamIsClosed(); if (!_unmanagedStream.CanRead) __Error.ReadNotSupported(); if (stream==null) throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream")); byte[] buffer = ToArray(); stream.Write(buffer, 0, buffer.Length); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // 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; 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 { get { return _unmanagedStream.CanRead; } } public override bool CanSeek { get { return _unmanagedStream.CanSeek; } } public override bool CanWrite { 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); } 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 (!_unmanagedStream._isOpen) __Error.StreamIsClosed(); if (!_unmanagedStream.CanRead) __Error.ReadNotSupported(); if (stream==null) throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream")); byte[] buffer = ToArray(); stream.Write(buffer, 0, buffer.Length); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ErrorHandler.cs
- SecurityState.cs
- SqlDataSourceStatusEventArgs.cs
- SwitchCase.cs
- ParenthesizePropertyNameAttribute.cs
- Collection.cs
- StrokeNodeEnumerator.cs
- CompositionAdorner.cs
- Parsers.cs
- PrimarySelectionAdorner.cs
- MarkupExtensionReturnTypeAttribute.cs
- DocumentApplication.cs
- XmlSignificantWhitespace.cs
- QilParameter.cs
- CompressStream.cs
- RouteValueDictionary.cs
- VectorAnimation.cs
- LinkButton.cs
- TextHidden.cs
- InkCanvasInnerCanvas.cs
- PartialList.cs
- Conditional.cs
- FilterQuery.cs
- XamlPathDataSerializer.cs
- FastPropertyAccessor.cs
- XmlDictionary.cs
- TreeViewBindingsEditor.cs
- CodeDelegateCreateExpression.cs
- PolygonHotSpot.cs
- DocumentCollection.cs
- AmbiguousMatchException.cs
- JsonByteArrayDataContract.cs
- GeneralTransform3DGroup.cs
- CallInfo.cs
- DataGridHeaderBorder.cs
- Brush.cs
- RIPEMD160Managed.cs
- BindingExpressionBase.cs
- HtmlFormParameterReader.cs
- ProcessModelInfo.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- StreamWithDictionary.cs
- StopRoutingHandler.cs
- ComboBoxItem.cs
- EventRoute.cs
- HandlerMappingMemo.cs
- ScrollPatternIdentifiers.cs
- DbException.cs
- SystemFonts.cs
- Message.cs
- RegistryExceptionHelper.cs
- IgnorePropertiesAttribute.cs
- RangeValuePatternIdentifiers.cs
- AddInServer.cs
- SmiMetaDataProperty.cs
- FullTextState.cs
- DataBoundControlHelper.cs
- ConfigPathUtility.cs
- PropertyDescriptorGridEntry.cs
- DrawingGroup.cs
- SqlParameter.cs
- XmlDataSourceNodeDescriptor.cs
- DataObjectPastingEventArgs.cs
- StreamUpdate.cs
- CustomErrorCollection.cs
- PopupRootAutomationPeer.cs
- SoapParser.cs
- KeyedCollection.cs
- EventToken.cs
- DirectoryRootQuery.cs
- Evaluator.cs
- Stroke.cs
- CompositeDataBoundControl.cs
- MasterPage.cs
- ColorTranslator.cs
- TemplateComponentConnector.cs
- Logging.cs
- Soap.cs
- RSAPKCS1KeyExchangeFormatter.cs
- DiscoveryServiceExtension.cs
- SqlNotificationRequest.cs
- DataControlPagerLinkButton.cs
- WebHttpElement.cs
- HandlerWithFactory.cs
- IISMapPath.cs
- XhtmlCssHandler.cs
- DeploymentExceptionMapper.cs
- PanelDesigner.cs
- DataGridViewCellStyleContentChangedEventArgs.cs
- baseaxisquery.cs
- PointLight.cs
- Filter.cs
- DuplicateWaitObjectException.cs
- ContractTypeNameElement.cs
- IndependentlyAnimatedPropertyMetadata.cs
- Serializer.cs
- RotateTransform.cs
- WebPartVerbCollection.cs
- EntityCommandDefinition.cs
- SoapAttributeOverrides.cs