com.google.common.io.CharSink#write ( )源码实例Demo

下面列出了com.google.common.io.CharSink#write ( ) 实例代码,或者点击链接到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 项目: tac-kbp-eal   文件: DefaultCorpusQueryWriter.java
@Override
public void writeQueries(final CorpusQuerySet2016 queries,
    final CharSink sink) throws IOException {
  final StringBuilder sb = new StringBuilder();

  int numEntryPoints = 0;
  for (final CorpusQuery2016 query : QUERY_ORDERING.sortedCopy(queries)) {
    for (final CorpusQueryEntryPoint entryPoint : ENTRY_POINT_ORDERING
        .sortedCopy(query.entryPoints())) {
      sb.append(entryPointString(query, entryPoint)).append("\n");
      ++numEntryPoints;
    }
  }
  log.info("Writing {} queries with {} entry points to {}", queries.queries().size(),
      numEntryPoints, sink);
  sink.write(sb.toString());
}
 
源代码3 项目: tutorials   文件: JavaXToWriterUnitTest.java
@Test
public void givenUsingGuava_whenConvertingByteArrayIntoWriter_thenCorrect() throws IOException {
    final byte[] initialArray = "With Guava".getBytes();

    final String buffer = new String(initialArray);
    final StringWriter stringWriter = new StringWriter();
    final CharSink charSink = new CharSink() {
        @Override
        public final Writer openStream() throws IOException {
            return stringWriter;
        }
    };
    charSink.write(buffer);

    stringWriter.close();

    assertEquals("With Guava", stringWriter.toString());
}
 
源代码4 项目: java-n-IDE-for-Android   文件: Formatter.java
/**
 * Format the given input (a Java compilation unit) into the output stream.
 *
 * @throws FormatterException if the input cannot be parsed
 */
public void formatSource(CharSource input, CharSink output)
        throws FormatterException, IOException {
    // TODO(cushon): proper support for streaming input/output. Input may
    // not be feasible (parsing) but output should be easier.
    output.write(formatSource(input.read()));
}
 
源代码5 项目: javaide   文件: Formatter.java
/**
 * Format the given input (a Java compilation unit) into the output stream.
 *
 * @throws FormatterException if the input cannot be parsed
 */
public void formatSource(CharSource input, CharSink output)
        throws FormatterException, IOException {
    // TODO(cushon): proper support for streaming input/output. Input may
    // not be feasible (parsing) but output should be easier.
    output.write(formatSource(input.read()));
}
 
源代码6 项目: google-java-format   文件: Formatter.java
/**
 * Format the given input (a Java compilation unit) into the output stream.
 *
 * @throws FormatterException if the input cannot be parsed
 */
public void formatSource(CharSource input, CharSink output)
    throws FormatterException, IOException {
  // TODO(cushon): proper support for streaming input/output. Input may
  // not be feasible (parsing) but output should be easier.
  output.write(formatSource(input.read()));
}
 
源代码7 项目: tac-kbp-eal   文件: KBPAssessmentDiff.java
private static void logCoverage(String leftName, Set<Symbol> leftDocIds, String rightName,
    Set<Symbol> rightDocIds,
    CharSink out) throws IOException {
  final String msg = String.format(
      "%d documents in %s; %d in %s. %d in common, %d left-only, %d right-only",
      leftDocIds.size(), leftName, rightDocIds.size(), rightName,
      Sets.intersection(leftDocIds, rightDocIds).size(),
      Sets.difference(leftDocIds, rightDocIds).size(),
      Sets.difference(rightDocIds, leftDocIds).size());
  log.info(msg);
  out.write(msg);
}
 
源代码8 项目: 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);
}
 
源代码9 项目: tutorials   文件: AppendToFileManualTest.java
@Test
public void whenAppendToFileUsingGuava_thenCorrect() throws IOException {
    File file = new File(fileName);
    CharSink chs = com.google.common.io.Files.asCharSink(file, Charsets.UTF_8, FileWriteMode.APPEND);
    chs.write("Spain\r\n");

    assertThat(StreamUtils.getStringFromInputStream(new FileInputStream(fileName))).isEqualTo("UK\r\n" + "US\r\n" + "Germany\r\n" + "Spain\r\n");
}
 
源代码10 项目: 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);
}
 
 同类方法