Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / Log / System / IO / Log / FileRegion.cs / 1 / FileRegion.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.IO.Log { using System; using System.Diagnostics; using System.IO; public sealed class FileRegion { long fileLength; string path; long offset; long length; byte[] fixedContent; internal FileRegion(long fileLength, string path, long offset, long length) { this.fileLength = fileLength; this.path = path; this.offset = offset; this.length = length; } internal FileRegion(long fileLength, string path, long offset, byte[] fixedContent) { this.fileLength = fileLength; this.path = path; this.offset = offset; this.length = fixedContent.LongLength; this.fixedContent = fixedContent; } public long FileLength { get { return this.fileLength; } } public long Offset { get { return this.offset; } } public string Path { get { return this.path; } } public Stream GetStream() { if (this.fixedContent != null) { return new MemoryStream(this.fixedContent, 0, this.fixedContent.Length, false, false); } else { Stream innerStream = new FileStream(this.path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); return new Substream(innerStream, this.offset, this.length); } } class Substream : Stream { Stream innerStream; long offset; long length; internal Substream(Stream innerStream, long offset, long length) { this.innerStream = innerStream; this.offset = offset; this.length = length; } public override bool CanRead { get { return true; } } public override bool CanSeek { get { return true; } } public override bool CanWrite { get { return false; } } public override long Length { get { return this.length; } } public override long Position { get { return this.innerStream.Position - this.offset; } set { this.innerStream.Position = value + this.offset; } } public override void Close() { this.innerStream.Close(); base.Close(); } public override void Flush() { this.innerStream.Flush(); } public override int Read(byte[] buffer, int offset, int count) { // Truncate read if it goes past the length of the // stream... // if (this.Length - this.Position < count) { count = checked((int)(this.Length - this.Position)); if (count < 0) return 0; } return this.innerStream.Read(buffer, offset, count); } public override long Seek(long offset, SeekOrigin origin) { if (origin == SeekOrigin.Begin) { offset += this.offset; } else if (origin == SeekOrigin.End) { offset = this.offset + this.length - offset; origin = SeekOrigin.Begin; } return this.innerStream.Seek(offset, origin); } public override void SetLength(long value) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported()); } public override void Write(byte[] buffer, int offset, int count) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported()); } public override void WriteByte(byte value) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.NotSupported()); } } } } // 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
- GenericIdentity.cs
- UnhandledExceptionEventArgs.cs
- DataViewManagerListItemTypeDescriptor.cs
- ExpressionBuilder.cs
- AstTree.cs
- PersonalizationAdministration.cs
- BatchServiceHost.cs
- StylusDevice.cs
- PrinterSettings.cs
- ThreadAttributes.cs
- ExpressionBuilderContext.cs
- HMACSHA1.cs
- BaseConfigurationRecord.cs
- ConfigUtil.cs
- QueryContinueDragEvent.cs
- ButtonFieldBase.cs
- SqlConnectionHelper.cs
- httpserverutility.cs
- Function.cs
- CriticalExceptions.cs
- MembershipUser.cs
- ScriptReference.cs
- ErrorsHelper.cs
- RSAPKCS1SignatureDeformatter.cs
- TcpWorkerProcess.cs
- SystemResources.cs
- TimeZoneInfo.cs
- MetadataArtifactLoaderComposite.cs
- TimeIntervalCollection.cs
- GenerateHelper.cs
- DesignerActionList.cs
- WebBrowserSiteBase.cs
- XmlILConstructAnalyzer.cs
- QuaternionAnimation.cs
- SoapException.cs
- CompletedAsyncResult.cs
- StreamSecurityUpgradeProvider.cs
- HttpListener.cs
- ProcessInputEventArgs.cs
- SmiRequestExecutor.cs
- XmlResolver.cs
- PageParser.cs
- Empty.cs
- StdValidatorsAndConverters.cs
- CodeDOMUtility.cs
- ImageField.cs
- CleanUpVirtualizedItemEventArgs.cs
- SourceItem.cs
- BaseTemplateCodeDomTreeGenerator.cs
- TrackingServices.cs
- InternalBase.cs
- RuleSettingsCollection.cs
- ListBox.cs
- SetterBaseCollection.cs
- StreamWriter.cs
- EncoderReplacementFallback.cs
- WCFBuildProvider.cs
- ResourceDescriptionAttribute.cs
- RegexCode.cs
- IdentifierCreationService.cs
- Quaternion.cs
- ExtentKey.cs
- SafePointer.cs
- _ScatterGatherBuffers.cs
- HtmlForm.cs
- RequestReplyCorrelator.cs
- SpeechEvent.cs
- SQLInt32.cs
- Currency.cs
- Pair.cs
- NamespaceDecl.cs
- CommandManager.cs
- CompilationSection.cs
- InvalidOleVariantTypeException.cs
- TabletCollection.cs
- SystemException.cs
- Internal.cs
- SystemWebExtensionsSectionGroup.cs
- CustomAttributeFormatException.cs
- TraceListeners.cs
- SingleConverter.cs
- _LocalDataStore.cs
- DispatcherTimer.cs
- KeyFrames.cs
- ProfileServiceManager.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- ParagraphVisual.cs
- IntPtr.cs
- ProfileGroupSettingsCollection.cs
- IList.cs
- ReferenceEqualityComparer.cs
- StatusBarItem.cs
- SafeHandle.cs
- ImageListDesigner.cs
- Int32AnimationBase.cs
- BitmapInitialize.cs
- EmptyEnumerator.cs
- FlowDocumentPageViewerAutomationPeer.cs
- COM2ColorConverter.cs
- BrowserTree.cs