use of com.google.common.io.CharSink in project druid by druid-io.
the class JSONFlatDataParserTest method setUp.
@Before
public void setUp() throws Exception {
tmpFile = temporaryFolder.newFile("lookup.json");
final CharSink sink = Files.asByteSink(tmpFile).asCharSink(Charsets.UTF_8);
sink.writeLines(Iterables.transform(MAPPINGS, new Function<Map<String, Object>, CharSequence>() {
@Override
public CharSequence apply(Map<String, Object> input) {
try {
return MAPPER.writeValueAsString(input);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
}));
}
use of com.google.common.io.CharSink in project randomizedtesting by randomizedtesting.
the class TextReport method setOuter.
/**
* Initialization by container task {@link JUnit4}.
*/
@Override
@SuppressForbidden("legitimate sysstreams.")
public void setOuter(JUnit4 task) {
this.seed = task.getSeed();
if (outputFile != null) {
try {
Files.createParentDirs(outputFile);
final CharSink charSink;
if (append) {
charSink = Files.asCharSink(outputFile, Charsets.UTF_8, FileWriteMode.APPEND);
} else {
charSink = Files.asCharSink(outputFile, Charsets.UTF_8);
}
this.output = charSink.openBufferedStream();
} catch (IOException e) {
throw new BuildException(e);
}
} else {
if (!UNICODE_ENCODINGS.contains(Charset.defaultCharset().name())) {
task.log("Your default console's encoding may not display certain" + " unicode glyphs: " + Charset.defaultCharset().name(), Project.MSG_INFO);
}
output = new LineFlushingWriter(new OutputStreamWriter(System.out, Charset.defaultCharset())) {
@Override
public // Don't close the underlying stream, just flush.
void close() throws IOException {
flush();
}
};
}
}
Aggregations