com.google.common.io.Resources.newReaderSupplier()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(98)

本文整理了Java中com.google.common.io.Resources.newReaderSupplier方法的一些代码示例,展示了Resources.newReaderSupplier的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Resources.newReaderSupplier方法的具体详情如下:
包路径:com.google.common.io.Resources
类名称:Resources
方法名:newReaderSupplier

Resources.newReaderSupplier介绍

[英]Returns a factory that will supply instances of InputStreamReader that read a URL using the given character set.
[中]返回一个工厂,该工厂将提供使用给定字符集读取URL的InputStreamReader实例。

代码示例

代码示例来源:origin: apache/mahout

@Test
public void incompleteBeta() throws IOException {
 Splitter onComma = Splitter.on(",").trimResults();
 InputSupplier<InputStreamReader> input =
   Resources.newReaderSupplier(Resources.getResource("beta-test-data.csv"), Charsets.UTF_8);
 boolean header = true;
 for (String line : CharStreams.readLines(input)) {
  if (header) {
   // skip
   header = false;
  } else {
   Iterable<String> values = onComma.split(line);
   double alpha = Double.parseDouble(Iterables.get(values, 0));
   double beta = Double.parseDouble(Iterables.get(values, 1));
   double x = Double.parseDouble(Iterables.get(values, 2));
   double ref = Double.parseDouble(Iterables.get(values, 3));
   double actual = Gamma.incompleteBeta(alpha, beta, x);
   assertEquals(alpha + "," + beta + ',' + x, ref, actual, ref * 1.0e-5);
  }
 }
}

代码示例来源:origin: apache/mahout

@Test
public void testDistributionFunctions() throws Exception {
 InputSupplier<InputStreamReader> input =
   Resources.newReaderSupplier(Resources.getResource("negative-binomial-test-data.csv"), Charsets.UTF_8);
 boolean header = true;
 for (String line : CharStreams.readLines(input)) {
  if (header) {
   // skip
   header = false;
  } else {
   Iterable<String> values = onComma.split(line);
   int k = Integer.parseInt(Iterables.get(values, 0));
   double p = Double.parseDouble(Iterables.get(values, 1));
   int r = Integer.parseInt(Iterables.get(values, 2));
   double density = Double.parseDouble(Iterables.get(values, 3));
   double cume = Double.parseDouble(Iterables.get(values, 4));
   NegativeBinomial nb = new NegativeBinomial(r, p, RandomUtils.getRandom());
   assertEquals("cumulative " + k + ',' + p + ',' + r, cume, nb.cdf(k), cume * 1.0e-5);
   assertEquals("density " + k + ',' + p + ',' + r, density, nb.pdf(k), density * 1.0e-5);
  }
 }
}

代码示例来源:origin: com.google.guava/guava-io

/**
 * Reads all characters from a URL into a {@link String}, using the given
 * character set.
 *
 * @param url the URL to read from
 * @param charset the character set used when reading the URL
 * @return a string containing all the characters from the URL
 * @throws IOException if an I/O error occurs.
 */
public static String toString(URL url, Charset charset) throws IOException {
 return CharStreams.toString(newReaderSupplier(url, charset));
}

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * Reads all characters from a URL into a {@link String}, using the given
 * character set.
 *
 * @param url the URL to read from
 * @param charset the character set used when reading the URL
 * @return a string containing all the characters from the URL
 * @throws IOException if an I/O error occurs.
 */
public static String toString(URL url, Charset charset) throws IOException {
 return CharStreams.toString(newReaderSupplier(url, charset));
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/**
 * Reads all characters from a URL into a {@link String}, using the given
 * character set.
 *
 * @param url the URL to read from
 * @param charset the character set used when reading the URL
 * @return a string containing all the characters from the URL
 * @throws IOException if an I/O error occurs.
 */
public static String toString(URL url, Charset charset) throws IOException {
 return CharStreams.toString(newReaderSupplier(url, charset));
}

代码示例来源:origin: org.codehaus.sonar.sslr-squid-bridge/sslr-squid-bridge

private InputStreamReader reader(String resourcePath) {
 URL url = Resources.getResource(SqaleXmlLoader.class, resourcePath);
 try {
  return Resources.newReaderSupplier(url, Charsets.UTF_8).getInput();
 } catch (IOException e) {
  throw new IllegalArgumentException("Could not read " + resourcePath, e);
 }
}

代码示例来源:origin: jvelo/mayocat-shop

private static Reader getResourceReader(String resource) throws IOException
  {
    return Resources.newReaderSupplier(Resources.getResource(resource), Charsets.UTF_8).getInput();
  }
}

代码示例来源:origin: org.apache.isis.viewer/isis-viewer-restfulobjects-server

private static String versionFromManifest() {
  try {
    URL resource = Resources.getResource(META_INF_POM_PROPERTIES);
    Properties p = new Properties();
    p.load(Resources.newReaderSupplier(resource, Charset.defaultCharset()).getInput());
    return p.getProperty("version");
  } catch (final Exception ex) {
    return "UNKNOWN";
  }
}

代码示例来源:origin: jvelo/mayocat-shop

private static Reader getResourceReader(String resource) throws IOException
  {
    return Resources.newReaderSupplier(Resources.getResource(resource), Charsets.UTF_8).getInput();
  }
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

/**
 * Streams lines from a URL, stopping when our callback returns false, or we
 * have read all of the lines.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link
 *     Charsets} for helpful predefined constants
 * @param callback the LineProcessor to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
public static <T> T readLines(URL url, Charset charset,
  LineProcessor<T> callback) throws IOException {
 return CharStreams.readLines(newReaderSupplier(url, charset), callback);
}

代码示例来源:origin: io.core9/closure-templates

/**
 * Creates a new {@code SoyFileSupplier} given a resource {@code URL}, as well as the desired
 * file path for messages.
 *
 * @param inputFileUrl The URL of the Soy file.
 * @param soyFileKind The kind of this input Soy file.
 * @param filePath The path to the Soy file (used for messages only).
 */
public static SoyFileSupplier create(
  URL inputFileUrl, SoyFileKind soyFileKind, String filePath) {
 return create(
   Resources.newReaderSupplier(inputFileUrl, Charsets.UTF_8), soyFileKind, filePath);
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/**
 * Streams lines from a URL, stopping when our callback returns false, or we
 * have read all of the lines.
 *
 * @param url the URL to read from
 * @param charset the character set used when reading the URL
 * @param callback the LineProcessor to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
public static <T> T readLines(URL url, Charset charset,
  LineProcessor<T> callback) throws IOException {
 return CharStreams.readLines(newReaderSupplier(url, charset), callback);
}

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * Reads all of the lines from a URL. The lines do not include
 * line-termination characters, but do include other leading and trailing
 * whitespace.
 *
 * @param url the URL to read from
 * @param charset the character set used when writing the file
 * @return a mutable {@link List} containing all the lines
 * @throws IOException if an I/O error occurs
 */
public static List<String> readLines(URL url, Charset charset)
  throws IOException {
 return CharStreams.readLines(newReaderSupplier(url, charset));
}

代码示例来源:origin: com.google.guava/guava-io

/**
 * Streams lines from a URL, stopping when our callback returns false, or we
 * have read all of the lines.
 *
 * @param url the URL to read from
 * @param charset the character set used when reading the URL
 * @param callback the LineProcessor to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
public static <T> T readLines(URL url, Charset charset,
  LineProcessor<T> callback) throws IOException {
 return CharStreams.readLines(newReaderSupplier(url, charset), callback);
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/**
 * Reads all of the lines from a URL. The lines do not include
 * line-termination characters, but do include other leading and trailing
 * whitespace.
 *
 * @param url the URL to read from
 * @param charset the character set used when writing the file
 * @return a mutable {@link List} containing all the lines
 * @throws IOException if an I/O error occurs
 */
public static List<String> readLines(URL url, Charset charset)
  throws IOException {
 return CharStreams.readLines(newReaderSupplier(url, charset));
}

代码示例来源:origin: com.google.guava/guava-jdk5

/**
 * Streams lines from a URL, stopping when our callback returns false, or we
 * have read all of the lines.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link
 *     Charsets} for helpful predefined constants
 * @param callback the LineProcessor to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
public static <T> T readLines(URL url, Charset charset,
  LineProcessor<T> callback) throws IOException {
 return CharStreams.readLines(newReaderSupplier(url, charset), callback);
}

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * Streams lines from a URL, stopping when our callback returns false, or we
 * have read all of the lines.
 *
 * @param url the URL to read from
 * @param charset the character set used when reading the URL
 * @param callback the LineProcessor to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
public static <T> T readLines(URL url, Charset charset,
  LineProcessor<T> callback) throws IOException {
 return CharStreams.readLines(newReaderSupplier(url, charset), callback);
}

代码示例来源:origin: com.google.guava/guava-io

/**
 * Reads all of the lines from a URL. The lines do not include
 * line-termination characters, but do include other leading and trailing
 * whitespace.
 *
 * @param url the URL to read from
 * @param charset the character set used when writing the file
 * @return a mutable {@link List} containing all the lines
 * @throws IOException if an I/O error occurs
 */
public static List<String> readLines(URL url, Charset charset)
  throws IOException {
 return CharStreams.readLines(newReaderSupplier(url, charset));
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.guava

/**
 * Streams lines from a URL, stopping when our callback returns false, or we
 * have read all of the lines.
 *
 * @param url the URL to read from
 * @param charset the charset used to decode the input stream; see {@link
 *     Charsets} for helpful predefined constants
 * @param callback the LineProcessor to use to handle the lines
 * @return the output of processing the lines
 * @throws IOException if an I/O error occurs
 */
public static <T> T readLines(URL url, Charset charset,
  LineProcessor<T> callback) throws IOException {
 return CharStreams.readLines(newReaderSupplier(url, charset), callback);
}

代码示例来源:origin: Noahs-ARK/semafor

/**
 * Initialize a new WordNetRelations with the default file_properties and stopwords files
 */
public WordNetRelations() throws URISyntaxException {
  final ClassLoader classLoader = getClass().getClassLoader();
  final InputStream filePropertiesFile = classLoader.getResourceAsStream(DEFAULT_FILE_PROPERTIES_FILE);
  final InputSupplier<InputStreamReader> stopwordsFile =
      Resources.newReaderSupplier(classLoader.getResource(DEFAULT_STOPWORDS_FILE), Charsets.UTF_8);
  try {
    stopwords = ImmutableSet.copyOf(CharStreams.readLines(stopwordsFile));
    mWN = WordNetAPI.getInstance(filePropertiesFile);
  } catch (Exception e) { throw new RuntimeException(e); }
}

相关文章