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


Java CharSink类代码示例

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


CharSink类属于com.google.common.io包,在下文中一共展示了CharSink类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: writeCorpusEventFrames

import com.google.common.io.CharSink; //导入依赖的package包/类
@Override
public void writeCorpusEventFrames(final CorpusEventLinking corpusEventLinking,
    final CharSink sink) throws IOException {
  checkArgument(noneEqualForHashable(FluentIterable.from(corpusEventLinking.corpusEventFrames())
      .transform(id())));

  try (Writer writer = sink.openBufferedStream()) {
    for (final CorpusEventFrame corpusEventFrame : BY_ID
        .sortedCopy(corpusEventLinking.corpusEventFrames())) {
      final List<DocEventFrameReference> sortedDocEventFrames =
          DocEventFrameReference.canonicalOrdering()
              .sortedCopy(corpusEventFrame.docEventFrames());
      writer.write(
          corpusEventFrame.id()
              + "\t"
              + FluentIterable.from(sortedDocEventFrames)
              .transform(canonicalStringFunction())
              .join(SPACE_JOINER)
              + "\n");
    }
  }
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:23,代码来源:CorpusEventLinkingIO2016.java

示例4: testGet_io

import com.google.common.io.CharSink; //导入依赖的package包/类
public void testGet_io() throws IOException {
  assertEquals(-1, ArbitraryInstances.get(InputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(ByteArrayInputStream.class).read());
  assertEquals(-1, ArbitraryInstances.get(Readable.class).read(CharBuffer.allocate(1)));
  assertEquals(-1, ArbitraryInstances.get(Reader.class).read());
  assertEquals(-1, ArbitraryInstances.get(StringReader.class).read());
  assertEquals(0, ArbitraryInstances.get(Buffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(CharBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ByteBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(ShortBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(IntBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(LongBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(FloatBuffer.class).capacity());
  assertEquals(0, ArbitraryInstances.get(DoubleBuffer.class).capacity());
  ArbitraryInstances.get(PrintStream.class).println("test");
  ArbitraryInstances.get(PrintWriter.class).println("test");
  assertNotNull(ArbitraryInstances.get(File.class));
  assertFreshInstanceReturned(
      ByteArrayOutputStream.class, OutputStream.class,
      Writer.class, StringWriter.class,
      PrintStream.class, PrintWriter.class);
  assertEquals(ByteSource.empty(), ArbitraryInstances.get(ByteSource.class));
  assertEquals(CharSource.empty(), ArbitraryInstances.get(CharSource.class));
  assertNotNull(ArbitraryInstances.get(ByteSink.class));
  assertNotNull(ArbitraryInstances.get(CharSink.class));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:27,代码来源:ArbitraryInstancesTest.java

示例5: storeProperties

import com.google.common.io.CharSink; //导入依赖的package包/类
/**
 * 
 * @param path
 * @param p
 * @param needEncrypts
 *          암호화 할 키 값 조건
 */
public static void storeProperties(String path, Properties p, Comparable<String> needEncrypts) {

	final EncryptedProperties ep = encryptedProperties(p);

	Iterable<String> lines = Iterables.transform(ep.stringPropertyNames(), k -> {
		String v = ep.getProperty(k);
		if (0 == needEncrypts.compareTo(k))
			v = Secures.encrypts(v);
		return k + "=" + v;
	});

	CharSink sink = Files.asCharSink(Paths.get(path).toFile(), Charsets.UTF_8);
	try {
		sink.writeLines(lines);
	} catch (Exception e) {
		log.error("fail to store properties cause: {}", e.getMessage());
		log.debug("detail cause", e);
	}
}
 
开发者ID:dohbot,项目名称:knives,代码行数:27,代码来源:Configs.java

示例6: whenWriteMultipleLinesUsingCharSink_thenWritten

import com.google.common.io.CharSink; //导入依赖的package包/类
@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());

}
 
开发者ID:wenzhucjy,项目名称:GeneralUtils,代码行数:14,代码来源:GuavaIOTest.java

示例7: 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

示例8: testOverridenLoad

import com.google.common.io.CharSink; //导入依赖的package包/类
@Test
public void testOverridenLoad() throws IOException, InvalidConfigurationException {
    C config = newTestConfig();
    File tempFile = File.createTempFile("config", ".txt");
    URL modifiedURL = Resources.getResource(getClass(), getModifiedResource());
    CharSource in = Resources.asByteSource(modifiedURL).asCharSource(Charsets.UTF_8);
    CharSink out = Files.asCharSink(tempFile, Charsets.UTF_8);
    in.copyTo(out);
    load(config, tempFile, AnnotationConfig.class.getResource(getDefaultResource()));
    assertEquals(112, config.getExample1());
    assertArrayEquals(new String[] {"This is", "stupid test"}, config.getExample2().toArray(new String[config.getExample2().size()]));
    assertEquals("Yr Mum", config.getExample4());
    assertEquals("Is ugly", config.getExample5()); // Overridden but still default
    assertEquals("I'm happy today", config.getExample6()); // Still has default config value, not specified in default config
    assertEquals(Food.TACO, config.getFood());
    assertEquals(TimeUnit.HOURS.toSeconds(30), config.getTime());
}
 
开发者ID:TechzoneMC,项目名称:TechUtils,代码行数:18,代码来源:AnnotationConfigTest.java

示例9: testLoadSaveEquals

import com.google.common.io.CharSink; //导入依赖的package包/类
@Test
public void testLoadSaveEquals() throws IOException, InvalidConfigurationException {
    C config = newTestConfig();
    File tempFile = File.createTempFile("config", ".yml");
    URL modifiedURL = Resources.getResource(getClass(), getModifiedResource());
    URL defaultURL = Resources.getResource(getClass(), getDefaultResource());
    CharSource originalIn = Resources.asByteSource(modifiedURL).asCharSource(Charsets.UTF_8);
    CharSink out = Files.asCharSink(tempFile, Charsets.UTF_8);
    CharSource fileIn = Files.asCharSource(tempFile, Charsets.UTF_8);
    originalIn.copyTo(out);
    load(config, tempFile, defaultURL);
    save(config, tempFile, defaultURL);
    List<String> originalLines = originalIn.readLines();
    originalLines = Lists.transform(originalLines, (s) -> s.replaceAll("\\s", "")); // Strip whitespace
    List<String> fileLines = fileIn.readLines();
    fileLines = Lists.transform(fileLines, (s) -> s.replaceAll("\\s", "")); // Strip whitespace
    assertEquals(originalLines, fileLines);
}
 
开发者ID:TechzoneMC,项目名称:TechUtils,代码行数:19,代码来源:AnnotationConfigTest.java

示例10: 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

示例11: writeLinesFrom

import com.google.common.io.CharSink; //导入依赖的package包/类
private void writeLinesFrom(Iterable<String> services) throws IOException {
  new CharSink() {
    @Override
    public Writer openStream() throws IOException {
      return getFiler()
          .createResource(StandardLocation.CLASS_OUTPUT, key.packageName, key.relativeName)
          .openWriter();
    }
  }.writeLines(services, "\n");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:Output.java

示例12: saveTo

import com.google.common.io.CharSink; //导入依赖的package包/类
public void saveTo(final CorpusQueryAssessments store, final CharSink sink)
    throws IOException {
  final Writer out = sink.openStream();
  for (final QueryResponse2016 q : by2016Ordering().immutableSortedCopy(store.queryReponses())) {
    final Optional<String> metadata = Optional.fromNullable(store.metadata().get(q));
    if (metadata.isPresent()) {
      out.write("#" + metadata.get() + "\n");
    }
    final QueryAssessment2016 assessment =
        Optional.fromNullable(store.assessments().get(q)).or(QueryAssessment2016.UNASSESSED);

    final ImmutableList.Builder<String> pjStrings = ImmutableList.builder();
    for (final CharOffsetSpan pj : Ordering.natural()
        .immutableSortedCopy(q.predicateJustifications())) {
      pjStrings.add(dashJoiner.join(pj.startInclusive(), pj.endInclusive()));
    }
    final String pjString = commaJoiner.join(pjStrings.build());
    final String systemIDs = StringUtils.commaJoiner()
        .join(FluentIterable.from(store.queryResponsesToSystemIDs().get(q))
            .transform(SymbolUtils.desymbolizeFunction()).toSet());

    final String line =
        tabJoiner.join(q.queryID(), q.docID(), systemIDs, pjString, assessment.name());
    out.write(line + "\n");
  }
  out.close();
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:28,代码来源:SingleFileQueryStoreWriter.java

示例13: write

import com.google.common.io.CharSink; //导入依赖的package包/类
@Override
public void write(ResponseLinking responseLinking, CharSink sink) throws IOException {
  final List<String> lines = Lists.newArrayList();
  for (final ResponseSet responseSet : responseLinking.responseSets()) {
    lines.add(renderLine(responseSet, responseLinking));
  }

  // incompletes last
  lines.add("INCOMPLETE\t" + Joiner.on("\t").join(
      transform(responseLinking.incompleteResponses(), ResponseFunctions.uniqueIdentifier())));

  sink.writeLines(lines, "\n");
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:14,代码来源:LinkingStoreSource.java

示例14: 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

示例15: 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


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