本文整理汇总了Java中com.google.common.io.CharSink.writeLines方法的典型用法代码示例。如果您正苦于以下问题:Java CharSink.writeLines方法的具体用法?Java CharSink.writeLines怎么用?Java CharSink.writeLines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.CharSink
的用法示例。
在下文中一共展示了CharSink.writeLines方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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());
}
示例3: 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");
}
示例4: writeEDLMentions
import com.google.common.io.CharSink; //导入方法依赖的package包/类
/**
* Writes out the specified {@link EDLMention}s. If a {@link #defaultKbId} was not specified,
* an exception will be thrown if any EDL mentions have an absent KB ID.
*/
public void writeEDLMentions(Iterable<EDLMention> edlMentions, CharSink sink) throws IOException {
final List<String> lines = Lists.newArrayList();
for (final EDLMention edlMention : edlMentions) {
lines.add(toLine(edlMention));
}
sink.writeLines(lines, "\n");
}
示例5: writeLines
import com.google.common.io.CharSink; //导入方法依赖的package包/类
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);
}
示例6: writeUnixLines
import com.google.common.io.CharSink; //导入方法依赖的package包/类
/**
* Generally we want to avoid {@link CharSink#writeLines(Iterable)} because it uses the OS default
* line separator, but our code always works with Unix line endings regardless of platform. This
* is just like {@link CharSink#writeLines(Iterable)}, but always uses Unix endings.
*/
public static void writeUnixLines(Iterable<? extends CharSequence> lines, CharSink sink)
throws IOException {
sink.writeLines(lines, "\n");
}