com.google.common.io.Files#asCharSink ( )源码实例Demo

下面列出了com.google.common.io.Files#asCharSink ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: google-ads-java   文件: MethodsListGenerator.java
public static void main(String args[])
    throws ClassNotFoundException, IOException, NoSuchMethodException {
  Method latestVersionMethod = GoogleAdsAllVersions.class.getMethod("getLatestVersion");
  Class cls = Class.forName(latestVersionMethod.getReturnType().getName());
  List<Method> methods = Arrays.asList(cls.getDeclaredMethods());

  StringBuilder output = new StringBuilder();
  for (Method method : methods) {
    output.append(method + "\n");
  }

  System.out.println("Writing the following methods to file:");
  System.out.printf(output.toString());

  File file = new File("./google-ads/src/test/resources/testdata/avail_service_clients.txt");
  CharSink sink = Files.asCharSink(file, Charsets.UTF_8);
  sink.write(output);
}
 
源代码2 项目: qmq   文件: BatchFileAppender.java
BatchFileAppender(final File file, final int capacity) {
    this.sink = Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND);
    this.pendingWrite = new ArrayBlockingQueue<>(capacity);
    this.batchWriteThread = new Thread(new Runnable() {
        @Override
        public void run() {
            batchWriteLoop();
        }
    });
    this.stop = false;
    this.batchWriteThread.start();
}
 
源代码3 项目: j2cl   文件: BazelJ2clRta.java
private static void writeToFile(String filePath, List<String> lines) {
  CharSink outputSink = Files.asCharSink(new File(filePath), StandardCharsets.UTF_8);
  try {
    outputSink.writeLines(lines);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
源代码4 项目: ipmi4j   文件: IpmiCommandNameTest.java
private void process(Context context, String templateName, String targetPath) throws IOException {
    URL templateUrl = Resources.getResource(IpmiCommandNameTest.class, templateName);
    CharSource source = Resources.asCharSource(templateUrl, StandardCharsets.UTF_8);

    File file = new File(targetPath);
    CharSink sink = Files.asCharSink(file, StandardCharsets.UTF_8);

    try (Reader r = source.openBufferedStream()) {
        try (Writer w = sink.openBufferedStream()) {
            engine.evaluate(context, w, file.getName(), r);
        }
    }
}
 
源代码5 项目: tutorials   文件: GuavaIOUnitTest.java
@Test
public void whenWriteUsingCharSink_thenWritten() throws IOException {
    final String expectedValue = "Hello world";
    final File file = new File("src/test/resources/test.out");
    final CharSink sink = Files.asCharSink(file, Charsets.UTF_8);

    sink.write(expectedValue);

    final String result = Files.toString(file, Charsets.UTF_8);
    assertEquals(expectedValue, result);
}
 
源代码6 项目: tutorials   文件: GuavaIOUnitTest.java
@Test
public void whenWriteMultipleLinesUsingCharSink_thenWritten() throws IOException {
    final List<String> names = Lists.newArrayList("John", "Jane", "Adam", "Tom");
    final File file = new File("src/test/resources/test.out");
    final CharSink sink = Files.asCharSink(file, Charsets.UTF_8);

    sink.writeLines(names, " ");

    final String result = Files.toString(file, Charsets.UTF_8);
    final String expectedValue = Joiner.on(" ").join(names);
    assertEquals(expectedValue, result.trim());

}
 
源代码7 项目: codehelper.generator   文件: IOUtils.java
public static  void writeLines(String fileName,List<String> list,Charset charset) throws IOException {
    CharSink cs = Files.asCharSink(new File(fileName), charset);
    list = PojoUtil.avoidEmptyList(list);
    cs.writeLines(list);
}
 
源代码8 项目: codehelper.generator   文件: IOUtils.java
public static  void writeLines(File file,List<String> list,Charset charset) throws IOException {
    CharSink cs = Files.asCharSink(file, charset);
    list = PojoUtil.avoidEmptyList(list);
    cs.writeLines(list);
}
 
源代码9 项目: fmt-maven-plugin   文件: FMT.java
/**
 * Hook called when the processd file is not compliant with the formatter.
 *
 * @param file the file that is not compliant
 * @param formatted the corresponding formatted of the file.
 */
@Override
protected void onNonComplyingFile(File file, String formatted) throws IOException {
  CharSink sink = Files.asCharSink(file, Charsets.UTF_8);
  sink.write(formatted);
}