Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / 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); } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DriveNotFoundException.cs
- DragEvent.cs
- DbExpressionBuilder.cs
- BamlCollectionHolder.cs
- CompoundFileStorageReference.cs
- PathData.cs
- _NestedSingleAsyncResult.cs
- TypeBrowser.xaml.cs
- SiteMapProvider.cs
- NegatedConstant.cs
- FastPropertyAccessor.cs
- BindingEntityInfo.cs
- FormViewInsertEventArgs.cs
- RuntimeResourceSet.cs
- GPPOINTF.cs
- ManipulationStartingEventArgs.cs
- BehaviorDragDropEventArgs.cs
- FileSystemInfo.cs
- TextBoxBase.cs
- ReferenceAssemblyAttribute.cs
- CopyAction.cs
- DataFormat.cs
- Math.cs
- WebBrowserHelper.cs
- CriticalExceptions.cs
- TransactionBridge.cs
- ReverseInheritProperty.cs
- XmlParserContext.cs
- StylusDownEventArgs.cs
- DispatchChannelSink.cs
- TaskHelper.cs
- ListViewTableCell.cs
- InvalidOleVariantTypeException.cs
- Schema.cs
- EventDescriptorCollection.cs
- ImmutableObjectAttribute.cs
- KeyMatchBuilder.cs
- TableLayoutSettings.cs
- DateTimeConverter.cs
- Trace.cs
- MatchAttribute.cs
- TableLayoutStyleCollection.cs
- DataGridViewCellStyle.cs
- Types.cs
- CompilationUtil.cs
- GeometryValueSerializer.cs
- CursorEditor.cs
- LogLogRecordHeader.cs
- OracleMonthSpan.cs
- Italic.cs
- FormatterServices.cs
- StructuredTypeInfo.cs
- FixedSOMLineRanges.cs
- categoryentry.cs
- SQLDecimal.cs
- XmlSignatureProperties.cs
- AvTrace.cs
- SqlStream.cs
- IDispatchConstantAttribute.cs
- ProfilePropertySettings.cs
- NTAccount.cs
- PrivilegeNotHeldException.cs
- PropertyEntry.cs
- CursorConverter.cs
- MultiDataTrigger.cs
- XmlQualifiedNameTest.cs
- _FixedSizeReader.cs
- DataGridViewCheckBoxCell.cs
- StylusPointProperties.cs
- MenuItem.cs
- Attributes.cs
- DelayedRegex.cs
- MultiAsyncResult.cs
- DataGridTextBoxColumn.cs
- SHA1CryptoServiceProvider.cs
- ObjectIDGenerator.cs
- ISAPIRuntime.cs
- SqlServices.cs
- SapiInterop.cs
- XsdCachingReader.cs
- CompilerParameters.cs
- DbConnectionPoolCounters.cs
- UnsafeCollabNativeMethods.cs
- WebPartCatalogCloseVerb.cs
- Debug.cs
- FileDataSourceCache.cs
- WpfWebRequestHelper.cs
- ContentPosition.cs
- ThicknessAnimationBase.cs
- JoinGraph.cs
- MenuBindingsEditor.cs
- HTTPNotFoundHandler.cs
- DataSet.cs
- XmlHierarchicalDataSourceView.cs
- TabItemWrapperAutomationPeer.cs
- SortQuery.cs
- AppliedDeviceFiltersEditor.cs
- DbDataSourceEnumerator.cs
- QuaternionKeyFrameCollection.cs
- JavascriptCallbackResponseProperty.cs