@VisibleForTesting static void buildValue(StringBuilder builder, ValueObject value) { ValueObject.TYPE type = value.getObjectType(); if (type == ValueObject.TYPE.CUSTOM) { value = value.asCustom().asSimple(); type = value.getObjectType(); } switch (type) { case INT: case FLOAT: builder.append(value.toString()); break; case STRING: builder.append("\""); builder.append(quoteString(value.toString())); builder.append("\""); break; default: break; } }
public static void buildRow(Bundle row, String delimiter, StringBuilder stringBuilder) { int count = 0; for (BundleField field : row.getFormat()) { ValueObject o = row.getValue(field); if (count++ > 0) { stringBuilder.append(delimiter); } if (o != null) { ValueObject.TYPE type = o.getObjectType(); if (type == ValueObject.TYPE.CUSTOM) { o = o.asCustom().asSimple(); type = o.getObjectType(); } switch (type) { case INT: case FLOAT: stringBuilder.append(o.toString()); break; case STRING: stringBuilder.append("\""); stringBuilder.append(o.toString().replace('"', '\'').replace('\n', ' ').replace('\r', ' ')); stringBuilder.append("\""); break; default: break; } } } stringBuilder.append("\n"); }
@Override protected void appendInitialBundleToString(Bundle firstRow, StringBuilder sendBuffer) { sendBuffer.append('['); int count = 0; for (BundleField field : firstRow.getFormat()) { ValueObject o = firstRow.getValue(field); if (count++ > 0) { sendBuffer.append(','); } if (o == null) { continue; } if (o.getObjectType() == ValueObject.TYPE.CUSTOM) { o = o.asCustom().asSimple(); } try { // TODO: no worse than the preivous version, but should still be able to avoid the string alloc. String encodedCopy = Jackson.defaultMapper().writeValueAsString(o.asNative()); sendBuffer.append(encodedCopy); } catch (JsonProcessingException e) { throw new UncheckedIOException(e); } } sendBuffer.append(']'); }