List of usage examples for com.google.common.io CharSource wrap
public static CharSource wrap(CharSequence charSequence)
From source file:io.takari.maven.plugins.util.PropertiesWriter.java
public static void write(Properties properties, String comment, OutputStream out) throws IOException { StringBuilder sb = new StringBuilder(); properties.store(CharStreams.asWriter(sb), comment); write(CharSource.wrap(sb.toString()), comment, out); }
From source file:org.glowroot.collector.ProfileCharSourceCreator.java
public static @Nullable CharSource createProfileCharSource(@Nullable Profile profile) throws IOException { if (profile == null) { return null; }//from w w w .ja v a2s . co m synchronized (profile.getLock()) { String profileJson = createProfileJson(profile.getSyntheticRootNode()); if (profileJson == null) { return null; } return CharSource.wrap(profileJson); } }
From source file:org.apache.druid.segment.MapVirtualColumnTestBase.java
static IncrementalIndex generateIndex() throws IOException { final CharSource input = CharSource .wrap("2011-01-12T00:00:00.000Z\ta\tkey1,key2,key3\tvalue1,value2,value3\n" + "2011-01-12T00:00:00.000Z\tb\tkey4,key5,key6\tvalue4\n" + "2011-01-12T00:00:00.000Z\tc\tkey1,key5\tvalue1,value5,value9\n"); final StringInputRowParser parser = new StringInputRowParser( new DelimitedParseSpec(new TimestampSpec("ts", "auto", null), new DimensionsSpec(DimensionsSpec.getDefaultSchemas(Arrays.asList("dim", "keys", "values")), null, null), "\t", ",", Arrays.asList("ts", "dim", "keys", "values"), false, 0), "utf8"); final IncrementalIndexSchema schema = new IncrementalIndexSchema.Builder() .withMinTimestamp(DateTimes.of("2011-01-12T00:00:00.000Z").getMillis()).build(); return TestIndex.loadIncrementalIndex( () -> new IncrementalIndex.Builder().setIndexSchema(schema).setMaxRowCount(10000).buildOnheap(), input, parser);//from w w w. j a v a 2s . c om }
From source file:org.glowroot.local.store.TraceTestData.java
static CharSource createEntries() { return CharSource.wrap("[{\"offset\":0,\"duration\":0,\"index\":0," + "\"level\":0,\"message\":{\"text\":\"Level One\"," + "\"detail\":{\"arg1\":\"a\",\"arg2\":\"b\"," + "\"nested1\":{\"nestedkey11\":\"a\",\"nestedkey12\":\"b\"," + "\"subnestedkey1\":{\"subnestedkey1\":\"a\",\"subnestedkey2\":\"b\"}}," + "\"nested2\":{\"nestedkey21\":\"a\",\"nestedkey22\":\"b\"}}}}," + "{\"offset\":0,\"duration\":0,\"index\":1,\"level\":1," + "\"message\":{\"text\":\"Level Two\",\"detail\":{\"arg1\":\"ax\"," + "\"arg2\":\"bx\"}}},{\"offset\":0,\"duration\":0,\"index\":2," + "\"level\":2,\"message\":{\"text\":\"Level Three\"," + "\"detail\":{\"arg1\":\"axy\",\"arg2\":\"bxy\"}}}]"); }
From source file:org.onlab.util.XmlString.java
/** * Prettifies given XML String.// w w w . j a v a2 s . co m * * @param xml input XML * @return prettified input or input itself is input is not well-formed */ public static CharSequence prettifyXml(CharSequence xml) { return new XmlString(CharSource.wrap(xml)); }
From source file:org.onosproject.netconf.NetconfRpcParserUtil.java
/** * Parse first rpc-reply contained in the input. * * @param xml input// w ww . j a va 2 s .c o m * @return {@link NetconfRpcReply} or null on error */ public static NetconfRpcReply parseRpcReply(CharSequence xml) { XMLInputFactory xif = XMLInputFactory.newFactory(); try { XMLStreamReader xsr = xif.createXMLStreamReader(CharSource.wrap(xml).openStream()); return parseRpcReply(xsr); } catch (XMLStreamException | IOException e) { log.error("Exception thrown creating XMLStreamReader", e); return null; } }
From source file:org.apache.isis.applib.fixturescripts.ExecutionParameters.java
static Map<String, String> asKeyValueMap(final String parameters) { final Map<String, String> keyValues = Maps.newLinkedHashMap(); if (parameters != null) { try {//from w ww . j ava 2 s .co m final ImmutableList<String> lines = CharSource.wrap(parameters).readLines(); for (final String line : lines) { if (line == null) { continue; } final Matcher matcher = keyEqualsValuePattern.matcher(line); if (matcher.matches()) { keyValues.put(matcher.group(1).trim(), matcher.group(2).trim()); } } } catch (final IOException e) { // ignore, shouldn't happen } } return keyValues; }
From source file:br.com.objectos.jabuticava.debs.DataParser.java
public LocalDate get() { LocalDate res = null;//from ww w. j a va 2 s .com try { CharSource charSource = CharSource.wrap(text); String line = charSource.readFirstLine(); line = Strings.nullToEmpty(line); Matcher matcher = REGEX.matcher(line); if (matcher.find()) { String data = matcher.group(0); res = new LocalDateCsvConverter("dd/MM/yyyy").convert(data); } } catch (IOException e) { } return res; }
From source file:org.eclipse.che.plugin.docker.client.DockerfileParser.java
/** Parse content of Dockerfile that is represented by String value. */ public static Dockerfile parse(String contentOfDockerFile) throws DockerFileException { try {/* w w w . j av a 2s. c o m*/ return parse(CharStreams.readLines(CharSource.wrap(contentOfDockerFile).openStream())); } catch (IOException e) { throw new DockerFileException("Error happened parsing the Docker file:" + e.getMessage(), e); } }
From source file:org.gradle.integtests.fixtures.executer.OutputScrapingExecutionResult.java
public static String normalize(String output) { StringBuilder result = new StringBuilder(); List<String> lines; try {//from w w w.j a v a 2 s.c o m lines = CharSource.wrap(output).readLines(); } catch (IOException e) { throw new UncheckedIOException(e); } int i = 0; while (i < lines.size()) { String line = lines.get(i); if (line.contains( "Support for running Gradle using Java 6 has been deprecated and will be removed in Gradle 3.0")) { // Assume running build on Java 6, skip over stack trace and ignore i++; while (i < lines.size() && STACK_TRACE_ELEMENT.matcher(lines.get(i)).matches()) { i++; } } else if (line.contains(STARTING_DAEMON_MESSAGE)) { // Assume running using the daemon, ignore i++; } else if (i == lines.size() - 1 && line.matches("Total time: [\\d\\.]+ secs")) { result.append("Total time: 1 secs"); result.append('\n'); i++; } else { result.append(line); result.append('\n'); i++; } } return result.toString(); }