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
- OleDbCommand.cs
- FolderNameEditor.cs
- DispatchOperationRuntime.cs
- StateRuntime.cs
- TypeConverterHelper.cs
- ResourceAssociationSetEnd.cs
- StorageTypeMapping.cs
- WinFormsUtils.cs
- MdbDataFileEditor.cs
- CorrelationManager.cs
- SmiRequestExecutor.cs
- ProfessionalColorTable.cs
- TypeProvider.cs
- FrameworkContentElement.cs
- ObjectStateEntryOriginalDbUpdatableDataRecord.cs
- Expander.cs
- Int32AnimationUsingKeyFrames.cs
- ToolStripSystemRenderer.cs
- DataGridViewHeaderCell.cs
- UriSection.cs
- XamlVector3DCollectionSerializer.cs
- FragmentQuery.cs
- XmlAttributes.cs
- CommunicationObjectManager.cs
- CustomValidator.cs
- ThicknessAnimationBase.cs
- GraphicsContainer.cs
- SpotLight.cs
- BulletDecorator.cs
- WebBrowserNavigatingEventHandler.cs
- AtomServiceDocumentSerializer.cs
- AutomationTextAttribute.cs
- HttpCapabilitiesEvaluator.cs
- WorkflowInspectionServices.cs
- SamlDoNotCacheCondition.cs
- MouseButtonEventArgs.cs
- ConsoleKeyInfo.cs
- PrimaryKeyTypeConverter.cs
- ExceptionUtil.cs
- ClientBuildManagerCallback.cs
- ImageInfo.cs
- TableColumn.cs
- WebResourceAttribute.cs
- DesignerFrame.cs
- SecurityTokenTypes.cs
- CompiledQueryCacheEntry.cs
- TraceListeners.cs
- QueuePropertyVariants.cs
- DoubleConverter.cs
- HijriCalendar.cs
- PageHandlerFactory.cs
- EmbeddedMailObjectsCollection.cs
- WsdlServiceChannelBuilder.cs
- XslAst.cs
- UICuesEvent.cs
- ObjRef.cs
- SqlBooleanizer.cs
- ListenerConstants.cs
- PrtCap_Base.cs
- EntityDataSourceQueryBuilder.cs
- LogEntrySerializer.cs
- MetadataPropertyvalue.cs
- ADMembershipProvider.cs
- SourceItem.cs
- ManagementScope.cs
- Parser.cs
- HitTestParameters3D.cs
- WSHttpTransportSecurityElement.cs
- Binding.cs
- DataGridCommandEventArgs.cs
- BufferModesCollection.cs
- EnvironmentPermission.cs
- WindowsFormsSectionHandler.cs
- VisualProxy.cs
- AutomationPropertyInfo.cs
- GroupItemAutomationPeer.cs
- TypefaceMetricsCache.cs
- PaginationProgressEventArgs.cs
- HtmlDocument.cs
- SafeCoTaskMem.cs
- RequestCachePolicy.cs
- XmlRootAttribute.cs
- XmlSchema.cs
- srgsitem.cs
- HtmlInputButton.cs
- ListViewTableCell.cs
- ResourceContainer.cs
- NotFiniteNumberException.cs
- XmlQueryRuntime.cs
- SecurityDescriptor.cs
- SemaphoreFullException.cs
- Italic.cs
- Vector3D.cs
- Socket.cs
- SystemUnicastIPAddressInformation.cs
- ApplicationDirectory.cs
- TypeListConverter.cs
- ExceptionUtil.cs
- BitmapSourceSafeMILHandle.cs
- ScriptResourceAttribute.cs