1
1
/**
2
- * Copyright 2010-2017 the original author or authors.
2
+ * Copyright 2010-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -96,8 +96,7 @@ public int read(char[] cbuf, int off, int len) throws IOException {
96
96
int result = in .read (cbuf , off , len );
97
97
if (result == -1 ) {
98
98
if (lineBuffer .length () > 0 && (!undo || inUndo )) {
99
- buffer .append (lineBuffer ).append (lineSeparator );
100
- lineBuffer .setLength (0 );
99
+ addToBuffer (lineBuffer );
101
100
}
102
101
if (buffer .length () > 0 ) {
103
102
break ;
@@ -115,10 +114,8 @@ public int read(char[] cbuf, int off, int len) throws IOException {
115
114
switch (part ) {
116
115
case AFTER_UNDO_TAG :
117
116
if (undo ) {
118
- replaceVariables ();
119
- buffer .append (lineBuffer .delete (afterCommentPrefixIndex , afterDoubleSlashIndex )
120
- .insert (afterCommentPrefixIndex , ' ' )).append (lineSeparator );
121
- lineBuffer .setLength (0 );
117
+ addToBuffer (lineBuffer .delete (afterCommentPrefixIndex , afterDoubleSlashIndex )
118
+ .insert (afterCommentPrefixIndex , ' ' ));
122
119
inUndo = true ;
123
120
} else {
124
121
// Won't read from the file anymore.
@@ -132,11 +129,11 @@ public int read(char[] cbuf, int off, int len) throws IOException {
132
129
}
133
130
break ;
134
131
case NOT_UNDO_LINE :
135
- if (!undo || (undo && inUndo )) {
136
- replaceVariables ();
137
- buffer .append (lineBuffer ).append (lineSeparator );
132
+ if (!undo || inUndo ) {
133
+ addToBuffer (lineBuffer );
134
+ } else {
135
+ lineBuffer .setLength (0 );
138
136
}
139
- lineBuffer .setLength (0 );
140
137
break ;
141
138
default :
142
139
break ;
@@ -154,13 +151,19 @@ public int read(char[] cbuf, int off, int len) throws IOException {
154
151
return readFromBuffer (cbuf , off , len );
155
152
}
156
153
157
- private void replaceVariables () {
154
+ private void addToBuffer (StringBuilder line ) {
155
+ replaceVariables (line );
156
+ buffer .append (line ).append (lineSeparator );
157
+ lineBuffer .setLength (0 );
158
+ }
159
+
160
+ private void replaceVariables (StringBuilder line ) {
158
161
if (variableStatus == VariableStatus .FOUND_POSSIBLE_VARIABLE ) {
159
- String lineBufferStr = lineBuffer .toString ();
162
+ String lineBufferStr = line .toString ();
160
163
String processed = PropertyParser .parse (lineBufferStr , variables );
161
164
if (!lineBufferStr .equals (processed )) {
162
- lineBuffer .setLength (0 );
163
- lineBuffer .append (processed );
165
+ line .setLength (0 );
166
+ line .append (processed );
164
167
}
165
168
}
166
169
variableStatus = VariableStatus .NOTHING ;
0 commit comments