@Override public CharSource createSource(String data) throws IOException { return CharSource.wrap(data); }
private static CharSource newNormalCharSource() { return CharSource.wrap("ABC"); }
/** Returns a copy of code as a list of lines. */ public List<String> getLines() { try { return CharSource.wrap(sourceBuilder).readLines(); } catch (IOException e) { throw new AssertionError("IOException not possible, as the string is in-memory"); } }
private boolean shouldShutdown(final String message) { try { return shutdownKey.equals(wrap(message).readFirstLine()); } catch (IOException e) { throw new MocoException(e); } } }
@Override public void close() throws IOException { try { formatter.formatSource( CharSource.wrap(stringBuilder), new CharSink() { @Override public Writer openStream() throws IOException { return fileObject.openWriter(); } }); } catch (FormatterException e) { // An exception will happen when the code being formatted has an error. It's better to // log the exception and emit unformatted code so the developer can view the code which // caused a problem. try (Writer writer = fileObject.openWriter()) { writer.append(stringBuilder.toString()); } if (messager != null) { messager.printMessage(Diagnostic.Kind.NOTE, "Error formatting " + getName()); } } } };
public void testConcat_infiniteIterable() throws IOException { CharSource source = CharSource.wrap("abcd"); Iterable<CharSource> cycle = Iterables.cycle(ImmutableList.of(source)); CharSource concatenated = CharSource.concat(cycle); String expected = "abcdabcd"; // read the first 8 chars manually, since there's no equivalent to ByteSource.slice // TODO(cgdecker): Add CharSource.slice? StringBuilder builder = new StringBuilder(); Reader reader = concatenated.openStream(); // no need to worry about closing for (int i = 0; i < 8; i++) { builder.append((char) reader.read()); } assertEquals(expected, builder.toString()); }
@Benchmark public InputStream apacheReaderInputStream() throws IOException { return new ReaderInputStream(CharSource.wrap(test1).openStream()); }
@Benchmark public InputStream apacheReaderInputStream() throws IOException { return new ReaderInputStream(CharSource.wrap(test1).openStream()); }
} else { logWriter.write("cannot find proper data from 'resource'.. regarding it as data string"); source = CharSource.wrap(resource);
public void testConcat() throws IOException { CharSource c1 = CharSource.wrap("abc"); CharSource c2 = CharSource.wrap(""); CharSource c3 = CharSource.wrap("de"); String expected = "abcde"; assertEquals(expected, CharSource.concat(ImmutableList.of(c1, c2, c3)).read()); assertEquals(expected, CharSource.concat(c1, c2, c3).read()); assertEquals(expected, CharSource.concat(ImmutableList.of(c1, c2, c3).iterator()).read()); assertFalse(CharSource.concat(c1, c2, c3).isEmpty()); CharSource emptyConcat = CharSource.concat(CharSource.empty(), CharSource.empty()); assertTrue(emptyConcat.isEmpty()); }
final List<Diagnostic<? extends JavaFileObject>> diagnostics = getDiagnostics(); final LineNumberReader reader = new LineNumberReader(CharSource.wrap(source.getCharContent(false)).openStream()); do { String line = reader.readLine();
@BeforeClass public static void setup() throws IOException { CharSource v_0112 = CharSource.wrap(StringUtils.join(V_0112, "\n")); CharSource v_0113 = CharSource.wrap(StringUtils.join(V_0113, "\n")); IncrementalIndex index0 = TestIndex.loadIncrementalIndex(newIndex("2011-01-12T00:00:00.000Z"), v_0112); IncrementalIndex index1 = TestIndex.loadIncrementalIndex(newIndex("2011-01-13T00:00:00.000Z"), v_0113); segment0 = new IncrementalIndexSegment(index0, makeIdentifier(index0, "v1")); segment1 = new IncrementalIndexSegment(index1, makeIdentifier(index1, "v1")); }
/** * Set a string from which to read entities. */ public void setSource(CharSequence text) { source = CharSource.wrap(text); sourceURL = null; }
private QueryRunner getCustomRunner() throws IOException { CharSource v_0112 = CharSource.wrap(StringUtils.join(V_0112, "\n")); CharSource v_0113 = CharSource.wrap(StringUtils.join(V_0113, "\n")); IncrementalIndex index0 = TestIndex.loadIncrementalIndex(newIndex("2011-01-12T00:00:00.000Z"), v_0112); IncrementalIndex index1 = TestIndex.loadIncrementalIndex(newIndex("2011-01-14T00:00:00.000Z"), v_0113); segment0 = new IncrementalIndexSegment(index0, makeIdentifier(index0, "v1")); segment1 = new IncrementalIndexSegment(index1, makeIdentifier(index1, "v1")); VersionedIntervalTimeline<String, Segment> timeline = new VersionedIntervalTimeline<>(StringComparators.LEXICOGRAPHIC); timeline.add(index0.getInterval(), "v1", new SingleElementPartitionChunk<>(segment0)); timeline.add(index1.getInterval(), "v1", new SingleElementPartitionChunk<>(segment1)); return QueryRunnerTestHelper.makeFilteringQueryRunner(timeline, factory); }
@BeforeClass public static void setup() throws IOException { CharSource v_0112 = CharSource.wrap(StringUtils.join(V_0112, "\n")); CharSource v_0113 = CharSource.wrap(StringUtils.join(V_0113, "\n")); CharSource v_override = CharSource.wrap(StringUtils.join(V_OVERRIDE, "\n")); IncrementalIndex index0 = TestIndex.loadIncrementalIndex(newIndex("2011-01-12T00:00:00.000Z"), v_0112); IncrementalIndex index1 = TestIndex.loadIncrementalIndex(newIndex("2011-01-13T00:00:00.000Z"), v_0113); IncrementalIndex index2 = TestIndex.loadIncrementalIndex(newIndex("2011-01-12T04:00:00.000Z"), v_override); segment0 = new IncrementalIndexSegment(index0, makeIdentifier(index0, "v1")); segment1 = new IncrementalIndexSegment(index1, makeIdentifier(index1, "v1")); segment_override = new IncrementalIndexSegment(index2, makeIdentifier(index2, "v2")); VersionedIntervalTimeline<String, Segment> timeline = new VersionedIntervalTimeline<>(StringComparators.LEXICOGRAPHIC); timeline.add(index0.getInterval(), "v1", new SingleElementPartitionChunk<>(segment0)); timeline.add(index1.getInterval(), "v1", new SingleElementPartitionChunk<>(segment1)); timeline.add(index2.getInterval(), "v2", new SingleElementPartitionChunk<>(segment_override)); segmentIdentifiers = new ArrayList<>(); for (TimelineObjectHolder<String, ?> holder : timeline.lookup(Intervals.of("2011-01-12/2011-01-14"))) { segmentIdentifiers.add(makeIdentifier(holder.getInterval(), holder.getVersion()).toString()); } runner = QueryRunnerTestHelper.makeFilteringQueryRunner(timeline, factory); }
configs[2].setSearchStrategy(AutoStrategy.NAME); CharSource input = CharSource.wrap( "2011-01-12T00:00:00.000Z\tspot\tAutoMotive\t1000\t10000.0\t10000.0\t100000\tPREFERRED\ta\u0001preferred\t100.000000\n" + "2011-01-12T00:00:00.000Z\tSPot\tbusiness\t1100\t11000.0\t11000.0\t110000\tpreferred\tb\u0001Preferred\t100.000000\n" +
Reader sanitizedReader = CharSource.wrap(decoder.decode(responseBuffer)).openStream(); final MesosFileChunkObject initialChunk = objectMapper.readValue(sanitizedReader, MesosFileChunkObject.class);
private static void storeCacheVersionsFile(String json, File cacheFile) { //noinspection ResultOfMethodCallIgnored cacheFile.getParentFile().mkdirs(); try { CharSource.wrap(json).copyTo(Files.asCharSink(cacheFile, Charsets.UTF_8)); } catch (IOException e) { LOG.error("Cannot write Gradle version information cache file.", e); // do not throw an exception if cache file cannot be written to be more robust against file system problems } }
public void test_of_escaping() { PropertiesFile test = PropertiesFile.of(CharSource.wrap(FILE3)); Multimap<String, String> keyValues1 = ImmutableListMultimap.of("a=d=", "x"); assertEquals(test.getProperties(), PropertySet.of(keyValues1)); }