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
- TemplateParser.cs
- DataRecordObjectView.cs
- BamlLocalizer.cs
- GrammarBuilderBase.cs
- DataGridViewLinkColumn.cs
- EventToken.cs
- EditingCoordinator.cs
- CustomBinding.cs
- WebPartEditorOkVerb.cs
- SuppressMessageAttribute.cs
- WSDualHttpSecurityMode.cs
- WrappedDispatcherException.cs
- PreApplicationStartMethodAttribute.cs
- LOSFormatter.cs
- CompositeCollectionView.cs
- DataObjectEventArgs.cs
- ChannelFactoryBase.cs
- VariableAction.cs
- MessageDescriptionCollection.cs
- TextServicesHost.cs
- TabletDeviceInfo.cs
- ErrorHandler.cs
- OpenTypeCommon.cs
- ClipboardData.cs
- ThrowHelper.cs
- CachedPathData.cs
- Point3DCollectionConverter.cs
- VerificationException.cs
- UnsafeNativeMethods.cs
- BuiltInPermissionSets.cs
- ViewStateException.cs
- Matrix.cs
- DecoderBestFitFallback.cs
- Animatable.cs
- VisualBrush.cs
- QueryStringHandler.cs
- BamlVersionHeader.cs
- SafeProcessHandle.cs
- ProxyWebPartManager.cs
- OdbcConnectionOpen.cs
- QueryStringParameter.cs
- GridViewSortEventArgs.cs
- EventListener.cs
- BypassElement.cs
- InternalBase.cs
- Lazy.cs
- ComContractElementCollection.cs
- WasAdminWrapper.cs
- PackageDigitalSignatureManager.cs
- ToRequest.cs
- PackageRelationship.cs
- FixedSOMTableCell.cs
- BoolLiteral.cs
- QuaternionAnimation.cs
- HttpDebugHandler.cs
- DefaultTraceListener.cs
- SortAction.cs
- TypeGeneratedEventArgs.cs
- DictionarySectionHandler.cs
- HandleExceptionArgs.cs
- TreePrinter.cs
- PointAnimationClockResource.cs
- DeviceContexts.cs
- Vars.cs
- ToolStripSeparatorRenderEventArgs.cs
- UndoEngine.cs
- TextCollapsingProperties.cs
- CheckBoxBaseAdapter.cs
- AsyncInvokeContext.cs
- streamingZipPartStream.cs
- ToolStripGrip.cs
- MenuEventArgs.cs
- TrackingProfile.cs
- UTF8Encoding.cs
- ColorInterpolationModeValidation.cs
- ICspAsymmetricAlgorithm.cs
- NetworkInformationException.cs
- ParentControlDesigner.cs
- ChangeProcessor.cs
- SecurityHeaderLayout.cs
- EventLogPermissionAttribute.cs
- HideDisabledControlAdapter.cs
- MimeImporter.cs
- DiscoveryProxy.cs
- _ListenerAsyncResult.cs
- ThreadStartException.cs
- ListSourceHelper.cs
- PenLineCapValidation.cs
- PerformanceCountersBase.cs
- OdbcParameter.cs
- DbConnectionPoolIdentity.cs
- X509SecurityToken.cs
- ReadContentAsBinaryHelper.cs
- DateTimeFormatInfoScanner.cs
- SafeCoTaskMem.cs
- RecordConverter.cs
- ReferenceCountedObject.cs
- CollectionViewGroup.cs
- CornerRadiusConverter.cs
- DSACryptoServiceProvider.cs