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
- SchemaNamespaceManager.cs
- CalendarDay.cs
- StreamSecurityUpgradeInitiator.cs
- StateBag.cs
- WebMessageEncodingElement.cs
- BaseDataList.cs
- IndentedTextWriter.cs
- DecoderNLS.cs
- sortedlist.cs
- Errors.cs
- WebSysDescriptionAttribute.cs
- FieldValue.cs
- ZipFileInfo.cs
- DecoderExceptionFallback.cs
- AudienceUriMode.cs
- WebSysDefaultValueAttribute.cs
- EndOfStreamException.cs
- TimeSpanValidatorAttribute.cs
- MouseGestureValueSerializer.cs
- CheckBoxList.cs
- SequenceFullException.cs
- ListControlConvertEventArgs.cs
- SystemIPv4InterfaceProperties.cs
- CategoryNameCollection.cs
- EntityDataSourceChangedEventArgs.cs
- BidirectionalDictionary.cs
- MinMaxParagraphWidth.cs
- Typography.cs
- PopupRootAutomationPeer.cs
- SqlInternalConnection.cs
- ReadOnlyCollectionBase.cs
- VisualStateChangedEventArgs.cs
- EventLevel.cs
- BlurEffect.cs
- DbConnectionPoolGroupProviderInfo.cs
- XmlUrlResolver.cs
- MasterPageCodeDomTreeGenerator.cs
- IntSecurity.cs
- RoutedEventValueSerializer.cs
- ProcessThreadDesigner.cs
- FileLogRecordEnumerator.cs
- Attachment.cs
- EntityDataSourceEntityTypeFilterConverter.cs
- RankException.cs
- ContextStaticAttribute.cs
- DataControlFieldHeaderCell.cs
- jithelpers.cs
- HuffModule.cs
- IntranetCredentialPolicy.cs
- GridErrorDlg.cs
- mactripleDES.cs
- SharedUtils.cs
- CheckPair.cs
- RadioButtonAutomationPeer.cs
- AutomationElement.cs
- NavigationPropertyEmitter.cs
- BitmapEffectState.cs
- ISO2022Encoding.cs
- ReadingWritingEntityEventArgs.cs
- BindToObject.cs
- NameNode.cs
- VerificationAttribute.cs
- ThreadStartException.cs
- GroupBoxRenderer.cs
- VectorCollection.cs
- NativeWindow.cs
- SingleSelectRootGridEntry.cs
- EventLogPermission.cs
- PackageRelationshipSelector.cs
- EmptyEnumerator.cs
- CompilerGlobalScopeAttribute.cs
- RelatedPropertyManager.cs
- MultipleViewProviderWrapper.cs
- Formatter.cs
- CompilerCollection.cs
- WindowClosedEventArgs.cs
- PeerObject.cs
- EntityDataSourceContainerNameConverter.cs
- PipeConnection.cs
- LicenseManager.cs
- SspiHelper.cs
- TextOptions.cs
- MultiAsyncResult.cs
- CollectionBuilder.cs
- TagPrefixInfo.cs
- QualifiedCellIdBoolean.cs
- MediaScriptCommandRoutedEventArgs.cs
- NativeCompoundFileAPIs.cs
- RtfControls.cs
- DynamicFilterExpression.cs
- RotationValidation.cs
- FieldToken.cs
- HtmlContainerControl.cs
- SessionState.cs
- WebPartAuthorizationEventArgs.cs
- StyleSelector.cs
- Authorization.cs
- Timer.cs
- IteratorAsyncResult.cs
- MergePropertyDescriptor.cs