Created
December 16, 2020 17:26
-
-
Save xrrocha/cac0e9eebd5f868547fcd6546952186a to your computer and use it in GitHub Desktop.
code block for README-6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Collect readers from args/stdin | |
final Stream<BufferedReader> readers; | |
if (args.length > 0) { | |
readers = Arrays.stream(args) | |
.map(filename -> { | |
try { | |
return new BufferedReader( | |
new FileReader(filename)); | |
} catch (Exception e) { | |
// No lambda checked exceptions | |
throw new RuntimeException(e); | |
} | |
}); | |
} else { | |
readers = Stream.of( | |
new BufferedReader( | |
new InputStreamReader(System.in))); | |
} | |
// Swallow all readers into one string | |
final var content = readers | |
.flatMap(BufferedReader::lines) | |
.collect(Collectors.joining("\n")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment