@Test public void testFileResolveEnvVarsBadPath() throws EtiqetException { String testFilePath = "${etiqet.directory}/path/does/not/exist/test.properties"; InputStream inputStream = fileResolveEnvVars(testFilePath); assertNull(inputStream); inputStream = fileResolveEnvVars(""); assertNull(inputStream); inputStream = fileResolveEnvVars(null); assertNull(inputStream); }
public static InputStream fileResolveEnvVars(String path) throws EtiqetException { InputStream res = null; if (!StringUtils.isNullOrEmpty(path)) { StringBuilder sbr = new StringBuilder(); path = resolveEnvVars(path); try (Stream<String> stream = Files.lines(Paths.get(path))) { Iterator<String> str = stream.iterator(); while (str.hasNext()) { String str2 = str.next(); Pattern p = Pattern.compile(("\\$\\{([\\w\\.]+)\\}|\\$([\\w\\.]+)")); Matcher m = p.matcher(str2); StringBuffer sb = new StringBuffer(); resolveEnvVars(m, sb); sbr.append(sb) .append(System.lineSeparator()); } res = new ByteArrayInputStream( sbr.toString().replace("/", File.separator).getBytes(StandardCharsets.UTF_8.name())); } catch (IOException e) { LOG.error("Exception occurred while reading file {}", path, e); } } return res; }
Environment { public static InputStream fileResolveEnvVars(String path) throws EtiqetException { InputStream res = null; if (!StringUtils.isNullOrEmpty(path)) { StringBuilder sbr = new StringBuilder(); path = resolveEnvVars(path); try (Stream<String> stream = Files.lines(Paths.get(path))) { Iterator<String> str = stream.iterator(); while (str.hasNext()) { String str2 = str.next(); Pattern p = Pattern.compile(("\\$\\{([\\w\\.]+)\\}|\\$([\\w\\.]+)")); Matcher m = p.matcher(str2); StringBuffer sb = new StringBuffer(); resolveEnvVars(m, sb); sbr.append(sb) .append(System.lineSeparator()); } res = new ByteArrayInputStream( sbr.toString().replace("/", File.separator).getBytes(StandardCharsets.UTF_8.name())); } catch (IOException e) { LOG.error("Exception occurred while reading file {}", path, e); } } return res; } }
Environment { public static InputStream fileResolveEnvVars(String path) throws EtiqetException { InputStream res = null; if (!StringUtils.isNullOrEmpty(path)) { StringBuilder sbr = new StringBuilder(); path = resolveEnvVars(path); try (Stream<String> stream = Files.lines(Paths.get(path))) { Iterator<String> str = stream.iterator(); while (str.hasNext()) { String str2 = str.next(); Pattern p = Pattern.compile(("\\$\\{([\\w\\.]+)\\}|\\$([\\w\\.]+)")); Matcher m = p.matcher(str2); StringBuffer sb = new StringBuffer(); resolveEnvVars(m, sb); sbr.append(sb) .append(System.lineSeparator()); } res = new ByteArrayInputStream( sbr.toString().replace("/", File.separator).getBytes(StandardCharsets.UTF_8.name())); } catch (IOException e) { LOG.error("Exception occurred while reading file {}", path, e); } } return res; } private  Environment(); }
Environment { public static InputStream fileResolveEnvVars(String path) throws EtiqetException { InputStream res = null; if (!StringUtils.isNullOrEmpty(path)) { StringBuilder sbr = new StringBuilder(); path = resolveEnvVars(path); try (Stream<String> stream = Files.lines(Paths.get(path))) { Iterator<String> str = stream.iterator(); while (str.hasNext()) { String str2 = str.next(); Pattern p = Pattern.compile(("\\$\\{([\\w\\.]+)\\}|\\$([\\w\\.]+)")); Matcher m = p.matcher(str2); StringBuffer sb = new StringBuffer(); resolveEnvVars(m, sb); sbr.append(sb) .append(System.lineSeparator()); } res = new ByteArrayInputStream( sbr.toString().replace("/", File.separator).getBytes(StandardCharsets.UTF_8.name())); } catch (IOException e) { LOG.error("Exception occurred while reading file {}", path, e); } } return res; } private  Environment(); static Boolean isEnvVarSet(String key); static String resolveEnvVars(String input); static InputStream fileResolveEnvVars(String path); }
Environment { public static InputStream fileResolveEnvVars(String path) throws EtiqetException { InputStream res = null; if (!StringUtils.isNullOrEmpty(path)) { StringBuilder sbr = new StringBuilder(); path = resolveEnvVars(path); try (Stream<String> stream = Files.lines(Paths.get(path))) { Iterator<String> str = stream.iterator(); while (str.hasNext()) { String str2 = str.next(); Pattern p = Pattern.compile(("\\$\\{([\\w\\.]+)\\}|\\$([\\w\\.]+)")); Matcher m = p.matcher(str2); StringBuffer sb = new StringBuffer(); resolveEnvVars(m, sb); sbr.append(sb) .append(System.lineSeparator()); } res = new ByteArrayInputStream( sbr.toString().replace("/", File.separator).getBytes(StandardCharsets.UTF_8.name())); } catch (IOException e) { LOG.error("Exception occurred while reading file {}", path, e); } } return res; } private  Environment(); static Boolean isEnvVarSet(String key); static String resolveEnvVars(String input); static InputStream fileResolveEnvVars(String path);  }