Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Net / System / Net / Mail / SevenBitStream.cs / 1 / SevenBitStream.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net.Mime { using System; using System.IO; ////// This stream validates outgoing bytes to be within the /// acceptible range of 0 - 127. Writes will throw if a /// value > 127 is found. /// internal class SevenBitStream : DelegatedStream { ////// ctor. /// /// Underlying stream internal SevenBitStream(Stream stream) : base(stream) { } ////// Writes the specified content to the underlying stream /// /// Buffer to write /// Offset within buffer to start writing /// Count of bytes to write /// Callback to call when write completes /// State to pass to callback public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { if (buffer == null) throw new ArgumentNullException("buffer"); if (offset < 0 || offset >= buffer.Length) throw new ArgumentOutOfRangeException("offset"); if (offset + count > buffer.Length) throw new ArgumentOutOfRangeException("count"); CheckBytes(buffer, offset, count); IAsyncResult result = base.BeginWrite(buffer, offset, count, callback, state); return result; } ////// Writes the specified content to the underlying stream /// /// Buffer to write /// Offset within buffer to start writing /// Count of bytes to write public override void Write(byte[] buffer, int offset, int count) { if (buffer == null) throw new ArgumentNullException("buffer"); if (offset < 0 || offset >= buffer.Length) throw new ArgumentOutOfRangeException("offset"); if (offset + count > buffer.Length) throw new ArgumentOutOfRangeException("count"); CheckBytes(buffer, offset, count); base.Write(buffer, offset, count); } // helper methods ////// Checks the data in the buffer for bytes > 127. /// /// Buffer containing data /// Offset within buffer to start checking /// Count of bytes to check void CheckBytes(byte[] buffer, int offset, int count) { for (int i = count; i < offset + count; i++) { if (buffer[i] > 127) throw new FormatException(SR.GetString(SR.Mail7BitStreamInvalidCharacter)); } } } }
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ObjectDataSourceFilteringEventArgs.cs
- ExpressionBuilder.cs
- SignalGate.cs
- HttpRuntime.cs
- xml.cs
- QueryOpeningEnumerator.cs
- InvalidEnumArgumentException.cs
- MenuAdapter.cs
- TextElementCollectionHelper.cs
- OracleConnectionFactory.cs
- SafeNativeMethods.cs
- Verify.cs
- LambdaValue.cs
- HwndSource.cs
- QuerySelectOp.cs
- TemplateParser.cs
- RectAnimation.cs
- NativeCppClassAttribute.cs
- UnknownWrapper.cs
- WebBrowserSiteBase.cs
- UserPreferenceChangingEventArgs.cs
- CacheHelper.cs
- TextRenderer.cs
- FormParameter.cs
- PagesChangedEventArgs.cs
- InputLanguageCollection.cs
- PaperSize.cs
- FormsAuthenticationEventArgs.cs
- ReflectEventDescriptor.cs
- PinnedBufferMemoryStream.cs
- COM2TypeInfoProcessor.cs
- EventManager.cs
- NullToBooleanConverter.cs
- PtsPage.cs
- XPathNode.cs
- DebugView.cs
- ScrollEvent.cs
- BuilderElements.cs
- Matrix.cs
- MaterialGroup.cs
- MessageHeader.cs
- PopupRoot.cs
- QueryReaderSettings.cs
- XhtmlTextWriter.cs
- AttachmentService.cs
- NotifyParentPropertyAttribute.cs
- ViewPort3D.cs
- InternalException.cs
- PageAsyncTaskManager.cs
- ConsoleKeyInfo.cs
- ActivityScheduledRecord.cs
- Operator.cs
- SchemaTableOptionalColumn.cs
- ProfileSettings.cs
- Figure.cs
- HttpStreams.cs
- dataSvcMapFileLoader.cs
- MultiTouchSystemGestureLogic.cs
- KeyPullup.cs
- DeviceContext2.cs
- ResourceReferenceExpression.cs
- LinqDataSourceStatusEventArgs.cs
- TemplateInstanceAttribute.cs
- ButtonChrome.cs
- PostBackOptions.cs
- NullableBoolConverter.cs
- ListViewVirtualItemsSelectionRangeChangedEvent.cs
- WebPartEditorOkVerb.cs
- IMembershipProvider.cs
- DataGridViewColumnDividerDoubleClickEventArgs.cs
- Array.cs
- SettingsAttributeDictionary.cs
- ServiceRoute.cs
- DataAdapter.cs
- IPAddress.cs
- SizeConverter.cs
- LogicalTreeHelper.cs
- AggregatePushdown.cs
- DataView.cs
- ZipIORawDataFileBlock.cs
- AudioDeviceOut.cs
- SlipBehavior.cs
- _ShellExpression.cs
- ContextMarshalException.cs
- Point3DIndependentAnimationStorage.cs
- HtmlInputPassword.cs
- CodeTypeMemberCollection.cs
- TypeConverterAttribute.cs
- BlurEffect.cs
- PixelFormats.cs
- CompilerState.cs
- DataGridTable.cs
- KeyboardDevice.cs
- WebPartCollection.cs
- WindowsButton.cs
- AssemblyBuilder.cs
- GrammarBuilderRuleRef.cs
- XPathDocumentBuilder.cs
- MemberDescriptor.cs
- DbDataSourceEnumerator.cs