In java 8, this code runs perfectly:
Stream<String> lines = Files.lines(outfile) {
List<String> replaced = lines
.map(line ->
line.replaceAll('date1', "$newdate1"))
.collect(Collectors.toList())
Files.write(outfile, replaced)
}
In groovy, because I am using a groovy version previous to the 2.6, it doesn't. I cannot change it, is the one used in Katalon. I receive an error "unexpected token ->"
I have tried to enclose the lambda function with brackets these 2 ways, but none works:
Stream<String> lines = Files.lines(outfile) {
List<String> replaced = lines
.map({line ->
line}.replaceAll('date1', "$newdate1"))
.collect(Collectors.toList())
Files.write(outfile, replaced)
}
and
Stream<String> lines = Files.lines(outfile) {
List<String> replaced = lines
.map({line ->
line.replaceAll('date1', "$newdate1")})
.collect(Collectors.toList())
Files.write(outfile, replaced)
}
This wrapping kind of isolate/takes out of context line, that is not recognized as a String, and replaceAll
is not working.
I don't know what is the right way to do it, to make it work.