public static String copyToStringFromClasspath(ClassLoader classLoader, String path) throws IOException { InputStream is = classLoader.getResourceAsStream(path); if (is == null) { throw new FileNotFoundException("Resource [" + path + "] not found in classpath with class loader [" + classLoader + "]"); } return Streams.copyToString(new InputStreamReader(is, StandardCharsets.UTF_8)); }
@Override public String toString() { try { if (klass != null) { InputStream inputStream = klass.getResourceAsStream(path); if (inputStream == null) { throw new FileNotFoundException("Resource [" + path + "] not found in classpath with class [" + klass.getName() + "]"); } return Streams.copyToString(new InputStreamReader(inputStream, "UTF-8")); } else { return Streams.copyToStringFromClasspath(classLoader, path); } } catch (IOException e) { throw new EsSetupRuntimeException(e); } } }
public static String copyToStringFromClasspath(String path) throws IOException { InputStream is = Streams.class.getResourceAsStream(path); if (is == null) { throw new FileNotFoundException("Resource [" + path + "] not found in classpath"); } return Streams.copyToString(new InputStreamReader(is, StandardCharsets.UTF_8)); }
@Override public String toString() { try { if (klass != null) { InputStream inputStream = klass.getResourceAsStream(path); if (inputStream == null) { throw new FileNotFoundException("Resource [" + path + "] not found in classpath with class [" + klass.getName() + "]"); } return Streams.copyToString(new InputStreamReader(inputStream, "UTF-8")); } else { return Streams.copyToStringFromClasspath(classLoader, path); } } catch (IOException e) { throw new EsSetupRuntimeException(e); } } }
Map<String, String> loadFromClasspath(String resourceName) throws IOException { InputStream is = this.getClass().getResourceAsStream(resourceName); if (is == null) { throw new FileNotFoundException("Unable to find file " + MESSAGES_FILE); } SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromResource(resourceName); return settingsLoader.load(Streams.copyToString(new InputStreamReader(is, "UTF-8"))); }
/** * Loads settings from a stream that represents them using the * {@link SettingsLoaderFactory#loaderFromResource(String)}. */ public Builder loadFromStream(String resourceName, InputStream is) throws IOException { SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromResource(resourceName); // NOTE: copyToString will close the input stream Map<String, String> loadedSettings = settingsLoader.load(Streams.copyToString(new InputStreamReader(is, StandardCharsets.UTF_8))); put(loadedSettings); return this; }
/** * Loads settings from a stream that represents them using the * {@link SettingsLoaderFactory#loaderFromSource(String)}. */ public Builder loadFromStream(String resourceName, InputStream is) throws SettingsException { SettingsLoader settingsLoader = SettingsLoaderFactory.loaderFromResource(resourceName); try { Map<String, String> loadedSettings = settingsLoader.load(Streams.copyToString(new InputStreamReader(is, Charsets.UTF_8))); put(loadedSettings); } catch (Exception e) { throw new SettingsException("Failed to load settings from [" + resourceName + "]", e); } return this; }
found = true; try { String view = Streams.copyToString(new InputStreamReader(new FileInputStream(file), "UTF-8")); viewEngine.load(viewName, view); } catch (Exception e) {
found = true; try { String view = Streams.copyToString(new InputStreamReader(new FileInputStream(file), "UTF-8")); viewEngine.load(viewName, view); } catch (Exception e) {
return Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)); } else {
return Streams.copyToString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)); } else {
logger.info("compiling script file [{}]", file.toAbsolutePath()); try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8)) { String script = Streams.copyToString(reader); String id = scriptNameExt.v1(); CacheKey cacheKey = new CacheKey(engineService.getType(), id, null);
logger.info("compiling script file [{}]", file.toAbsolutePath()); try(InputStreamReader reader = new InputStreamReader(Files.newInputStream(file), Charsets.UTF_8)) { String script = Streams.copyToString(reader); CacheKey cacheKey = new CacheKey(engineService, scriptNameExt.v1(), null, Collections.<String, String>emptyMap()); staticCache.put(cacheKey, new CompiledScript(ScriptType.FILE, scriptNameExt.v1(), engineService.types()[0], engineService.compile(script, Collections.<String, String>emptyMap())));
Exception failureToResolve = null; try { rules = Streams.copyToString(Files.newBufferedReader(environment.configFile().resolve(rules), Charset.forName("UTF-8"))); } catch (IOException | SecurityException e) { failureToResolve = e;