9
9
*/
10
10
final class Append {
11
11
12
+ private static final boolean debug = Boolean .getBoolean ("append.debug" );
13
+
12
14
private final Writer writer ;
15
+ private final StringBuilder stringBuilder = new StringBuilder ();
13
16
private int nameIndex ;
14
17
private boolean comma ;
15
18
private String extraIndent ;
@@ -27,8 +30,14 @@ Append indent(String content) {
27
30
try {
28
31
if (extraIndent != null ) {
29
32
writer .append (extraIndent );
33
+ if (debug ) {
34
+ stringBuilder .append (extraIndent );
35
+ }
30
36
}
31
37
writer .append (content );
38
+ if (debug ) {
39
+ stringBuilder .append (content );
40
+ }
32
41
return this ;
33
42
} catch (IOException e ) {
34
43
throw new UncheckedIOException (e );
@@ -38,6 +47,9 @@ Append indent(String content) {
38
47
Append append (String content ) {
39
48
try {
40
49
writer .append (content );
50
+ if (debug ) {
51
+ stringBuilder .append (content );
52
+ }
41
53
return this ;
42
54
} catch (IOException e ) {
43
55
throw new UncheckedIOException (e );
@@ -56,6 +68,9 @@ void close() {
56
68
Append eol () {
57
69
try {
58
70
writer .append ("\n " );
71
+ if (debug ) {
72
+ stringBuilder .append ("\n " );
73
+ }
59
74
return this ;
60
75
} catch (IOException e ) {
61
76
throw new UncheckedIOException (e );
@@ -86,4 +101,10 @@ void commaAppend(String name) {
86
101
}
87
102
append (name );
88
103
}
104
+
105
+
106
+ @ Override
107
+ public String toString () {
108
+ return stringBuilder .toString ();
109
+ }
89
110
}
0 commit comments