0

I have this method that creates a JSON tree from a directory recieved by parameters:

 public static void generateReport(File dir, JSONArray content) throws IOException, ParseException {
        File listFile[] = dir.listFiles();
        String md5;
        if (listFile != null && listFile.length > 0) {
            for (int i = 0; i < listFile.length; i++) {
                JSONObject obj = new JSONObject();
                content.add(obj);
                if (listFile[i].isDirectory()) {
                    md5 = md5OfString(listFile[i].getAbsolutePath());
                    obj.put("md5", md5);
                    obj.put("type", "folder");
                    obj.put("path", listFile[i].getAbsolutePath());
                    JSONArray contentSon = new JSONArray();
                    obj.put("Content", contentSon);
                    generateReport(listFile[i], contentSon);
                    //numDir++;
                } else if (listFile[i].isFile()) {
                    md5 = md5OfFile(listFile[i]);
                    obj.put("md5", md5);
                    obj.put("type", "file");
                    obj.put("path", listFile[i].getAbsolutePath());
                    //numFiles++;
                }
            }
        }
    }

If I call this method twice it will create two diferent JSON's from two diferent directories! What I need to do is to compare those two JSON's and get a new JSON with the diferences between those two.

Example of diff JSON:

{
    "root": "/u/data/Coldview/apps",
    "origin-report": "informe.json",
    "diff": [
        {
            "type": "folder",
            "path": "ldf.web.ejecuciondeprotestos",
            "origin-md5": ".........",
            "destination-md5": "........."
        },
        {
            "type": "folder",
            "path": "ldf.web.ejecuciondeprotestos/lib",
            "origin-md5": ".........",
            "destination-md5": "........."
        },
        {
            "type": "file", 
            "name": "AMCOX.Core.jar", 
            "origin-md5": ".........",
            "destination-md5": "........."
        }
    ]
}

I'm using JAVA 7 and the json-simple library to deal with the JSON's but there's nothing to do what I need.

import org.json.simple.JSONArray;
import org.json.simple.Jr.JSONParser;
import org.json.simple.parser.ParseException;SONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

0 Answers0