How can I output to a given writer all the rows in the list that consist only of Latin letters or numbers and return the number of successfully written bytes before the first exception using a lambda expression?
My code:
public int writeAllCountingBytesTransferred(Writer writer, List<String> list) {
return list.stream().filter(x -> x.matches("^[a-zA-Z0-9]+$") ).forEach(x-> {
try {
writer.write(x);
how do I count bytes?
} catch (IOException e) {
how do I return bytes?
}
});
}