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
- ZipIOExtraFieldElement.cs
- ActivityUtilities.cs
- SmtpNtlmAuthenticationModule.cs
- DataTableTypeConverter.cs
- MarkupObject.cs
- RangeValuePattern.cs
- Policy.cs
- WinFormsComponentEditor.cs
- QilLoop.cs
- PixelFormatConverter.cs
- PageStatePersister.cs
- ColumnTypeConverter.cs
- FontCacheUtil.cs
- NotImplementedException.cs
- TreeViewImageKeyConverter.cs
- SelectionChangedEventArgs.cs
- Symbol.cs
- MouseOverProperty.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- BrowserInteropHelper.cs
- AudioStateChangedEventArgs.cs
- MergeExecutor.cs
- ObjectDisposedException.cs
- MSHTMLHostUtil.cs
- ButtonChrome.cs
- TableLayoutStyleCollection.cs
- PackWebRequestFactory.cs
- TemplateParser.cs
- ImageClickEventArgs.cs
- OracleColumn.cs
- ArrangedElement.cs
- WmpBitmapDecoder.cs
- HostProtectionPermission.cs
- Version.cs
- BounceEase.cs
- ChineseLunisolarCalendar.cs
- ProviderConnectionPoint.cs
- DependencyObjectType.cs
- HttpPostClientProtocol.cs
- ActiveXSite.cs
- AsynchronousChannel.cs
- Compiler.cs
- SubqueryRules.cs
- Unit.cs
- GuidConverter.cs
- RadioButton.cs
- AlphaSortedEnumConverter.cs
- XmlSchemaGroup.cs
- XPathNavigatorReader.cs
- SerialPort.cs
- CodeIdentifiers.cs
- Baml2006KnownTypes.cs
- SchemaCreator.cs
- TextBox.cs
- NameValueFileSectionHandler.cs
- CellNormalizer.cs
- InvalidDataException.cs
- DataBindEngine.cs
- ListViewGroupConverter.cs
- DatePickerTextBox.cs
- Operator.cs
- NamedPipeChannelFactory.cs
- SessionPageStatePersister.cs
- CodeExporter.cs
- RemoteWebConfigurationHostStream.cs
- TreeNodeClickEventArgs.cs
- DeferredReference.cs
- XmlUtilWriter.cs
- AddInActivator.cs
- RightsManagementEncryptedStream.cs
- Literal.cs
- ReflectionUtil.cs
- _IPv6Address.cs
- WindowsFormsHost.cs
- Themes.cs
- StringValueConverter.cs
- AssociatedControlConverter.cs
- AnnotationResource.cs
- SystemDiagnosticsSection.cs
- EventWaitHandleSecurity.cs
- ToggleButtonAutomationPeer.cs
- BuildResult.cs
- FlowPosition.cs
- HttpHandlersInstallComponent.cs
- SchemaType.cs
- WebBrowserUriTypeConverter.cs
- SoapAttributeOverrides.cs
- ToolBarButtonDesigner.cs
- securestring.cs
- TranslateTransform3D.cs
- SQLByte.cs
- DeploymentSectionCache.cs
- DeploymentSection.cs
- PointUtil.cs
- SendMailErrorEventArgs.cs
- IpcClientManager.cs
- MetadataItem.cs
- Size3D.cs
- XmlUnspecifiedAttribute.cs
- SettingsPropertyNotFoundException.cs