try {
FileOutputStream out = new FileOutputStream(file);
// First construct an index that allows us to quickly find the partitions that we want
JSONStringer stringer = (JSONStringer)(new JSONStringer().object());
int offset = 1;
for (Integer partition : sorted) {
stringer.key(partition.toString()).value(offset++);
} // FOR
out.write((stringer.endObject().toString() + "\n").getBytes());
// Now Loop through each file individually so that we only have to load one into memory at a time
for (Integer partition : sorted) {
File in = markovs.get(partition);
try {
JSONObject json_object = new JSONObject(FileUtil.readFile(in));
MarkovGraphsContainer markov = MarkovGraphsContainerUtil.createMarkovGraphsContainer(json_object, procedures, catalog_db);
markov.load(in, catalog_db);
stringer = (JSONStringer)new JSONStringer().object();
stringer.key(partition.toString()).object();
markov.toJSON(stringer);
stringer.endObject().endObject();
out.write((stringer.toString() + "\n").getBytes());
} catch (Exception ex) {
throw new Exception(String.format("Failed to copy MarkovGraphsContainer for partition %d from '%s'", partition, in), ex);
}
} // FOR
out.close();