Package org.json.simple

Examples of org.json.simple.JSONArray


    viewPath.append(File.separator);
    viewPath.append(uid);
    String[] pathList = new String[2];
    pathList[0]=viewPath.toString();
    pathList[1]=publicViewPath;
    JSONArray list = new JSONArray();
    for(String path : pathList) {
      Path viewFile = new Path(path);
      try {
        FileSystem fs = FileSystem.get(config);
        FileStatus[] fstatus = fs.listStatus(viewFile);
        if(fstatus!=null) {
          for(int i=0;i<fstatus.length;i++) {
            if(!fstatus[i].getPath().getName().endsWith(".view")) {
              continue;
            }
            long size = fstatus[i].getLen();
            FSDataInputStream viewStream = fs.open(fstatus[i].getPath());
            byte[] buffer = new byte[(int)size];
            viewStream.readFully(buffer);
            viewStream.close();
            try {
              ViewBean view = new ViewBean(buffer);
              Map<String, String> json=new LinkedHashMap<String, String>();
              json.put("name", view.getName());
              json.put("type", view.getPermissionType());
              json.put("owner", view.getOwner());
              if(uid.intern()==view.getOwner().intern()) {
                json.put("editable","true");
              } else {
                json.put("editable","false");
              }
              list.add(json);
            } catch (Exception e) {
              log.error(ExceptionUtil.getStackTrace(e));
            }
          }
        }
View Full Code Here


  }
 
  public void add(long x, double y) {
    try {
    if(!series.containsKey("data")) {
      series.put("data", new JSONArray());
    }
    JSONArray xy = new JSONArray();
    xy.add(x);
    xy.add(y);
    ((JSONArray)series.get("data")).add(xy);
    } catch(Exception e) {
      log.error(ExceptionUtil.getStackTrace(e));
    }
  }
View Full Code Here

 
  public PagesBean(JSONObject json) throws ParseException {
    try {
      title = (String) json.get("title");
      columns = ((Long) json.get("columns")).intValue();
      JSONArray layout = (JSONArray) json.get("layout");
      this.layout = new ColumnBean[layout.size()];
      for(int i=0;i<layout.size();i++) {
        ColumnBean c = new ColumnBean((JSONArray) layout.get(i));
        this.layout[i]=c;
      }
      if(json.containsKey("colSize")) {
        JSONArray ja = (JSONArray) json.get("colSize");
        columnSizes = new int[ja.size()];
        for(int i=0; i< ja.size(); i++) {
          columnSizes[i] = ((Long) ja.get(i)).intValue();
        }
      }
    } catch (Exception e) {
      log.error(ExceptionUtil.getStackTrace(e));
      throw new ParseException(ExceptionUtil.getStackTrace(e), 0);
View Full Code Here

    this.columns = columns;
  }
 
  public JSONObject deserialize() {
    JSONObject json = new JSONObject();
    JSONArray ja = new JSONArray();
    JSONArray sizes = new JSONArray();
    try {
      json.put("title", this.title);
      for(int i=0;i<layout.length;i++) {
        ja.add(layout[i].deserialize());
      }
      json.put("layout", (JSONArray) ja);
      json.put("columns", layout.length);
      if(columnSizes!=null) {
        for(int colSize : columnSizes) {
          sizes.add(colSize);
        }
      }
      json.put("colSize", (JSONArray) sizes);
    } catch (Exception e) {
      log.error(ExceptionUtil.getStackTrace(e));
View Full Code Here

  private JSONArray views;
  private JSONObject properties;
  private static Log log = LogFactory.getLog(UserBean.class);
 
  public UserBean() {
    views = new JSONArray();
    properties = new JSONObject();
  }
View Full Code Here

      widgets[i].update();
    }
  }
 
  public JSONArray deserialize() {
    JSONArray ja = new JSONArray();
    for(int i=0;i<widgets.length;i++) {
      ja.add(widgets[i].deserialize());
    }
    return ja;
  }
View Full Code Here

          throw new IllegalAccessException("Unable to access user profile database.");
        }
      } else {
        profile = new UserBean();
        profile.setId(uid);
        JSONArray ja = new JSONArray();
        profile.setViews(ja);
        JSONObject json = new JSONObject();
        profile.setProperties(json.toString());
      }
    } catch (IOException ex) {
View Full Code Here

    profilePath.append(hiccPath);
    profilePath.append(File.separator);
    profilePath.append("*.profile");
    Path viewFile = new Path(profilePath.toString());
    FileSystem fs;
    JSONArray list = new JSONArray();
    try {
      fs = FileSystem.get(config);
      FileStatus[] fstatus = fs.listStatus(viewFile);
      if(fstatus!=null) {
        for(int i=0;i<fstatus.length;i++) {
          long size = fstatus[i].getLen();
          FSDataInputStream profileStream = fs.open(fstatus[i].getPath());
          byte[] buffer = new byte[(int)size];
          profileStream.readFully(buffer);
          profileStream.close();
          try {
            UserBean user = new UserBean((JSONObject) JSONValue.parse(new String(buffer)));
            list.add(user.getId());
          } catch (Exception e) {
            log.error(ExceptionUtil.getStackTrace(e));
          }
        }
      }
View Full Code Here

       */

      String cluster = "demo";
      DatabaseWriter db = new DatabaseWriter(cluster);

      JSONArray json_array=(JSONArray)JSONValue.parse(json_str);
      for (int i=0; i < json_array.size(); i++) {
    JSONObject row_obj=(JSONObject) json_array.get(i);

    // get the database row

    String queryString=getDatabaseQuery(table, row_obj);
    Macro m=new Macro(startTime, endTime, queryString);
View Full Code Here

    ChukwaRecord record = new ChukwaRecord();
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    cal.setTimeInMillis(timestamp);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    JSONArray cpuList = (JSONArray) json.get("cpu");
    double combined = 0.0;
    double user = 0.0;
    double sys = 0.0;
    double idle = 0.0;
    for(int i = 0; i< cpuList.size(); i++) {
      JSONObject cpu = (JSONObject) cpuList.get(i);
      Iterator<String> keys = cpu.keySet().iterator();
      combined = combined + Double.parseDouble(cpu.get("combined").toString());
      user = user + Double.parseDouble(cpu.get("user").toString());
      sys = sys + Double.parseDouble(cpu.get("sys").toString());
      idle = idle + Double.parseDouble(cpu.get("idle").toString());
      while(keys.hasNext()) {
        String key = keys.next();
        record.add(key + "." + i, cpu.get(key).toString());
      }
    }
    combined = combined / cpuList.size();
    user = user / cpuList.size();
    sys = sys / cpuList.size();
    idle = idle / cpuList.size();
    record.add("combined", Double.toString(combined));
    record.add("user", Double.toString(user));
    record.add("idle", Double.toString(idle));   
    record.add("sys", Double.toString(sys));
    buildGenericRecord(record, null, cal.getTimeInMillis(), "cpu");
    output.collect(key, record);   

    record = new ChukwaRecord();
    record.add("Uptime", json.get("uptime").toString());
    JSONArray loadavg = (JSONArray) json.get("loadavg");
    record.add("LoadAverage.1", loadavg.get(0).toString());
    record.add("LoadAverage.5", loadavg.get(1).toString());
    record.add("LoadAverage.15", loadavg.get(2).toString());
    buildGenericRecord(record, null, cal.getTimeInMillis(), "system");
    output.collect(key, record);   

    record = new ChukwaRecord();
    JSONObject memory = (JSONObject) json.get("memory");
    Iterator<String> memKeys = memory.keySet().iterator();
    while(memKeys.hasNext()) {
      String key = memKeys.next();
      record.add(key, memory.get(key).toString());
    }
    buildGenericRecord(record, null, cal.getTimeInMillis(), "memory");
    output.collect(key, record);   
   
    double rxBytes = 0;
    double rxDropped = 0;
    double rxErrors = 0;
    double rxPackets = 0;
    double txBytes = 0;
    double txCollisions = 0;
    double txErrors = 0;
    double txPackets = 0;
    record = new ChukwaRecord();
    JSONArray netList = (JSONArray) json.get("network");
    for(int i = 0;i < netList.size(); i++) {
      JSONObject netIf = (JSONObject) netList.get(i);
      Iterator<String> keys = netIf.keySet().iterator();
      while(keys.hasNext()) {
        String key = keys.next();
        record.add(key + "." + i, netIf.get(key).toString());
        if(i!=0) {
          if(key.equals("RxBytes")) {
            rxBytes = rxBytes + (Long) netIf.get(key);
          } else if(key.equals("RxDropped")) {
            rxDropped = rxDropped + (Long) netIf.get(key);
          } else if(key.equals("RxErrors")) {         
            rxErrors = rxErrors + (Long) netIf.get(key);
          } else if(key.equals("RxPackets")) {
            rxPackets = rxPackets + (Long) netIf.get(key);
          } else if(key.equals("TxBytes")) {
            txBytes = txBytes + (Long) netIf.get(key);
          } else if(key.equals("TxCollisions")) {
            txCollisions = txCollisions + (Long) netIf.get(key);
          } else if(key.equals("TxErrors")) {
            txErrors = txErrors + (Long) netIf.get(key);
          } else if(key.equals("TxPackets")) {
            txPackets = txPackets + (Long) netIf.get(key);
          }
        }
      }
    }
    buildGenericRecord(record, null, cal.getTimeInMillis(), "network");
    record.add("RxBytes", Double.toString(rxBytes));
    record.add("RxDropped", Double.toString(rxDropped));
    record.add("RxErrors", Double.toString(rxErrors));
    record.add("RxPackets", Double.toString(rxPackets));
    record.add("TxBytes", Double.toString(txBytes));
    record.add("TxCollisions", Double.toString(txCollisions));
    record.add("TxErrors", Double.toString(txErrors));
    record.add("TxPackets", Double.toString(txPackets));
    output.collect(key, record);   
   
    double readBytes = 0;
    double reads = 0;
    double writeBytes = 0;
    double writes = 0;
    record = new ChukwaRecord();
    JSONArray diskList = (JSONArray) json.get("disk");
    for(int i = 0;i < diskList.size(); i++) {
      JSONObject disk = (JSONObject) diskList.get(i);
      Iterator<String> keys = disk.keySet().iterator();
      while(keys.hasNext()) {
        String key = keys.next();
        record.add(key + "." + i, disk.get(key).toString());
        if(key.equals("ReadBytes")) {
View Full Code Here

TOP

Related Classes of org.json.simple.JSONArray

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.