|
2 | 2 |
|
3 | 3 | namespace LogExpert.Core.Interface; |
4 | 4 |
|
| 5 | +/// <summary> |
| 6 | +/// Provides a position-aware stream reader interface for reading log files with support for character encoding |
| 7 | +/// and position tracking. |
| 8 | +/// </summary> |
| 9 | +/// <remarks> |
| 10 | +/// <para> |
| 11 | +/// This interface abstracts log file reading operations, providing a consistent API for different stream reading |
| 12 | +/// implementations. All implementations must maintain accurate byte position tracking to support seeking and |
| 13 | +/// re-reading specific portions of the log file. |
| 14 | +/// </para> |
| 15 | +/// <para> |
| 16 | +/// Implementations include: |
| 17 | +/// <list type="bullet"> |
| 18 | +/// <item><description><c>PositionAwareStreamReaderLegacy</c> - Character-by-character reading for precise position control</description></item> |
| 19 | +/// <item><description><c>PositionAwareStreamReaderSystem</c> - Uses .NET's StreamReader.ReadLine() for improved performance</description></item> |
| 20 | +/// <item><description><c>PositionAwareStreamReaderPipeline</c> - Modern async pipeline-based implementation using System.IO.Pipelines</description></item> |
| 21 | +/// <item><description><c>XmlLogReader</c> - Decorator for reading structured XML log blocks (e.g., Log4j XML format)</description></item> |
| 22 | +/// </list> |
| 23 | +/// </para> |
| 24 | +/// </remarks> |
5 | 25 | public interface ILogStreamReader : IDisposable |
6 | 26 | { |
7 | 27 | #region Properties |
8 | 28 |
|
| 29 | + /// <summary> |
| 30 | + /// Gets or sets the current byte position in the stream. |
| 31 | + /// </summary> |
| 32 | + /// <value> |
| 33 | + /// The zero-based byte offset from the beginning of the stream, accounting for any byte order mark (BOM). |
| 34 | + /// </value> |
| 35 | + /// <remarks> |
| 36 | + /// <para> |
| 37 | + /// Setting the position causes the reader to seek to the specified byte offset in the underlying stream. |
| 38 | + /// This operation may be expensive as it requires resetting internal buffers and decoder state. |
| 39 | + /// </para> |
| 40 | + /// <para> |
| 41 | + /// The position should always represent a valid character boundary. Setting the position to the middle |
| 42 | + /// of a multi-byte character may result in decoding errors or incorrect output. |
| 43 | + /// </para> |
| 44 | + /// <para> |
| 45 | + /// After seeking, the next <see cref="ReadLine"/> or <see cref="ReadChar"/> operation will begin reading |
| 46 | + /// from the new position. |
| 47 | + /// </para> |
| 48 | + /// </remarks> |
9 | 49 | long Position { get; set; } |
10 | 50 |
|
| 51 | + /// <summary> |
| 52 | + /// Gets a value indicating whether the internal buffer has been completely filled from the stream. |
| 53 | + /// </summary> |
| 54 | + /// <value> |
| 55 | + /// <see langword="true"/> if the buffer is complete and no additional data needs to be loaded; |
| 56 | + /// otherwise, <see langword="false"/>. |
| 57 | + /// </value> |
| 58 | + /// <remarks> |
| 59 | + /// This property is primarily used to determine if the reader is still waiting for data to become |
| 60 | + /// available in the stream. Most implementations return <see langword="true"/> as they read directly |
| 61 | + /// from the stream without pre-buffering. |
| 62 | + /// </remarks> |
11 | 63 | bool IsBufferComplete { get; } |
12 | 64 |
|
| 65 | + /// <summary> |
| 66 | + /// Gets the character encoding used by the stream reader. |
| 67 | + /// </summary> |
| 68 | + /// <value> |
| 69 | + /// The <see cref="System.Text.Encoding"/> object representing the character encoding of the stream. |
| 70 | + /// </value> |
| 71 | + /// <remarks> |
| 72 | + /// <para> |
| 73 | + /// The encoding is determined during initialization and may be detected from a byte order mark (BOM) |
| 74 | + /// at the beginning of the stream, explicitly specified via <c>EncodingOptions</c>, or defaulted to |
| 75 | + /// the system default encoding. |
| 76 | + /// </para> |
| 77 | + /// <para> |
| 78 | + /// Supported BOM detection includes: |
| 79 | + /// <list type="bullet"> |
| 80 | + /// <item><description>UTF-8 (EF BB BF)</description></item> |
| 81 | + /// <item><description>UTF-16 Little Endian (FF FE)</description></item> |
| 82 | + /// <item><description>UTF-16 Big Endian (FE FF)</description></item> |
| 83 | + /// <item><description>UTF-32 Little Endian (FF FE 00 00)</description></item> |
| 84 | + /// <item><description>UTF-32 Big Endian (00 00 FE FF)</description></item> |
| 85 | + /// </list> |
| 86 | + /// </para> |
| 87 | + /// </remarks> |
13 | 88 | Encoding Encoding { get; } |
14 | 89 |
|
15 | 90 | #endregion |
16 | 91 |
|
17 | 92 | #region Public methods |
18 | 93 |
|
| 94 | + /// <summary> |
| 95 | + /// Reads the next character from the stream and advances the position by the number of bytes consumed. |
| 96 | + /// </summary> |
| 97 | + /// <returns> |
| 98 | + /// The next character as an <see cref="int"/>, or -1 if the end of the stream has been reached. |
| 99 | + /// </returns> |
| 100 | + /// <remarks> |
| 101 | + /// <para> |
| 102 | + /// The return value is an <see cref="int"/> rather than a <see cref="char"/> to allow returning -1 |
| 103 | + /// for end-of-stream, following the convention established by <see cref="StreamReader.Read()"/>. |
| 104 | + /// </para> |
| 105 | + /// <para> |
| 106 | + /// After reading a character, the <see cref="Position"/> property is automatically advanced by the |
| 107 | + /// number of bytes consumed from the stream. For single-byte encodings this is always 1, for UTF-16 |
| 108 | + /// this is always 2, but for variable-width encodings like UTF-8 this may be 1-4 bytes depending on |
| 109 | + /// the character. |
| 110 | + /// </para> |
| 111 | + /// <para> |
| 112 | + /// Some implementations (like <c>PositionAwareStreamReaderPipeline</c>) may not support this method |
| 113 | + /// and will throw <see cref="NotSupportedException"/> as they are optimized for line-based reading only. |
| 114 | + /// </para> |
| 115 | + /// </remarks> |
| 116 | + /// <exception cref="ObjectDisposedException">The reader has been disposed.</exception> |
| 117 | + /// <exception cref="NotSupportedException">The implementation does not support character-level reading.</exception> |
| 118 | + /// <exception cref="IOException">An I/O error occurred while reading from the stream.</exception> |
19 | 119 | int ReadChar (); |
20 | 120 |
|
| 121 | + /// <summary> |
| 122 | + /// Reads a line of characters from the stream and advances the position by the number of bytes consumed. |
| 123 | + /// </summary> |
| 124 | + /// <returns> |
| 125 | + /// A string containing the next line from the stream (excluding newline characters), or <see langword="null"/> |
| 126 | + /// if the end of the stream has been reached. |
| 127 | + /// </returns> |
| 128 | + /// <remarks> |
| 129 | + /// <para> |
| 130 | + /// A line is defined as a sequence of characters followed by a line feed (\n), a carriage return (\r), |
| 131 | + /// or a carriage return followed by a line feed (\r\n). The returned string does not include the |
| 132 | + /// terminating newline character(s). |
| 133 | + /// </para> |
| 134 | + /// <para> |
| 135 | + /// The <see cref="Position"/> property is automatically advanced by the total number of bytes consumed, |
| 136 | + /// including the newline character(s). |
| 137 | + /// </para> |
| 138 | + /// <para> |
| 139 | + /// Implementations may enforce a maximum line length constraint. Lines exceeding this limit will be |
| 140 | + /// truncated to the maximum length. The specific limit is implementation-dependent and typically |
| 141 | + /// specified during construction. |
| 142 | + /// </para> |
| 143 | + /// <para> |
| 144 | + /// If the stream ends without a trailing newline, the remaining characters are returned as the last line. |
| 145 | + /// Subsequent calls will return <see langword="null"/> to indicate end-of-stream. |
| 146 | + /// </para> |
| 147 | + /// </remarks> |
| 148 | + /// <exception cref="ObjectDisposedException">The reader has been disposed.</exception> |
| 149 | + /// <exception cref="IOException">An I/O error occurred while reading from the stream.</exception> |
| 150 | + /// <exception cref="InvalidOperationException"> |
| 151 | + /// The internal producer task encountered an error (specific to async implementations). |
| 152 | + /// </exception> |
21 | 153 | string ReadLine (); |
22 | 154 |
|
23 | 155 | #endregion |
|
0 commit comments