/** * Write an array of strings. * * @param value provides the strings to write. */ public void writeStringArray(List<String> value) throws IOException { writeStartArray(); for (String s : value) { writeString(s); } writeEndArray(); }
/** * Encode the members of an {@link UnionDataSchema}. * * @param unionDataSchema The union schema whose members needs to be encoded. * @throws IOException if there is an error while encoding. */ protected void encodeUnion(UnionDataSchema unionDataSchema) throws IOException { List<UnionDataSchema.Member> members = unionDataSchema.getMembers(); _builder.writeStartArray(); for (UnionDataSchema.Member member: members) { encodeUnionMember(member); } _builder.writeEndArray(); }
private void writeIncludes(RecordDataSchema recordDataSchema) throws IOException { _builder.writeFieldName(INCLUDE_KEY); _builder.writeStartArray(); for (NamedDataSchema includedSchema : recordDataSchema.getInclude()) { encode(includedSchema); } _builder.writeEndArray(); }
public File writeFile(File outdirFile, String fileName) throws IOException { fileName += RestConstants.SNAPSHOT_FILENAME_EXTENTION; final File file = new File(outdirFile, fileName); FileOutputStream fileOutputStream = new FileOutputStream(file); JsonBuilder jsonBuilder = new JsonBuilder(JsonBuilder.Pretty.INDENTED); SchemaToJsonEncoder encoder = new SchemaToJsonEncoder(jsonBuilder); jsonBuilder.writeStartObject(); jsonBuilder.writeFieldName(Snapshot.MODELS_KEY); jsonBuilder.writeStartArray(); List<NamedDataSchema> models = generateModelList(); models.sort(Comparator.comparing(NamedDataSchema::getFullName)); for(DataSchema model : models){ encoder.encode(model); } jsonBuilder.writeEndArray(); jsonBuilder.writeFieldName(Snapshot.SCHEMA_KEY); jsonBuilder.writeDataTemplate(_topLevelSchema, true); jsonBuilder.writeEndObject(); try { fileOutputStream.write(jsonBuilder.result().getBytes()); } finally { fileOutputStream.close(); jsonBuilder.close(); } return file; }
/** * Encode a the fields of a {@link RecordDataSchema}. * * This method does not output a key. The key should be emitted before calling this method. * If {@link #isEncodeInclude()} returns true, then only fields that are defined in the record being * encoded will be encoded, else all fields including those from included records will be encoded. * * @param recordDataSchema the {@link RecordDataSchema} being encoded. * @throws IOException if there is an error while encoding. */ protected void encodeFields(RecordDataSchema recordDataSchema) throws IOException { Collection<RecordDataSchema.Field> fields = recordDataSchema.getFields(); _builder.writeStartArray(); boolean encodeInclude = isEncodeInclude(); for (RecordDataSchema.Field field : fields) { if (encodeInclude == false || recordDataSchema == field.getRecord()) { encodeField(field); } } _builder.writeEndArray(); }