Package org.json.simple

Examples of org.json.simple.JSONObject


      public String getValue() {
        return "foo";
      }
    };

    JSONObject json = (JSONObject) new JSONParser().parse(variableHolder.toJSONString());
    Assert.assertEquals(json.size(), 1);
    Assert.assertEquals(json.get("value"), "foo");

    StringWriter writer = new StringWriter();
    variableHolder.writeJSONString(writer);
    writer.close();
    json = (JSONObject) new JSONParser().parse(writer.toString());
    Assert.assertEquals(json.size(), 1);
    Assert.assertEquals(json.get("value"), "foo");
  }
View Full Code Here


   */
  private static void validateResponse(HttpURLConnection conn, int expected) throws IOException {
    int status = conn.getResponseCode();
    if (status != expected) {
      try {
        JSONObject json = (JSONObject) jsonParse(conn);
        throw new IOException(MessageFormat.format("HTTP status [{0}], {1} - {2}", json.get("status"),
                                                   json.get("reason"), json.get("message")));
      }
      catch (IOException ex) {
        if (ex.getCause() instanceof IOException) {
          throw (IOException) ex.getCause();
        }
View Full Code Here

    Map<String, String> params = new HashMap<String, String>();
    params.put("op", "rename");
    params.put("to", dst.toString());
    HttpURLConnection conn = getConnection("PUT", params, src);
    validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) jsonParse(conn);
    return (Boolean) json.get("rename");
  }
View Full Code Here

  public boolean delete(Path f, boolean recursive) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put("recursive", Boolean.toString(recursive));
    HttpURLConnection conn = getConnection("DELETE", params, f);
    validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) jsonParse(conn);
    return (Boolean) json.get("delete");
  }
View Full Code Here

    Map<String, String> params = new HashMap<String, String>();
    params.put("op", "mkdirs");
    params.put("permission", permissionToString(permission));
    HttpURLConnection conn = getConnection("POST", params, f);
    validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) jsonParse(conn);
    return (Boolean) json.get("mkdirs");
  }
View Full Code Here

  public FileStatus getFileStatus(Path f) throws IOException {
    Map<String, String> params = new HashMap<String, String>();
    params.put("op", "status");
    HttpURLConnection conn = getConnection("GET", params, f);
    validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) jsonParse(conn);
    return createFileStatus(json);
  }
View Full Code Here

    Map<String, String> params = new HashMap<String, String>();
    params.put("op", "homedir");
    try {
      HttpURLConnection conn = getConnection("GET", params, new Path("/"));
      validateResponse(conn, HttpURLConnection.HTTP_OK);
      JSONObject json = (JSONObject) jsonParse(conn);
      return new Path((String) json.get("homeDir"));
    }
    catch (IOException ex) {
      throw new RuntimeException(ex);
    }
  }
View Full Code Here

    Map<String, String> params = new HashMap<String, String>();
    params.put("op", "setreplication");
    params.put("replication", Short.toString(replication));
    HttpURLConnection conn = getConnection("PUT", params, src);
    validateResponse(conn, HttpURLConnection.HTTP_OK);
    JSONObject json = (JSONObject) jsonParse(conn);
    return (Boolean) json.get("setReplication");
  }
View Full Code Here

    public void execute(Tuple input) {
        //just need an id
        long genId = MessageId.generateId();
        _inputs.put(genId, input);
        try {
            JSONObject obj = new JSONObject();
            obj.put("id", genId);
            obj.put("comp", input.getSourceComponent());
            obj.put("stream", input.getSourceStreamId());
            obj.put("task", input.getSourceTask());
            obj.put("tuple", input.getValues());
            sendToSubprocess(obj.toString());
            while(true) {
              String line = "";
              while(true) {
                  String subline = _processout.readLine();
                  if(subline==null)
View Full Code Here

        }
    }

    public Number connect(Map conf, TopologyContext context)
            throws IOException, NoOutputException {
        JSONObject setupInfo = new JSONObject();
        setupInfo.put("pidDir", context.getPIDDir());
        setupInfo.put("conf", conf);
        setupInfo.put("context", context);
        writeMessage(setupInfo);

        Number pid = (Number) ((JSONObject) readMessage()).get("pid");
        return pid;
    }
View Full Code Here

TOP

Related Classes of org.json.simple.JSONObject

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.