Search in sources :

Example 1 with CharSink

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);
            }
        }
    }));
}
Also used : Function(com.google.common.base.Function) CharSink(com.google.common.io.CharSink) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before)

Example 2 with CharSink

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();
            }
        };
    }
}
Also used : CharSink(com.google.common.io.CharSink) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) SuppressForbidden(com.carrotsearch.randomizedtesting.annotations.SuppressForbidden)

Aggregations

CharSink (com.google.common.io.CharSink)2 SuppressForbidden (com.carrotsearch.randomizedtesting.annotations.SuppressForbidden)1 Function (com.google.common.base.Function)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BuildException (org.apache.tools.ant.BuildException)1 Before (org.junit.Before)1 ExpectedException (org.junit.rules.ExpectedException)1