* Try and parse the contents as a JSON object. If it succeeds then assume
* it is a the new version of the digest file. It is unlikely the old version
* will successfully parse as JSON because it starts with a number
* instead of an open brace.
*/
JSONObject obj = null;
try {
obj = new JSONObject(caw.toString());
} catch (JSONException e) {
//assume it is the old format
}
/*
* Convert the old style file to a JSONObject so it can be presented
* via a consistent interface.
*/
if (obj == null) {
String tableList = caw.toString();
byte tableListBytes[] = tableList.getBytes("UTF-8");
PureJavaCrc32 tableListCRC = new PureJavaCrc32();
tableListCRC.update(tableListBytes);
tableListCRC.update("\n".getBytes("UTF-8"));
final int calculatedValue = (int)tableListCRC.getValue();
if (crc != calculatedValue) {
logger.warn("CRC of snapshot digest " + f + " did not match digest contents");
return null;
}
String tableNames[] = tableList.split(",");
long txnId = Long.valueOf(tableNames[0]);
obj = new JSONObject();
try {
obj.put("version", 0);
obj.put("txnId", txnId);
for (int ii = 1; ii < tableNames.length; ii++) {
obj.append("tables", tableNames[ii]);
}
} catch (JSONException e) {
logger.warn("Exception parsing JSON of digest " + f, e);
return null;
}