return copyReaderToBuilder((Reader) from, (StringBuilder) to); } else { return copyReaderToWriter((Reader) from, asWriter(to));
public void testAsWriter() { // Should wrap Appendable in a new object Appendable plainAppendable = new StringBuilder(); Writer result = CharStreams.asWriter(plainAppendable); assertNotSame(plainAppendable, result); assertNotNull(result); // A Writer should not be wrapped Appendable secretlyAWriter = new StringWriter(); result = CharStreams.asWriter(secretlyAWriter); assertSame(secretlyAWriter, result); }
return copyReaderToBuilder((Reader) from, (StringBuilder) to); } else { return copyReaderToWriter((Reader) from, asWriter(to));
return copyReaderToBuilder((Reader) from, (StringBuilder) to); } else { return copyReaderToWriter((Reader) from, asWriter(to));
public String toJson() throws IOException { StringBuilder sb = new StringBuilder(); JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb)); writeJson(jg); jg.close(); return sb.toString(); }
public String toFlameGraphJson() throws IOException { StringBuilder sb = new StringBuilder(); JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb)); try { jg.writeStartObject(); jg.writeNumberField("totalSampleCount", getSampleCount()); jg.writeArrayFieldStart("rootNodes"); int height = 0; for (ProfileNode rootNode : rootNodes) { if (rootNode.sampleCount > rootNode.ellipsedSampleCount) { FlameGraphWriter flameGraphWriter = new FlameGraphWriter(rootNode, jg); flameGraphWriter.traverse(); height = Math.max(height, flameGraphWriter.height); } } jg.writeEndArray(); jg.writeNumberField("height", height); jg.writeEndObject(); } finally { jg.close(); } return sb.toString(); }
private static String writeConfigAsString(ObjectNode rootObjectNode, List<String> keyOrder) throws IOException { ObjectNode orderedRootObjectNode = getOrderedObjectNode(rootObjectNode, keyOrder); ObjectMappers.stripEmptyContainerNodes(orderedRootObjectNode); StringBuilder sb = new StringBuilder(); JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb)); try { jg.setPrettyPrinter(ObjectMappers.getPrettyPrinter()); jg.writeTree(orderedRootObjectNode); } finally { jg.close(); } // newline is not required, just a personal preference return sb.toString() + ObjectMappers.NEWLINE; }
public static String writeValue(List<PluginDescriptor> pluginDescriptors) throws IOException { ObjectMapper mapper = ObjectMappers.create(); StringBuilder sb = new StringBuilder(); JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb)); try { jg.setPrettyPrinter(ObjectMappers.getPrettyPrinter()); jg.writeStartArray(); for (PluginDescriptor pluginDescriptor : pluginDescriptors) { ObjectNode objectNode = mapper.valueToTree(pluginDescriptor); ObjectMappers.stripEmptyContainerNodes(objectNode); jg.writeTree(objectNode); } jg.writeEndArray(); } finally { jg.close(); } // newline is not required, just a personal preference sb.append(ObjectMappers.NEWLINE); return sb.toString(); } }
@Override public Writer openStream() throws IOException { return asWriter(supplier.getOutput()); }
@Override public void appendTo(Appendable buf) throws IOException { // Use a writer so the re can be correctly converted to json using DeltaJson. Writer out = CharStreams.asWriter(buf); out.write("like("); DeltaJson.write(out, _condition); out.write(")"); }
@Override public Writer openStream() throws IOException { return asWriter(supplier.getOutput()); } };
@Override public Writer openStream() throws IOException { return asWriter(supplier.getOutput()); }
@Override public Writer openStream() throws IOException { return asWriter(supplier.getOutput()); }
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); }
@Override public void appendTo(Appendable buf) throws IOException { // Use a writer so the value can be correctly converted to json using DeltaJson. Writer out = CharStreams.asWriter(buf); out.write(_comparison.getDeltaFunction()); out.write("("); DeltaJson.write(out, _value); out.write(")"); }
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); }
@Override public void appendTo(Appendable buf) throws IOException { buf.append("{.."); Writer writer = CharStreams.asWriter(buf); for (Map.Entry<String, Condition> entry : OrderedJson.ENTRY_COMPARATOR.immutableSortedCopy(_entries.entrySet())) { buf.append(','); DeltaJson.write(writer, entry.getKey()); buf.append(':'); entry.getValue().appendTo(buf); } buf.append('}'); }
@Override public void appendTo(Appendable buf) throws IOException { buf.append("intrinsic("); Writer out = CharStreams.asWriter(buf); DeltaJson.write(out, _name); buf.append(':'); appendSubCondition(buf, _condition); buf.append(')'); }
@Override public void appendTo(Appendable buf) throws IOException { // nested content is sorted so toString() is deterministic. this is valuable in tests and for // comparing hashes of deltas for equality. DeltaJson.write(CharStreams.asWriter(buf), OrderedJson.ordered(_value)); }
public void testAsWriter() { // Should wrap Appendable in a new object Appendable plainAppendable = new StringBuilder(); Writer result = CharStreams.asWriter(plainAppendable); assertNotSame(plainAppendable, result); assertNotNull(result); // A Writer should not be wrapped Appendable secretlyAWriter = new StringWriter(); result = CharStreams.asWriter(secretlyAWriter); assertSame(secretlyAWriter, result); }