Ignore:
Timestamp:
2015-05-31T17:30:53+02:00 (9 years ago)
Author:
nokutu
Message:

Change from org.json to javax.json

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySequenceDownloadThread.java

    r31158 r31165  
    66import java.io.InputStreamReader;
    77
    8 import org.json.JSONException;
    9 import org.json.JSONObject;
    10 import org.json.JSONArray;
     8import javax.json.JsonArray;
     9import javax.json.JsonObject;
     10import javax.json.Json;
    1111
    1212import java.util.ArrayList;
     
    4646                        br = new BufferedReader(new InputStreamReader(
    4747                                        new URL(url).openStream()));
    48                         String jsonLine = "";
    49                         while (br.ready()) {
    50                                 jsonLine += br.readLine();
    51                         }
    52                         JSONObject jsonall = new JSONObject(jsonLine);
     48                        /*
     49                         * String jsonLine = ""; while (br.ready()) { jsonLine +=
     50                         * br.readLine(); }
     51                         */
     52                        JsonObject jsonall = Json.createReader(br).readObject();
    5353
    5454                        if (!jsonall.getBoolean("more") && !ex.isShutdown()) {
    5555                                ex.shutdownNow();
    5656                        }
    57                         JSONArray jsonseq = jsonall.getJSONArray("ss");
    58                         for (int i = 0; i < jsonseq.length(); i++) {
    59                                 JSONObject jsonobj = jsonseq.getJSONObject(i);
    60                                 JSONArray cas = jsonobj.getJSONArray("cas");
    61                                 JSONArray coords = jsonobj.getJSONArray("coords");
    62                                 JSONArray keys = jsonobj.getJSONArray("keys");
     57                        JsonArray jsonseq = jsonall.getJsonArray("ss");
     58                        for (int i = 0; i < jsonseq.size(); i++) {
     59                                JsonObject jsonobj = jsonseq.getJsonObject(i);
     60                                JsonArray cas = jsonobj.getJsonArray("cas");
     61                                JsonArray coords = jsonobj.getJsonArray("coords");
     62                                JsonArray keys = jsonobj.getJsonArray("keys");
    6363                                ArrayList<MapillaryImage> images = new ArrayList<>();
    64                                 for (int j = 0; j < cas.length(); j++) {
     64                                for (int j = 0; j < cas.size(); j++) {
    6565                                        try {
    66                                                 images.add(new MapillaryImage(keys.getString(j), coords
    67                                                                 .getJSONArray(j).getDouble(1), coords
    68                                                                 .getJSONArray(j).getDouble(0), cas.getDouble(j)));
     66                                                images.add(new MapillaryImage(keys.getString(j),
     67                                                                coords.getJsonArray(j).getJsonNumber(1)
     68                                                                                .doubleValue(), coords.getJsonArray(j)
     69                                                                                .getJsonNumber(0).doubleValue(), cas
     70                                                                                .getJsonNumber(j).doubleValue()));
    6971                                        } catch (Exception e) {
    7072                                                // Mapillary service bug here
    71                                                 //System.out.println(cas.length());
    72                                                 //System.out.println(coords.length());
    73                                                 //System.out.println(keys.length());
     73                                                // System.out.println(cas.length());
     74                                                // System.out.println(coords.length());
     75                                                // System.out.println(keys.length());
    7476                                                System.out.println(e);
    7577                                        }
     
    7981                                int last = -1;
    8082                                int pos = 0;
    81                                
     83
    8284                                // Here it gets only those images which are in the downloaded
    8385                                // area.
     
    104106                                sequence.add(finalImages);
    105107                        }
    106                 } catch (IOException | JSONException e) {
     108                } catch (IOException e) {
    107109                        return;
    108110                }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadManagerThread.java

    r31158 r31165  
    22
    33import java.util.concurrent.ThreadPoolExecutor;
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    54import java.util.concurrent.TimeUnit;
    65import java.util.concurrent.ArrayBlockingQueue;
     
    3433
    3534        public void run() {
    36                 /*
    37                  * ThreadPoolExecutor ex = new ThreadPoolExecutor(30, 35, 25,
    38                  * TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(20));
    39                  * ArrayList<JSONArray> ret = new ArrayList<JSONArray>(); int page = 0;
    40                  * while (!ex.isShutdown()) { ex.execute(new
    41                  * MapillarySquareDownloadThread(ex, this.data, urlImages + "&page=" +
    42                  * page + "&limit=25")); try { if (ex.getQueue().peek() != null)
    43                  * Thread.sleep(1000); } catch(Exception e){ System.out.println(e); }
    44                  * page++; }
    45                  */
    46                 System.out.println(tr("INFORMATION: GET") + urlSequences);
    4735                fullfillSequences();
    4836                return;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/downloads/MapillarySquareDownloadThread.java

    r31158 r31165  
    55import java.io.InputStreamReader;
    66
    7 import org.json.JSONObject;
    8 import org.json.JSONArray;
     7import javax.json.JsonArray;
     8import javax.json.JsonObject;
     9import javax.json.Json;
    910
    1011import java.util.ArrayList;
     
    3132                        br = new BufferedReader(new InputStreamReader(
    3233                                        new URL(url).openStream()));
    33                         String jsonLine = "";
     34                        /*String jsonLine = "";
    3435                        while (br.ready()) {
    3536                                jsonLine += br.readLine();
    36                         }
    37                         JSONObject jsonobj = new JSONObject(jsonLine);
     37                        }*/
     38                        JsonObject jsonobj = Json.createReader(br).readObject();
    3839                        if (!jsonobj.getBoolean("more")) {
    3940                                ex.shutdownNow();
    4041                        }
    41                         JSONArray jsonarr = jsonobj.getJSONArray("ims");
     42                        JsonArray jsonarr = jsonobj.getJsonArray("ims");
    4243                        ArrayList<MapillaryImage> images = new ArrayList<>();
    43                         JSONObject image;
    44                         for (int i = 0; i < jsonarr.length(); i++) {
     44                        JsonObject image;
     45                        for (int i = 0; i < jsonarr.size(); i++) {
    4546                                try {
    46                                         image = jsonarr.getJSONObject(i);
     47                                        image = jsonarr.getJsonObject(i);
    4748                                        images.add(new MapillaryImage(image.getString("key"), image
    48                                                         .getDouble("lat"), image.getDouble("lon"), image
    49                                                         .getDouble("ca")));
     49                                                        .getJsonNumber("lat")
     50                                                        .doubleValue(), image.getJsonNumber("lon").doubleValue(), image
     51                                                        .getJsonNumber("ca").doubleValue()));
    5052                                } catch (Exception e) {
    5153                                        System.out.println(e);
Note: See TracChangeset for help on using the changeset viewer.