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

x33g5p2x  于2022-01-18 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(107)

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

Files.newReaderSupplier介绍

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

代码示例

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

/**
 * Copies all characters from a file to an appendable object,
 * using the given character set.
 *
 * @param from the source file
 * @param charset the character set used when reading the file
 * @param to the appendable object
 * @throws IOException if an I/O error occurs
 */
public static void copy(File from, Charset charset, Appendable to)
  throws IOException {
 CharStreams.copy(newReaderSupplier(from, charset), to);
}

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

/**
 * Creates a new {@code SoyFileSupplier} given a {@code File}.
 *
 * @param inputFile The Soy file.
 * @param soyFileKind The kind of this input Soy file.
 */
public static SoyFileSupplier create(File inputFile, SoyFileKind soyFileKind) {
 return create(
   Files.newReaderSupplier(inputFile, Charsets.UTF_8), soyFileKind, inputFile.getPath());
}

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

/**
 * Reads all of the lines from a file. The lines do not include
 * line-termination characters, but do include other leading and
 * trailing whitespace.
 *
 * @param file the file 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(File file, Charset charset)
  throws IOException {
 return CharStreams.readLines(Files.newReaderSupplier(file, charset));
}

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

/**
 * Copies all characters from a file to a {@link Appendable} &
 * {@link Closeable} object supplied by a factory, using the given
 * character set.
 *
 * @param from the source file
 * @param charset the character set used when reading the file
 * @param to the appendable supplier
 * @throws IOException if an I/O error occurs
 */
public static <W extends Appendable & Closeable> void copy(File from,
  Charset charset, OutputSupplier<W> to) throws IOException {
 CharStreams.copy(newReaderSupplier(from, charset), to);
}

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

/**
 * Copies all characters from a file to a {@link Appendable} &
 * {@link Closeable} object supplied by a factory, using the given
 * character set.
 *
 * @param from the source file
 * @param charset the character set used when reading the file
 * @param to the appendable supplier
 * @throws IOException if an I/O error occurs
 */
public static <W extends Appendable & Closeable> void copy(File from,
  Charset charset, OutputSupplier<W> to) throws IOException {
 CharStreams.copy(newReaderSupplier(from, charset), to);
}

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

/**
 * Reads all of the lines from a file. The lines do not include
 * line-termination characters, but do include other leading and
 * trailing whitespace.
 *
 * @param file the file 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(File file, Charset charset)
  throws IOException {
 return CharStreams.readLines(Files.newReaderSupplier(file, charset));
}

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

/**
 * Copies all characters from a file to a {@link Appendable} &
 * {@link Closeable} object supplied by a factory, using the given
 * character set.
 *
 * @param from the source file
 * @param charset the character set used when reading the file
 * @param to the appendable supplier
 * @throws IOException if an I/O error occurs
 */
public static <W extends Appendable & Closeable> void copy(File from,
  Charset charset, OutputSupplier<W> to) throws IOException {
 CharStreams.copy(newReaderSupplier(from, charset), to);
}

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

/**
 * Reads the first line from a file. The line does not include
 * line-termination characters, but does include other leading and
 * trailing whitespace.
 *
 * @param file the file to read from
 * @param charset the character set used when writing the file
 * @return the first line, or null if the file is empty
 * @throws IOException if an I/O error occurs
 */
public static String readFirstLine(File file, Charset charset)
  throws IOException {
 return CharStreams.readFirstLine(Files.newReaderSupplier(file, charset));
}

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

/**
 * Copies all characters from a file to an appendable object,
 * using the given character set.
 *
 * @param from the source file
 * @param charset the character set used when reading the file
 * @param to the appendable object
 * @throws IOException if an I/O error occurs
 */
public static void copy(File from, Charset charset, Appendable to)
  throws IOException {
 CharStreams.copy(newReaderSupplier(from, charset), to);
}

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

/**
 * Streams lines from a {@link File}, stopping when our callback returns
 * false, or we have read all of the lines.
 *
 * @param file the file to read from
 * @param charset the charset used to decode the input stream; see {@link
 *     Charsets} for helpful predefined constants
 * @param callback the {@link 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(File file, Charset charset,
  LineProcessor<T> callback) throws IOException {
 return CharStreams.readLines(newReaderSupplier(file, charset), callback);
}

代码示例来源:origin: org.hudsonci.lib.guava/guava

/**
 * Reads all of the lines from a file. The lines do not include
 * line-termination characters, but do include other leading and
 * trailing whitespace.
 *
 * @param file the file to read from
 * @param charset the charset used to decode the input stream; see {@link
 *     Charsets} for helpful predefined constants
 * @return a mutable {@link List} containing all the lines
 * @throws IOException if an I/O error occurs
 */
public static List<String> readLines(File file, Charset charset)
  throws IOException {
 return CharStreams.readLines(Files.newReaderSupplier(file, charset));
}

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

/**
 * Copies all characters from a file to an appendable object,
 * using the given character set.
 *
 * @param from the source file
 * @param charset the character set used when reading the file
 * @param to the appendable object
 * @throws IOException if an I/O error occurs
 */
public static void copy(File from, Charset charset, Appendable to)
  throws IOException {
 CharStreams.copy(newReaderSupplier(from, charset), to);
}

代码示例来源:origin: org.apache.twill/twill-yarn

private static Arguments decodeArgs() throws IOException {
 return ArgumentsCodec.decode(
  Files.newReaderSupplier(new File(Constants.Files.RUNTIME_CONFIG_JAR, Constants.Files.ARGUMENTS), Charsets.UTF_8));
}

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

/**
 * Streams lines from a {@link File}, stopping when our callback returns
 * false, or we have read all of the lines.
 *
 * @param file the file to read from
 * @param charset the character set used when writing the file
 * @param callback the {@link 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(File file, Charset charset,
  LineProcessor<T> callback) throws IOException {
 return CharStreams.readLines(Files.newReaderSupplier(file, charset),
   callback);
}

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

private static Arguments decodeArgs() throws IOException {
 return ArgumentsCodec.decode(
  Files.newReaderSupplier(new File(Constants.Files.RUNTIME_CONFIG_JAR, Constants.Files.ARGUMENTS), Charsets.UTF_8));
}

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

public static int countLines(String filename) throws IOException {
  return countLines(Files.newReaderSupplier(new File(filename), Charsets.UTF_8));
}

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

/**
 * Reads the first line from a file. The line does not include
 * line-termination characters, but does include other leading and
 * trailing whitespace.
 *
 * @param file the file to read from
 * @param charset the character set used when writing the file
 * @return the first line, or null if the file is empty
 * @throws IOException if an I/O error occurs
 */
public static String readFirstLine(File file, Charset charset)
  throws IOException {
 return CharStreams.readFirstLine(Files.newReaderSupplier(file, charset));
}

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

/**
 * Reads all of the lines from a file. The lines do not include
 * line-termination characters, but do include other leading and
 * trailing whitespace.
 *
 * @param file the file 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(File file, Charset charset)
  throws IOException {
 return CharStreams.readLines(Files.newReaderSupplier(file, charset));
}

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

/**
 * Reads the first line from a file. The line does not include
 * line-termination characters, but does include other leading and
 * trailing whitespace.
 *
 * @param file the file to read from
 * @param charset the character set used when writing the file
 * @return the first line, or null if the file is empty
 * @throws IOException if an I/O error occurs
 */
public static String readFirstLine(File file, Charset charset)
  throws IOException {
 return CharStreams.readFirstLine(Files.newReaderSupplier(file, charset));
}

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

public WordNetRelations(String stopWordFile, String configFile) {
  try {
    final InputSupplier<InputStreamReader> stopwordSupplier =
        Files.newReaderSupplier(new File(stopWordFile), Charsets.UTF_8);
    stopwords = ImmutableSet.copyOf(CharStreams.readLines(stopwordSupplier));
    mWN = WordNetAPI.getInstance(new FileInputStream(configFile));
  } catch (Exception e) { throw new RuntimeException(e); }
}

相关文章