当前位置: 首页>>代码示例>>Java>>正文


Java CharSink.write方法代码示例

本文整理汇总了Java中com.google.common.io.CharSink.write方法的典型用法代码示例。如果您正苦于以下问题:Java CharSink.write方法的具体用法?Java CharSink.write怎么用?Java CharSink.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.io.CharSink的用法示例。


在下文中一共展示了CharSink.write方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import com.google.common.io.CharSink; //导入方法依赖的package包/类
@Deprecated
public void save() {
  String stats = collect();
  String filename = AppConfig.outputDir + "/" + map.getSimpleFileName() + ".csv";

  // if file exists, remove it
  (new File(filename)).delete();

  CharSink sink = Files.asCharSink(new File(filename), Charsets.UTF_8);
  try {
    sink.write(stats);
  } catch (IOException e) {
    e.printStackTrace();
  }

  logger.info("Exported statistics to: {}", filename);
}
 
开发者ID:sinaa,项目名称:train-simulator,代码行数:18,代码来源:StatisticsController.java

示例2: writeQueries

import com.google.common.io.CharSink; //导入方法依赖的package包/类
@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());
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:18,代码来源:DefaultCorpusQueryWriter.java

示例3: finish

import com.google.common.io.CharSink; //导入方法依赖的package包/类
@Override
public void finish() throws IOException {
  final CharSink textSink = Files.asCharSink(new File(outputDir, outputName + FILE_SUFFIX),
      Charsets.UTF_8);
  final ByteSink jsonSink = Files.asByteSink(new File(outputDir, outputName + FILE_SUFFIX + ".json"));

  final SummaryConfusionMatrix summaryConfusionMatrix = summaryConfusionMatrixB.build();
  // Output the summaries and add a final newline
  final FMeasureCounts fMeasure =
      SummaryConfusionMatrices.FMeasureVsAllOthers(summaryConfusionMatrix, PRESENT);
  textSink.write(StringUtils.NewlineJoiner.join(
      SummaryConfusionMatrices.prettyPrint(summaryConfusionMatrix),
      fMeasure.compactPrettyString(),
      ""));  // Empty string creates a bare newline at the end
  JacksonSerializer.builder().forJson().prettyOutput().build().serializeTo(fMeasure, jsonSink);

  // Call finish on the observers
  for (final ScoringEventObserver observer : scoringEventObservers) {
    observer.finish(outputDir);
  }
}
 
开发者ID:BBN-E,项目名称:bue-common-open,代码行数:22,代码来源:AggregateBinaryFScoresInspector.java

示例4: writeSeedScript

import com.google.common.io.CharSink; //导入方法依赖的package包/类
public void writeSeedScript(final File scriptPath) {
  final CharSource script = Resources.asCharSource(getClass().getResource("seedScript"), Charsets.UTF_8);
  final CharSink charSink = Files.asCharSink(scriptPath, Charsets.UTF_8);
  try {
    final StringBuilder scriptBuilder = new StringBuilder();
    scriptBuilder.append(script.read());
    for(final User user : users) {
      final StringBuilder line = new StringBuilder();
      line.append("add_user('");
      line.append(user.username);
      line.append("', '");
      line.append(user.password);
      line.append("', '");
      line.append(user.apiKey);
      line.append("')\n");
      scriptBuilder.append(line);
      
      logger.debug("Adding user: " + line);
    }
    charSink.write(scriptBuilder);
  } catch(final IOException ioException) {
    throw new RuntimeException(ioException);
  }
}
 
开发者ID:jmchilton,项目名称:galaxy-bootstrap,代码行数:25,代码来源:GalaxyData.java

示例5: logCoverage

import com.google.common.io.CharSink; //导入方法依赖的package包/类
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);
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:13,代码来源:KBPAssessmentDiff.java

示例6: formatSource

import com.google.common.io.CharSink; //导入方法依赖的package包/类
/**
 * 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()));
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:12,代码来源:Formatter.java

示例7: writeFile

import com.google.common.io.CharSink; //导入方法依赖的package包/类
public static void writeFile(String fileName, String message){
    try {
        CharSink charSink = Files.asCharSink(new File(fileName), Charsets.UTF_8, FileWriteMode.APPEND);
        charSink.write(message + "\n");
    }catch(Exception e){

    }
}
 
开发者ID:deanjin,项目名称:houseHunter,代码行数:9,代码来源:FileOP.java

示例8: whenWriteUsingCharSink_thenWritten

import com.google.common.io.CharSink; //导入方法依赖的package包/类
@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);
}
 
开发者ID:wenzhucjy,项目名称:GeneralUtils,代码行数:12,代码来源:GuavaIOTest.java

示例9: formatSource

import com.google.common.io.CharSink; //导入方法依赖的package包/类
/**
 * 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()));
}
 
开发者ID:google,项目名称:google-java-format,代码行数:12,代码来源:Formatter.java

示例10: trueMain

import com.google.common.io.CharSink; //导入方法依赖的package包/类
private static void trueMain(final String[] args) throws IOException {
  final Parameters input = Parameters.loadSerifStyle(new File(args[0]));
  final String resolved = input.dump();
  final CharSink output = Files.asCharSink(new File(args[1]), Charsets.UTF_8,
      FileWriteMode.APPEND);
  output.write(resolved);
}
 
开发者ID:BBN-E,项目名称:bue-common-open,代码行数:8,代码来源:ExpandParameters.java

示例11: logDocIdsWithUndeterminedGenre

import com.google.common.io.CharSink; //导入方法依赖的package包/类
public void logDocIdsWithUndeterminedGenre(CharSink sink) throws IOException {
  sink.write(Joiner.on("\n").join(docIdsWithUndeterminedGenre.build()));
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:4,代码来源:GenreExtractor.java

示例12: genDML

import com.google.common.io.CharSink; //导入方法依赖的package包/类
static void genDML(SchemaExporter generator, TableMetadata table, File file) throws IOException, ExecutionException, InterruptedException {
    String   tableName    = Utils.escapeReservedWord(table.getName());
    String   keyspaceName = table.getKeyspace().getName();
    CharSink charSink     = Files.asCharSink(file, Charset.defaultCharset(), FileWriteMode.APPEND);

    System.out.printf("-----------------------------------------------" + Main.LINE_SEPARATOR);
    System.out.printf("Extract from %s.%s" + Main.LINE_SEPARATOR, keyspaceName, tableName);

    if (generator.truncate) {
        charSink.write(QueryBuilder.truncate(keyspaceName, tableName).getQueryString());
    }

    Row firstRow = getFirstRow(generator.session, tableName, keyspaceName);

    if (firstRow == null) {
        return;
    }

    final List<String>                 colNames    = new ArrayList();
    final List<TypeCodec>              typeCodecs  = new ArrayList();
    List<ColumnDefinitions.Definition> definitions = firstRow.getColumnDefinitions().asList();

    for (ColumnDefinitions.Definition definition : definitions) {
        String   colName = definition.getName();
        DataType type    = definition.getType();
        colNames.add(Utils.escapeReservedWord(colName));
        Object object = firstRow.getObject(colName);
        typeCodecs.add(object != null ? CODEC_REGISTRY.codecFor(type, object) : CODEC_REGISTRY
                .codecFor(type));
    }

    String prefix = "INSERT INTO " + keyspaceName + "." + tableName + " (" + Joiner.on(',')
                                                                                   .join(colNames) + ") VALUES (";
    String postfix = generator.merge ? ") IF NOT EXISTS;" : ");";

    long totalNoOfRows = getTotalNoOfRows(generator.session, tableName, keyspaceName);
    System.out.printf("Total number of record: %s" + Main.LINE_SEPARATOR, totalNoOfRows);

    int count = 0;
    Select select = QueryBuilder.select()
                                .all()
                                .from(keyspaceName, tableName).allowFiltering();
    select.setFetchSize(SchemaExporter.FETCH_SIZE);
    ResultSet     resultSet = generator.session.execute(select);
    Iterator<Row> iterator  = resultSet.iterator();

    System.out.printf("Start write \"%s\" data DML to %s" + Main.LINE_SEPARATOR, tableName, file.getCanonicalPath());

    int  noOfStep  = getNoOfStep(totalNoOfRows);
    long step      = totalNoOfRows / noOfStep;
    int  stepCount = 0;

    while (iterator.hasNext()) {
        Row    next      = iterator.next();
        String statement = generateInsertFromRow(typeCodecs, prefix, postfix, next) + Main.LINE_SEPARATOR;
        charSink.write(statement);
        count++;
        if (totalNoOfRows > SchemaExporter.FETCH_SIZE && count > stepCount * step) {
            float v = (float) count / (float) totalNoOfRows * 100;
            System.out.printf("Done %.2f%%" + Main.LINE_SEPARATOR, v);
            stepCount++;
        }
    }
    System.out.printf("Done exporting \"%s\", total number of records exported: %s" + Main.LINE_SEPARATOR, tableName, count);
}
 
开发者ID:thangbn,项目名称:cassandra-CQL-exporter,代码行数:66,代码来源:TableExporter.java

示例13: onNonComplyingFile

import com.google.common.io.CharSink; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:coveo,项目名称:fmt-maven-plugin,代码行数:12,代码来源:FMT.java


注:本文中的com.google.common.io.CharSink.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。