34
34
import java .util .function .BiConsumer ;
35
35
import java .util .regex .Pattern ;
36
36
import java .util .stream .Collectors ;
37
+ import java .util .stream .Stream ;
37
38
38
39
import org .yaml .snakeyaml .LoaderOptions ;
39
40
import org .yaml .snakeyaml .Yaml ;
@@ -208,7 +209,7 @@ private List<String> getLines() {
208
209
StringWriter writer = new StringWriter ();
209
210
store (writer , null );
210
211
List <String > lines = Arrays .stream (writer .toString ().split ("\n " ))
211
- .map (this ::postProcess )
212
+ .flatMap (this ::postProcess )
212
213
.collect (Collectors .toList ());
213
214
lines .remove (0 );
214
215
return lines ;
@@ -218,29 +219,39 @@ private List<String> getLines() {
218
219
}
219
220
}
220
221
221
- private String postProcess (String line ) {
222
+ private Stream < String > postProcess (String line ) {
222
223
int split = line .indexOf ('=' );
223
224
if (split == -1 ) {
224
- return line ;
225
+ return Stream . of ( line ) ;
225
226
}
226
227
String name = line .substring (0 , split );
227
- String value = line .substring (split );
228
+ String value = line .substring (split + 1 );
228
229
if (name .contains (BLANK_LINE )) {
229
- return "" ;
230
+ return Stream . of ( "" ) ;
230
231
}
231
232
if (name .contains (COMMENT )) {
232
233
try {
233
234
Properties properties = new Properties ();
234
235
properties .load (new ByteArrayInputStream (line .getBytes (StandardCharsets .UTF_8 )));
235
- return ( String ) properties .values ().iterator ().next ();
236
+ return Stream . of (( String ) properties .values ().iterator ().next () );
236
237
}
237
238
catch (IOException ex ) {
238
239
throw new IllegalStateException (ex );
239
240
}
240
241
}
241
242
value = value .replace ("\\ :" , ":" );
242
243
value = value .replace ("\\ =" , "=" );
243
- return name + value ;
244
+ if (!value .contains ("\\ n" )) {
245
+ return Stream .of (name + "=" + value );
246
+ }
247
+
248
+ List <String > multilines = new ArrayList <>(Arrays .asList (value .split ("\\ \\ n" )));
249
+ for (int i = 0 ; i < multilines .size (); i ++) {
250
+ boolean last = i == multilines .size () - 1 ;
251
+ multilines .set (i , multilines .get (i ) + "\\ n" + ((!last ) ? "\\ " : "" ));
252
+ }
253
+ multilines .add (0 , name + "=\\ " );
254
+ return multilines .stream ();
244
255
}
245
256
246
257
}
0 commit comments