1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . IO ;
4
- using System . Linq ;
5
- using System . Text ;
6
- using System . Threading . Tasks ;
7
-
8
- namespace Cucumber . HtmlFormatter ;
1
+ namespace Cucumber . HtmlFormatter ;
9
2
10
3
public class JsonInHtmlWriter : StreamWriter
11
4
{
12
- private readonly int BUFFER_SIZE = 1024 ;
13
- private StreamWriter Writer ;
14
- private char [ ] escapeBuffer ;
5
+ private const int BUFFER_SIZE = 1024 ;
6
+ private readonly StreamWriter _writer ;
7
+ private readonly char [ ] _escapeBuffer ;
15
8
16
9
public JsonInHtmlWriter ( StreamWriter writer ) : base ( writer . BaseStream )
17
10
{
18
- Writer = writer ;
19
- escapeBuffer = new char [ BUFFER_SIZE ] ; // Initialize escapeBuffer
11
+ _writer = writer ;
12
+ _escapeBuffer = new char [ BUFFER_SIZE ] ; // Initialize escapeBuffer
20
13
}
21
14
22
15
public override void Write ( string value )
@@ -39,17 +32,17 @@ public override void Write(char[] source, int offset, int length)
39
32
if ( offset + length > source . GetLength ( 0 ) )
40
33
throw new ArgumentException ( "Cannot read past the end of the input source char array." ) ;
41
34
42
- char [ ] destination = PrepareBuffer ( ) ;
43
- int flushAt = BUFFER_SIZE - 2 ;
44
- int written = 0 ;
45
- for ( int i = offset ; i < offset + length ; i ++ )
35
+ var destination = PrepareBuffer ( ) ;
36
+ var flushAt = BUFFER_SIZE - 2 ;
37
+ var written = 0 ;
38
+ for ( var i = offset ; i < offset + length ; i ++ )
46
39
{
47
- char c = source [ i ] ;
40
+ var c = source [ i ] ;
48
41
49
42
// Flush buffer if (nearly) full
50
43
if ( written >= flushAt )
51
44
{
52
- Writer . Write ( destination , 0 , written ) ;
45
+ _writer . Write ( destination , 0 , written ) ;
53
46
written = 0 ;
54
47
}
55
48
@@ -63,7 +56,7 @@ public override void Write(char[] source, int offset, int length)
63
56
// Flush any remaining
64
57
if ( written > 0 )
65
58
{
66
- Writer . Write ( destination , 0 , written ) ;
59
+ _writer . Write ( destination , 0 , written ) ;
67
60
}
68
61
}
69
62
@@ -72,17 +65,17 @@ public override async Task WriteAsync(char[] source, int offset, int length)
72
65
if ( offset + length > source . GetLength ( 0 ) )
73
66
throw new ArgumentException ( "Cannot read past the end of the input source char array." ) ;
74
67
75
- char [ ] destination = PrepareBuffer ( ) ;
76
- int flushAt = BUFFER_SIZE - 2 ;
77
- int written = 0 ;
78
- for ( int i = offset ; i < offset + length ; i ++ )
68
+ var destination = PrepareBuffer ( ) ;
69
+ var flushAt = BUFFER_SIZE - 2 ;
70
+ var written = 0 ;
71
+ for ( var i = offset ; i < offset + length ; i ++ )
79
72
{
80
73
char c = source [ i ] ;
81
74
82
75
// Flush buffer if (nearly) full
83
76
if ( written >= flushAt )
84
77
{
85
- await Writer . WriteAsync ( destination , 0 , written ) ;
78
+ await _writer . WriteAsync ( destination , 0 , written ) ;
86
79
written = 0 ;
87
80
}
88
81
@@ -96,28 +89,28 @@ public override async Task WriteAsync(char[] source, int offset, int length)
96
89
// Flush any remaining
97
90
if ( written > 0 )
98
91
{
99
- await Writer . WriteAsync ( destination , 0 , written ) ;
92
+ await _writer . WriteAsync ( destination , 0 , written ) ;
100
93
}
101
94
}
95
+
102
96
private char [ ] PrepareBuffer ( )
103
97
{
104
98
// Reuse the same buffer, avoids repeated array allocation
105
- escapeBuffer ??= new char [ BUFFER_SIZE ] ;
106
- return escapeBuffer ;
99
+ return _escapeBuffer ;
107
100
}
108
101
109
102
public override void Flush ( )
110
103
{
111
- Writer . Flush ( ) ;
104
+ _writer . Flush ( ) ;
112
105
}
113
106
114
107
public override async Task FlushAsync ( )
115
108
{
116
- await Writer . FlushAsync ( ) ;
109
+ await _writer . FlushAsync ( ) ;
117
110
}
118
111
119
112
public override void Close ( )
120
113
{
121
- Writer . Close ( ) ;
114
+ _writer . Close ( ) ;
122
115
}
123
116
}
0 commit comments