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();
for(DataSchema model : models){
encoder.encode(model);
}
jsonBuilder.writeEndArray();
jsonBuilder.writeFieldName(Snapshot.SCHEMA_KEY);
jsonBuilder.writeStartObject();
jsonBuilder.writeProperties(_topLevelSchema.data());
jsonBuilder.writeEndObject();
jsonBuilder.writeEndObject();
try
{
fileOutputStream.write(jsonBuilder.result().getBytes());
}
finally
{
fileOutputStream.close();
jsonBuilder.close();
}
return file;
}