Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / InfoCardBinaryReader.cs / 1 / InfoCardBinaryReader.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- // // Presharp uses the c# pragma mechanism to supress its warnings. // These are not recognised by the base compiler so we need to explictly // disable the following warnings. See http://winweb/cse/Tools/PREsharp/userguide/default.asp // for details. // #pragma warning disable 1634, 1691 // unknown message, unknown pragma namespace Microsoft.InfoCards { using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Text; using System.Runtime.InteropServices; using Microsoft.InfoCards.Diagnostics; using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace; // // Summary: // Internal BinaryWriter class that will throw InfoCardArgumentExceptions // when stream appears to be corrupted. // internal sealed class InfoCardBinaryReader : BinaryReader { static readonly char[] s_singleChar = { 'a' }; int m_charSize; public InfoCardBinaryReader(Stream stream, Encoding encoding) : base(stream, encoding ) { m_charSize = encoding.GetByteCount( s_singleChar ); } public InfoCardBinaryReader(Stream stream) : this(stream,Encoding.Unicode) { } public override int Read() { EnsureBufferBounds(1); return base.Read(); } public override int Read(byte[] buffer, int index, int count) { // // This method will not read past the end of the buffer, // and are used to read blocks of information. The count // provided may exceed the max, but only what is present // will be returned. // return base.Read(buffer, index, count); } public override int Read(char[] buffer, int index, int count) { // // This method will not read past the end of the buffer, // and are used to read blocks of information. The count // provided may exceed the max, but only what is present // will be returned. // return base.Read(buffer, index, count); } public override bool ReadBoolean() { EnsureBufferBounds(1); return base.ReadBoolean(); } public override byte ReadByte() { EnsureBufferBounds(1); return base.ReadByte(); } public override byte[] ReadBytes(int count) { EnsureBufferBounds(count); return base.ReadBytes(count); } public override char ReadChar() { EnsureBufferBounds(m_charSize); return base.ReadChar(); } public override char[] ReadChars(int count) { EnsureBufferBounds(Convert.ToInt64(m_charSize * count)); return base.ReadChars(count); } public override decimal ReadDecimal() { EnsureBufferBounds( Convert.ToInt64( Marshal.SizeOf( typeof(Decimal) ) ) ); return base.ReadDecimal(); } public override double ReadDouble() { EnsureBufferBounds(sizeof(Double)); return base.ReadDouble(); } public override short ReadInt16() { EnsureBufferBounds(sizeof(Int16)); return base.ReadInt16(); } public override int ReadInt32() { EnsureBufferBounds(sizeof(Int32)); return base.ReadInt32(); } public override long ReadInt64() { EnsureBufferBounds(sizeof(Int64)); return base.ReadInt64(); } public override sbyte ReadSByte() { EnsureBufferBounds(sizeof(SByte)); return base.ReadSByte(); } public override float ReadSingle() { EnsureBufferBounds(sizeof(Single)); return base.ReadSingle(); } public override string ReadString() { EnsureBufferBounds( (m_charSize * PeekChar()) + sizeof(Int32) ); return base.ReadString(); } public override ushort ReadUInt16() { EnsureBufferBounds(sizeof(UInt32)); return base.ReadUInt16(); } public override uint ReadUInt32() { EnsureBufferBounds(sizeof(UInt32)); return base.ReadUInt32(); } public override ulong ReadUInt64() { EnsureBufferBounds(sizeof(UInt64)); return base.ReadUInt64(); } // // Summary: // Ensures that the offset will not overrun the stream. // void EnsureBufferBounds(long offset) { if( (ulong)(BaseStream.Position + offset) > (ulong)BaseStream.Length) { throw IDT.ThrowHelperError( new InfoCardArgumentException( SR.GetString( SR.InvalidOrCorruptArgumentStream ) ) ); } } } } // 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
- DataGridViewHeaderCell.cs
- FontStyleConverter.cs
- FixedSOMPage.cs
- PeerToPeerException.cs
- MimeObjectFactory.cs
- BooleanFunctions.cs
- ExtensibleClassFactory.cs
- HttpRuntimeSection.cs
- SrgsElementFactory.cs
- DiscardableAttribute.cs
- OptimisticConcurrencyException.cs
- IpcManager.cs
- QilPatternVisitor.cs
- HelpProvider.cs
- RoutedEventArgs.cs
- dsa.cs
- IISUnsafeMethods.cs
- ScriptingSectionGroup.cs
- SelectionHighlightInfo.cs
- FormsAuthentication.cs
- ExtenderHelpers.cs
- WhiteSpaceTrimStringConverter.cs
- SafeSecurityHandles.cs
- ServiceHttpModule.cs
- ImageSourceConverter.cs
- Columns.cs
- NativeActivityContext.cs
- TextEffect.cs
- DataGridViewRowConverter.cs
- AnnotationHelper.cs
- DataObjectPastingEventArgs.cs
- DesignerTextBoxAdapter.cs
- parserscommon.cs
- PermissionToken.cs
- CngAlgorithmGroup.cs
- Dump.cs
- XPathDocument.cs
- GridViewCommandEventArgs.cs
- SpeechRecognitionEngine.cs
- httpserverutility.cs
- ClonableStack.cs
- HtmlControl.cs
- RuntimeHandles.cs
- DynamicMethod.cs
- WinFormsComponentEditor.cs
- Range.cs
- XmlTextWriter.cs
- __TransparentProxy.cs
- FilteredXmlReader.cs
- QueuePathEditor.cs
- XmlChildEnumerator.cs
- RegexTypeEditor.cs
- XamlGridLengthSerializer.cs
- FeatureSupport.cs
- XmlSchemaComplexContent.cs
- StylusEventArgs.cs
- XmlNamedNodeMap.cs
- AnnotationMap.cs
- XPathDocument.cs
- ListParagraph.cs
- WebBrowserUriTypeConverter.cs
- ToolboxComponentsCreatedEventArgs.cs
- InlineUIContainer.cs
- XmlNamespaceDeclarationsAttribute.cs
- Vector3DCollection.cs
- PassportPrincipal.cs
- PeerNameRecordCollection.cs
- WsdlBuildProvider.cs
- GreenMethods.cs
- ExpanderAutomationPeer.cs
- DynamicQueryStringParameter.cs
- SchemaNamespaceManager.cs
- ScriptResourceMapping.cs
- EntityDataSourceState.cs
- AnimatedTypeHelpers.cs
- ResponseStream.cs
- SqlError.cs
- TreeNodeEventArgs.cs
- DataSetFieldSchema.cs
- CodeFieldReferenceExpression.cs
- CacheDependency.cs
- IISUnsafeMethods.cs
- TextRunCacheImp.cs
- TextViewSelectionProcessor.cs
- Random.cs
- CompleteWizardStep.cs
- LocatorManager.cs
- TimeSpanSecondsConverter.cs
- XPathNodeInfoAtom.cs
- MouseCaptureWithinProperty.cs
- path.cs
- HashSet.cs
- XmlSchemaComplexContentRestriction.cs
- followingquery.cs
- __ConsoleStream.cs
- ForEachAction.cs
- WebBrowser.cs
- ObjectListGeneralPage.cs
- FullTrustAssembly.cs
- SortQuery.cs