@Test public void testGet_Args() throws Exception { String result = new TextFile().get("sql/selectByArgs.sql", new String[]{"1", "2"}); String[] results = result.split("\n"); int i = 0; assertEquals(results[i++], "SELECT"); assertEquals(results[i++], " *"); assertEquals(results[i++], " FROM"); assertEquals(results[i++], " emp"); assertEquals(results[i++], " WHERE"); assertEquals(results[i++], " deptno = ?"); assertEquals(results[i++], " AND job = ?"); assertEquals(results[i++], " ORDER BY"); assertEquals(results[i++], " empno"); assertEquals(i, results.length); }
@Override public String get(String resource, Object args) { String template = templateCache.get(resource); if (template != null) { return template; } try { InputStream in = getClass().getResourceAsStream("/" + resource); if (in == null) { throw new FileNotFoundException("Template '" + resource + "' not found"); } try (BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); Stream<String> stream = br.lines()) { template = stream.collect(Collectors.joining("\n")); } } catch (IOException ex) { throw new UncheckedIOException(ex); } templateCache.put(resource, template); return template; }
TextFile implements TemplateEngine { @Override public String get(String resource, Object args) { String template = templateCache.get(resource); if (template != null) { return template; } try { InputStream in = getClass().getResourceAsStream("/" + resource); if (in == null) { throw new FileNotFoundException("Template '" + resource + "' not found"); } try (BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); Stream<String> stream = br.lines()) { template = stream.collect(Collectors.joining("\n")); } } catch (IOException ex) { throw new UncheckedIOException(ex); } templateCache.put(resource, template); return template; } }
TextFile implements TemplateEngine { @Override public String get(String resource, Object args) { String template = templateCache.get(resource); if (template != null) { return template; } try { InputStream in = getClass().getResourceAsStream("/" + resource); if (in == null) { throw new FileNotFoundException("Template '" + resource + "' not found"); } try (BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); Stream<String> stream = br.lines()) { template = stream.collect(Collectors.joining("\n")); } } catch (IOException ex) { throw new UncheckedIOException(ex); } templateCache.put(resource, template); return template; }  }
TextFile implements TemplateEngine { @Override public String get(String resource, Object args) { String template = templateCache.get(resource); if (template != null) { return template; } try { InputStream in = getClass().getResourceAsStream("/" + resource); if (in == null) { throw new FileNotFoundException("Template '" + resource + "' not found"); } try (BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); Stream<String> stream = br.lines()) { template = stream.collect(Collectors.joining("\n")); } } catch (IOException ex) { throw new UncheckedIOException(ex); } templateCache.put(resource, template); return template; }  @Override String get(String resource, Object args); @Override String get(String resource); }
TextFile implements TemplateEngine { @Override public String get(String resource, Object args) { String template = templateCache.get(resource); if (template != null) { return template; } try { InputStream in = getClass().getResourceAsStream("/" + resource); if (in == null) { throw new FileNotFoundException("Template '" + resource + "' not found"); } try (BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); Stream<String> stream = br.lines()) { template = stream.collect(Collectors.joining("\n")); } } catch (IOException ex) { throw new UncheckedIOException(ex); } templateCache.put(resource, template); return template; }  @Override String get(String resource, Object args); @Override String get(String resource);  }