/** Print text to the output stream. */ @Override public void print(final CharSequence text) throws IOException { final int size = text.length(); int pos = 0; for (int i = 0; i < size; i++) { if (text.charAt(i) == '\n') { write(text.subSequence(pos, i + 1)); pos = i + 1; atStartOfLine = true; } } write(text.subSequence(pos, size)); }
PrinterImpl( TypeRegistry registry, boolean alwaysOutputDefaultValueFields, Set<FieldDescriptor> includingDefaultValueFields, boolean preservingProtoFieldNames, Appendable jsonOutput, boolean omittingInsignificantWhitespace, boolean printingEnumsAsInts) { this.registry = registry; this.alwaysOutputDefaultValueFields = alwaysOutputDefaultValueFields; this.includingDefaultValueFields = includingDefaultValueFields; this.preservingProtoFieldNames = preservingProtoFieldNames; this.printingEnumsAsInts = printingEnumsAsInts; this.gson = GsonHolder.DEFAULT_GSON; // json format related properties, determined by printerType if (omittingInsignificantWhitespace) { this.generator = new CompactTextGenerator(jsonOutput); this.blankOrSpace = ""; this.blankOrNewLine = ""; } else { this.generator = new PrettyTextGenerator(jsonOutput); this.blankOrSpace = " "; this.blankOrNewLine = "\n"; } }