List of usage examples for com.google.common.io Resources asCharSource
public static CharSource asCharSource(URL url, Charset charset)
From source file:com.spotify.helios.testing.TemporaryJobBuilder.java
private boolean imageInfoFromImageNameFile() { final URL resource = loadFile("docker/image-name"); if (resource == null) { return false; }/*from w w w . jav a 2 s .c o m*/ try { final String imageName = Resources.asCharSource(resource, UTF_8).read().trim(); image(imageName); return true; } catch (IOException e) { throw new AssertionError("Failed to load image info", e); } }
From source file:org.nmdp.ngs.sra.SraReader.java
/** * Read a study from the specified URL.//from w ww . j av a 2 s. c o m * * @param url URL, must not be null * @return a study read from the specified URL * @throws IOException if an I/O error occurs */ public static Study readStudy(final URL url) throws IOException { checkNotNull(url); try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) { return readStudy(reader); } }
From source file:org.nmdp.ngs.sra.SraReader.java
/** * Read a submission from the specified URL. * * @param url URL, must not be null// w ww.j av a 2 s. c o m * @return a submission read from the specified URL * @throws IOException if an I/O error occurs */ public static Submission readSubmission(final URL url) throws IOException { checkNotNull(url); try (BufferedReader reader = Resources.asCharSource(url, Charsets.UTF_8).openBufferedStream()) { return readSubmission(reader); } }
From source file:com.alibaba.dubbo.common.extension.ExtensionLoader.java
private void loadFile(Map<String, Class<?>> extensionClasses, String dir) { String fileName = dir + type.getName(); try {/*ww w . ja va 2 s . c o m*/ Enumeration<java.net.URL> urls; ClassLoader classLoader = findClassLoader(); if (classLoader != null) { urls = classLoader.getResources(fileName); } else { urls = ClassLoader.getSystemResources(fileName); } if (urls == null) { return; } while (urls.hasMoreElements()) { java.net.URL url = urls.nextElement(); ImmutableList<String> lines = Resources.asCharSource(url, Charset.forName("utf-8")).readLines(); for (String line : lines) { processLine(extensionClasses, classLoader, url, line); } } // end of while urls } catch (Throwable t) { logger.error("Exception when load extension class(interface: " + type + ", description file: " + fileName + ").", t); } }
From source file:com.ning.billing.recurly.RecurlyClient.java
private String buildUserAgent() { final String defaultVersion = "0.0.0"; final String defaultJavaVersion = "0.0.0"; try {//from w w w .ja v a 2 s .c o m final Properties gitRepositoryState = new Properties(); final URL resourceURL = Resources.getResource(GIT_PROPERTIES_FILE); final CharSource charSource = Resources.asCharSource(resourceURL, Charset.forName("UTF-8")); Reader reader = null; try { reader = charSource.openStream(); gitRepositoryState.load(reader); } finally { if (reader != null) { reader.close(); } } final String version = MoreObjects.firstNonNull(getVersionFromGitRepositoryState(gitRepositoryState), defaultVersion); final String javaVersion = MoreObjects.firstNonNull(StandardSystemProperty.JAVA_VERSION.value(), defaultJavaVersion); return String.format("KillBill/%s; %s", version, javaVersion); } catch (final Exception e) { return String.format("KillBill/%s; %s", defaultVersion, defaultJavaVersion); } }