Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- final MustacheFactory mf = new DefaultMustacheFactory();
- [...]
- private Mustache initMustache() {
- log.debug("Compiling mustache with '{}'", this.templatePath);
- String templateXml = getTemplateString();
- return mf.compile(new StringReader(templateXml), this.templatePath);
- }
- private String getTemplateString() {
- String templateXml;
- try (BufferedReader br = new BufferedReader(new InputStreamReader(this.templateInputStream))) {
- templateXml = br.lines().collect(Collectors.joining("\n"));
- } catch (IOException e) {
- String message = "Cannot read template from '" + this.templateInputStream + "'";
- throw new UncheckedIOException(message, e);
- }
- return templateXml;
- }
- /*********************** AFTER ********************************/
- private Mustache getInitializedMustache() {
- log.debug("Compiling mustache with '{}'", templatePath);
- return Try.withResources(this::readerOfInputStream)
- .of(this::stringWithNewlineFromReader)
- .map(StringReader::new)
- .map(stringReader -> mf.compile(stringReader, templatePath))
- .getOrElseThrow(this::mustacheInitException);
- }
- private String stringWithNewlineFromReader(BufferedReader reader) {
- return reader
- .lines()
- .collect(Collectors.joining("\n"));
- }
- private BufferedReader readerOfInputStream() {
- return new BufferedReader(new InputStreamReader(this.templateInputStream));
- }
- private MustacheException mustacheInitException(Throwable throwable) {
- return new MustacheException(
- "Cannot init mustache template from '" + this.templatePath + "'",
- throwable
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement