Package external.JSON

Examples of external.JSON.JSONObject$Null


  }

  /* Complex accessors */

    public String toJSON() {
        JSONObject theJSON = new JSONObject();

        try {
            theJSON.put("matchId", matchId);
            theJSON.put("randomToken", randomToken);
            theJSON.put("startTime", startTime.getTime());
            theJSON.put("gameMetaURL", getGameRepositoryURL());
            theJSON.put("isCompleted", isCompleted);
            theJSON.put("isAborted", isAborted);
            theJSON.put("states", new JSONArray(renderArrayAsJSON(renderStateHistory(stateHistory), true)));
            theJSON.put("moves", new JSONArray(renderArrayAsJSON(renderMoveHistory(moveHistory), false)));
            theJSON.put("stateTimes", new JSONArray(renderArrayAsJSON(stateTimeHistory, false)));
            if (errorHistory.size() > 0) {
                theJSON.put("errors", new JSONArray(renderArrayAsJSON(renderErrorHistory(errorHistory), false)));
            }
            if (goalValues.size() > 0) {
                theJSON.put("goalValues", goalValues);
            }
            theJSON.put("previewClock", previewClock);
            theJSON.put("startClock", startClock);
            theJSON.put("playClock", playClock);
            if (thePlayerNamesFromHost != null) {
                theJSON.put("playerNamesFromHost", thePlayerNamesFromHost);
            }
            if (isPlayerHuman != null) {
              theJSON.put("isPlayerHuman", isPlayerHuman);
            }
            theJSON.put("scrambled", theGdlScrambler != null ? theGdlScrambler.scrambles() : false);
        } catch (JSONException e) {
            return null;
        }

        if (theCryptographicKeys != null) {
            try {
                SignableJSON.signJSON(theJSON, theCryptographicKeys.thePublicKey, theCryptographicKeys.thePrivateKey);
                if (!SignableJSON.isSignedJSON(theJSON)) {
                    throw new Exception("Could not recognize signed match: " + theJSON);
                }
                if (!SignableJSON.verifySignedJSON(theJSON)) {
                    throw new Exception("Could not verify signed match: " + theJSON);
                }
            } catch (Exception e) {
                System.err.println(e);
                theJSON.remove("matchHostPK");
                theJSON.remove("matchHostSignature");
            }
        }

        return theJSON.toString();
    }
View Full Code Here


        public EncodedKeyPair(PublicKey thePK, PrivateKey theSK) {
            thePublicKey = encodeKey(thePK);
            thePrivateKey = encodeKey(theSK);
        }
        public EncodedKeyPair(String theKeyJSON) throws JSONException {
            JSONObject theJSON = new JSONObject(theKeyJSON);
            thePublicKey = theJSON.getString("PK");
            thePrivateKey = theJSON.getString("SK");
        }
View Full Code Here

        String theSignature = theJSON.getString("matchHostSignature");
        if (!theSignature.startsWith(theCanonicalizationPrefix))
            return false;
        theSignature = theSignature.replaceFirst(theCanonicalizationPrefix, "");

        JSONObject tempObject = new JSONObject(theJSON.toString());
        tempObject.remove("matchHostSignature");
        try {
            return BaseCryptography.verifySignature(thePK, theSignature, CanonicalJSON.getCanonicalForm(tempObject, CanonicalizationStrategy.SIMPLE));
        } catch (InvalidKeyException e) {
        } catch (SignatureException e) {
        } catch (NoSuchAlgorithmException e) {
View Full Code Here

        return theJSON.toString();
    }

    public String toXML() {
      try {
        JSONObject theJSON = new JSONObject(toJSON());

        StringBuilder theXML = new StringBuilder();
        theXML.append("<match>");
        for (String key : JSONObject.getNames(theJSON)) {
          Object value = theJSON.get(key);
          if (value instanceof JSONObject) {
            throw new RuntimeException("Unexpected embedded JSONObject in match JSON with tag " + key + "; could not convert to XML.");
          } else if (!(value instanceof JSONArray)) {
            theXML.append(renderLeafXML(key, theJSON.get(key)));
          } else if (key.equals("states")) {
            theXML.append(renderStateHistoryXML(stateHistory));
          } else if (key.equals("moves")) {
            theXML.append(renderMoveHistoryXML(moveHistory));
          } else if (key.equals("errors")) {
View Full Code Here

  }

  private static final String playerListFilename = ".ggpserver-playerlist.json";
  private void savePlayersJSON() {
    try {
      JSONObject playerListJSON = new JSONObject();
      playerListJSON.put("hostports", monitoredPlayers.keySet());
      File file = new File(System.getProperty("user.home"), playerListFilename);
      if (!file.exists()) {
        file.createNewFile();
      }
      FileWriter fw = new FileWriter(file);
      BufferedWriter bw = new BufferedWriter(fw);
      bw.write(playerListJSON.toString());
      bw.close();
    } catch (IOException ie) {
      ie.printStackTrace();
    } catch (JSONException e) {
      e.printStackTrace();
View Full Code Here

          pdata.append(line);
        }
      } finally {
        br.close();
      }
      JSONObject playerListJSON = new JSONObject(pdata.toString());
      if (playerListJSON.has("hostports")) {
        JSONArray theHostports = playerListJSON.getJSONArray("hostports");
        for (int i = 0; i < theHostports.length(); i++) {
          try {
            addPlayerSilently(theHostports.get(i).toString());
          } catch (InvalidHostportException e) {
            e.printStackTrace();
View Full Code Here

TOP

Related Classes of external.JSON.JSONObject$Null

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.