Example usage for org.json.simple JSONArray JSONArray

List of usage examples for org.json.simple JSONArray JSONArray

Introduction

In this page you can find the example usage for org.json.simple JSONArray JSONArray.

Prototype

JSONArray

Source Link

Usage

From source file:edu.usc.polar.NLTKRest.java

public static void dir(String path, String[] args) {
    try {//  w  w w  .j  av a2 s.  c  om

        File root = new File(path);
        if (root.isFile()) {

            if (counter >= 1000 || file == null) {
                counter = 0;
                jsonCount++;
                file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\NLTKRest\\NER_"
                        + jsonCount + ".json");
                if (jsonFile != null) {
                    jsonFile.write("{\"NER_NLTKRest\":");
                    jsonFile.write(jsonArray.toJSONString());
                    jsonFile.write("}");
                    //   System.out.println(jsonArray.toJSONString());
                    jsonFile.close();
                }
                jsonFile = new FileWriter(file);
                jsonArray = new JSONArray();
            }

            if (!root.getName().equals((".DS_Store"))) {
                ApacheNLTKRest(root.getAbsolutePath(), args);
                counter++;
            }
        } else {
            File[] list = root.listFiles();
            if (list == null) {
                return;
            }
            for (File f : list) {
                if (f.isDirectory()) {
                    dir(f.getAbsolutePath(), args);
                    System.out.println("Dir:" + f.getAbsoluteFile());
                } else {
                    if (counter >= 1000 || file == null) {
                        counter = 0;
                        jsonCount++;
                        file = new File("C:\\Users\\Snehal\\Documents\\tikaSimilarityTestSet\\NLTKRest\\NER_"
                                + jsonCount + ".json");
                        //  System.out.print("check"+jsonArray.toJSONString());
                        if (jsonFile != null) {
                            jsonFile.write("{\"NER_NLTKRest\":");
                            jsonFile.write(jsonArray.toJSONString());
                            jsonFile.write("}");
                            System.out.println(jsonArray.toJSONString());
                            jsonFile.close();
                        }
                        jsonFile = new FileWriter(file);
                        jsonArray = new JSONArray();
                    }

                    if (!f.getName().equals((".DS_Store"))) {
                        ApacheNLTKRest(f.getAbsolutePath(), args);
                        counter++;
                        // add json   
                    }
                }
            }
        }
    } catch (Exception e) {
        System.err.print(e.toString());

    }
}

From source file:com.saludtec.web.DescripcionPlanDeTratamientoWeb.java

private JSONArray listarDescripcionPlanDeTratamiento(HttpServletRequest request) {
    List<DescripcionPlanDeTratamiento> descripcionPlanTratamientoes = ejbDescripcionPlanTratamiento
            .listar(Integer.parseInt(request.getParameter("idPlanTratamiento")));
    objArray = new JSONArray();
    if (descripcionPlanTratamientoes != null) {
        for (DescripcionPlanDeTratamiento descripcionPlanTratamiento : descripcionPlanTratamientoes) {
            obj = new JSONObject();
            obj.put("idDescripcionPlanDeTratamiento",
                    descripcionPlanTratamiento.getIdDescripcionPlanTratamiento());
            obj.put("idPlanTratamiento",
                    descripcionPlanTratamiento.getIdPlanTratamiento().getIdPlanDeTratamiento());
            obj.put("textoDescripcionPlanTratamiento",
                    descripcionPlanTratamiento.getTextoDescripcionPlanTratamiento());
            obj.put("valorDescripcionPlanTratamiento",
                    descripcionPlanTratamiento.getValorDescripcionPlanTratamiento());
            objArray.add(obj);/*from w  ww  .ja  v a 2  s .c  om*/
        }
    }
    return objArray;
}

From source file:modelo.ProcesoVertimientosManagers.Visitas.java

public JSONArray getVisitasPendientes(String filaInicio, String filaFin, String codigoProceso, String contrato,
        String nit, String razonSocial, String comuna, String direccion) throws SQLException {

    JSONArray jsonArray = new JSONArray();
    JSONArray jsonArreglo = new JSONArray();
    JSONObject jsonObject = new JSONObject();
    ResultSet rset;/*from  w ww .  j av  a2 s  .  c o  m*/

    SeleccionarVisitas select = new SeleccionarVisitas(filaInicio, filaFin, codigoProceso, contrato, nit,
            razonSocial, comuna, direccion);

    rset = select.getVisitasPendientes();

    while (rset.next()) {

        jsonObject.put("codigoProceso", rset.getString("CODPROCESO"));
        jsonObject.put("contrato", rset.getString("CONTRATO"));
        jsonObject.put("nit", rset.getString("NIT"));
        jsonObject.put("razon_social", rset.getString("RAZON_SOCIAL"));
        jsonObject.put("comuna", rset.getString("COMUNA"));
        jsonObject.put("direccion", rset.getString("DIRECCION"));

        jsonArray.add(jsonObject.clone());

    }

    jsonArreglo.add(jsonArray);

    //Se cierra el ResultSet
    select.desconectar();

    return jsonArreglo;

}

From source file:com.saludtec.web.ProcedimientosWeb.java

private JSONArray listarProcedimientos() throws NonexistentEntityException {
    List<Procedimientos> procedimientos = ejb.traerProcedimientos();
    objArray = new JSONArray();
    if (procedimientos != null) {
        for (Procedimientos procedimiento : procedimientos) {
            obj = new JSONObject();
            obj.put("idProcedimiento", procedimiento.getIdProcedimiento());
            obj.put("nombreProcedimiento", procedimiento.getNombreProcedimiento());
            obj.put("idCategoriaProcedimiento", procedimiento.getIdCategoriaProcedimiento().getIdCategoria());
            obj.put("categoriaProcedimiento",
                    procedimiento.getIdCategoriaProcedimiento().getCategoriaProcedimiento());
            obj.put("rangoProcedimiento", procedimiento.getRangoProcedimiento());
            obj.put("cups", procedimiento.getCups());
            obj.put("valor", procedimiento.getValor());
            obj.put("ambitoRealizacion", procedimiento.getAmbitoRealizacion());
            obj.put("finalidad", procedimiento.getFinalidad());
            obj.put("actoQuirurjico", procedimiento.getActoQuirurjico());
            objArray.add(obj);/* ww w  . j a  v a 2 s  .c o m*/
        }
    }
    return objArray;
}

From source file:com.imagelake.android.details.Servlet_ImageDetails.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {/*  ww w  .jav a 2 s.c  om*/
        String type = request.getParameter("type");
        System.out.println(type);
        if (!type.equals("") && type != null) {

            if (type.equals("info")) {
                String imgid = request.getParameter("imgid");
                String uid = request.getParameter("uid");

                Images img = idip.getImageDetail(Integer.parseInt(imgid));

                if (img != null) {
                    boolean k = new ImagesDAOImp().updateImageViewCount(img.getImages_id(), img.getView() + 1);
                    if (k) {
                        if (img.getImage_state_image_state_id() == 1) {
                            detailObject = new JSONObject();
                            detailObject.put("title", img.getTitle());
                            detailObject.put("url", img.getImg_url());
                            detailObject.put("view", img.getView());
                            int chh = cdi.getCartDownloadCount(Integer.parseInt(imgid));
                            detailObject.put("dwn", chh);

                            JSONArray subImagesArray = new JSONArray();
                            Credits cre;
                            List<ImagesSub> subList = idip.getImagedescription(Integer.parseInt(imgid));
                            for (ImagesSub imagesSub : subList) {
                                JSONObject jo = new JSONObject();
                                cre = crdi.getCreditDetails(imagesSub.getCredits());

                                jo.put("sid", imagesSub.getSub_images_id());
                                jo.put("size", cre.getSize());
                                jo.put("dim", imagesSub.getDimention());
                                jo.put("crd", cre.getCredits());

                                subImagesArray.add(jo);

                            }
                            detailObject.put("subList", subImagesArray);

                            User u = udi.getUser(img.getUser_user_id());
                            detailObject.put("uName", u.getUser_name());

                            List<KeyWords> keyList = kdi.getkeyWordList(Integer.parseInt(imgid));
                            JSONArray keyArray = new JSONArray();
                            for (KeyWords keyWords : keyList) {
                                JSONObject jo = new JSONObject();
                                jo.put("kid", keyWords.getKey_words_id());
                                jo.put("key", keyWords.getKey_word());
                                keyArray.add(jo);
                            }
                            detailObject.put("keyList", keyArray);
                            //List<CartHasImages> chiList = cdi.getRattingList(Integer.parseInt(imgid));

                            String sql = "SELECT * FROM images WHERE categories_category_id='"
                                    + img.getCategories_category_id() + "' AND image_state_image_state_id='1'";
                            PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
                            ResultSet rs = ps.executeQuery();
                            JSONArray simImage = new JSONArray();
                            while (rs.next()) {
                                JSONObject jo = new JSONObject();
                                jo.put("simid", rs.getInt(1));
                                jo.put("url", rs.getString(15));
                                simImage.add(jo);
                            }
                            detailObject.put("imgList", simImage);
                            System.out.println("user id " + uid);
                            if (Integer.parseInt(uid) != (-1) && Integer.parseInt(uid) != 0) {
                                Cart cct = cdi.getCart(Integer.parseInt(uid));
                                if (cct != null) {
                                    boolean have = cdi.isThisInLightBoxImage(cct.getCart_id(), 2,
                                            Integer.parseInt(imgid));
                                    if (have) {
                                        detailObject.put("lightbox", 1);
                                    } else {
                                        detailObject.put("lightbox", 0);
                                    }
                                } else {
                                    detailObject.put("lightbox", 0);
                                }
                            } else {
                                detailObject.put("lightbox", 0);
                            }
                            out.write("json=" + detailObject.toJSONString());
                        }
                    } else {
                        out.write("msg=Unable to complete the action.Please try again later.");
                    }
                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }
            } else if (type.equals("lightbox")) {

                String imgid = request.getParameter("imgid");
                String uid = request.getParameter("uid");

                System.out.println(imgid);
                System.out.println(uid);

                ImagesSub is = null;
                Credits cre = null;
                Cart cart = null;

                is = idip.getLowestQuality(Integer.parseInt(imgid));
                cre = new CreditsDAOImp().getCreditDetails(is.getCredits());
                cart = new CartDAOImp().getCart(Integer.parseInt(uid));
                System.gc();
                if (is != null) {
                    boolean ok = new CartDAOImp().addToLightBox(Integer.parseInt(imgid), is.getSub_images_id(),
                            2, cart.getCart_id(), date, cre.getCredits());
                    if (ok) {
                        out.write("msg=Successfully_add_lightbox");
                    } else {
                        out.write("msg=Unable to complete the action,Please try again later.");

                    }

                } else {
                    out.write("msg=Internal server error,Please try again later.");

                }
            } else if (type.equals("Add_cart")) {
                String imgid = request.getParameter("imgid");
                String sid = request.getParameter("sid");
                String uid = request.getParameter("uid");

                System.out.println(imgid);
                System.out.println(sid);
                System.out.println(uid);

                Images img = idip.getImageDetail(Integer.parseInt(imgid));
                boolean update = false;
                boolean o = false;

                if (img != null) {
                    int i = 0;
                    int subimg_Id = Integer.parseInt(sid);
                    ImagesSub isu = idip.getSubImage(subimg_Id);

                    if (isu != null) {

                        CreditsDAOImp cdi = new CreditsDAOImp();

                        int credits = cdi.getCredit(isu.getCredits());

                        CartItems ci = null;

                        int cartCount = 0;

                        if (uid == null) {

                        } else {
                            //if user signin
                            System.out.println("signIn user");
                            //          

                            List<CartItems> citems;

                            Cart b = new CartDAOImp().getCart(Integer.parseInt(uid));
                            //           
                            //           System.out.println("cart :"+b.getCart_id());
                            //           System.out.println("cart is null"+b==null);
                            //           
                            if (b.getCart_id() == 0) {

                                //if user didn't have cart in the database
                                System.out.println("don't have a cart");
                                Cart c = new Cart();
                                c.setUser_id(Integer.parseInt(uid));
                                c.setCredit_count(0);
                                c.setCredit_unit_price_id(1);
                                c.setImage_count(0);
                                c.setSubscription_unit_price_id(1);

                                //creating a new cart
                                boolean bb = new CartDAOImp().setACart(c);
                                System.out.println("created a new cart" + bb);
                                System.gc();

                                if (bb) {
                                    //getting that new cart 

                                    b = new CartDAOImp().getCart(Integer.parseInt(uid));

                                    if (b == null) {

                                    } else {
                                        CartItems cartI = new CartItems();
                                        cartI.setImgId(Integer.parseInt(imgid));
                                        cartI.setSubimg_Id(subimg_Id);
                                        cartI.setCredit(credits);
                                        cartI.setDate(date);

                                        boolean owner = idip.checkOwner(Integer.parseInt(uid),
                                                Integer.parseInt(imgid));
                                        if (owner) {
                                            out.write("msg=This is your image,you can't add to cart.");

                                        } else {
                                            //  boolean alreadyPur=new CartDAOImp().checkAlreadyPurchase(b.getCart_id(),cartI.getImgId());
                                            //if(!alreadyPur){ 
                                            boolean duplicat = new CartDAOImp()
                                                    .checkImageDuplication(b.getCart_id(), cartI.getImgId());
                                            if (duplicat) {
                                                boolean updated = new CartDAOImp()
                                                        .updateCartHasImagesSubImageID(b.getCart_id(),
                                                                cartI.getImgId(), cartI.getSubimg_Id(),
                                                                cartI.getCredit());
                                            } else {
                                                System.out.println("addingCarItems");
                                                o = new CartDAOImp().addingCarItems(cartI, b);
                                                System.gc();

                                            }

                                        }
                                    }

                                }
                                System.gc();
                            } else {
                                //if user have a cart in the database

                                System.out.println("this user have a car in the DB");
                                b = new CartDAOImp().getCart(Integer.parseInt(uid));

                                List<CartHasImages> ch = null;

                                int imgcount = 0;
                                int creditcount = 0;

                                if (b == null) {

                                } else {
                                    //               
                                    CartItems cartI = new CartItems();
                                    cartI.setImgId(Integer.parseInt(imgid));
                                    cartI.setSubimg_Id(subimg_Id);
                                    cartI.setCredit(credits);
                                    cartI.setDate(date);

                                    boolean owner = idip.checkOwner(Integer.parseInt(uid),
                                            Integer.parseInt(imgid));
                                    if (owner) {
                                        out.write("msg=This is your image,you can't add to cart.");
                                    } else {

                                        boolean duplicat = new CartDAOImp()
                                                .checkImageDuplication(b.getCart_id(), cartI.getImgId());
                                        if (duplicat) {
                                            boolean updated = new CartDAOImp().updateCartHasImagesSubImageID(
                                                    b.getCart_id(), cartI.getImgId(), cartI.getSubimg_Id(),
                                                    cartI.getCredit());
                                            out.write("msg=Image is added to the cart.");
                                        } else {
                                            System.out.println("addingCarItems");
                                            o = new CartDAOImp().addingCarItems(cartI, b);
                                            System.gc();
                                            out.write("msg=Image is added to the cart.");

                                        }

                                    }
                                    ch = new CartDAOImp().listCartHasImages();
                                    for (CartHasImages carhi : ch) {

                                        if (carhi.getCart_id() == b.getCart_id()
                                                && carhi.getIs_purchase() == 0) {
                                            imgcount++;
                                            creditcount += carhi.getCredits();
                                            System.out.println(
                                                    "-----------------totalcount------------------------"
                                                            + imgcount);
                                            System.out
                                                    .println("-----------------credits------------------------"
                                                            + creditcount);
                                        }

                                    }
                                    update = new CartDAOImp().updateCartQty(imgcount, creditcount,
                                            b.getCart_id());

                                }
                                //               
                                System.gc();
                            }
                        }

                        System.out.println("near end");

                        //                            System.gc();
                        //                            response.sendRedirect("description.jsp?image_id=" + imgid);

                    } else {

                        out.write("msg=Internal server error,Please try again later.");
                    }

                } else {
                    out.write("msg=Internal server error,Please try again later.");
                }

            }
        } else {
            out.write("msg=Internal server error,Please try again later.");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:modelo.ProcesoVertimientosManagers.ManejoLodos.java

public JSONArray getLodo(int codigo) throws Exception {

    //Ejecutamos la consulta y obtenemos el ResultSet
    SeleccionarEntidadesLodos select = new SeleccionarEntidadesLodos();
    ResultSet rset = select.getLodo(codigo);
    //Creamos los JSONArray para guardar los objetos JSON
    JSONArray jsonArray = new JSONArray();
    JSONArray jsonArreglo = new JSONArray();

    //Recorremos el ResultSet, armamos el objeto JSON con la info y guardamos
    //en el JSONArray.
    while (rset.next()) {

        //Armamos el objeto JSON con la informacion del registro
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("codigo", rset.getString("CODIGO"));
        jsonObject.put("nombreEmpresa", rset.getString("NOMBRE_EMPRESA"));
        jsonObject.put("recolecta", rset.getString("RECOLECTA"));
        jsonObject.put("transporte", rset.getString("TRANSPORTE"));
        jsonObject.put("dispone", rset.getString("DISPONE"));
        jsonObject.put("volumen", rset.getString("VOLUMEN"));
        jsonObject.put("fecha", rset.getString("FECHA_RECOLECCION"));
        jsonObject.put("frecuencia", rset.getString("FRECUENCIA"));
        jsonObject.put("sitio", rset.getString("SITIO_DISPOSICION"));

        //Guardamos el JSONObject en el JSONArray y lo enviamos a la vista.
        jsonArray.add(jsonObject.clone());

    }/* w ww.  j  a va  2  s  . c  o m*/

    jsonArreglo.add(jsonArray);
    select.desconectar();

    return jsonArreglo;

}

From source file:me.timothy.ddd.acheivements.AchievementManager.java

public AchievementManager() {
    logger = LogManager.getLogger();
    achievements = new ArrayList<>();
    toDisplay = new LinkedList<Achievement>();

    bkndColor = new Color(49, 45, 150);
    titleColor = new Color(215, 208, 39);
    textColor = new Color(215, 135, 39);

    final File achievs = new File("achievements_acquired.json");
    if (achievs.exists()) {
        try (FileReader fr = new FileReader(achievs)) {
            JSONArray jArr = (JSONArray) (new JSONParser().parse(fr));
            for (int i = 0; i < jArr.size(); i++) {
                Achievement ach = new Achievement();
                ach.loadFrom((JSONObject) jArr.get(i));
                achievements.add(ach);//www.j a v a 2s  .c o  m
            }
        } catch (IOException | ParseException e) {
            logger.throwing(e);
            throw new RuntimeException(e);
        }
    }

    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            JSONArray jArr = new JSONArray();
            for (Achievement ach : achievements) {
                JSONObject jObj = new JSONObject();
                ach.saveTo(jObj);
                jArr.add(jObj);
            }
            try (FileWriter fw = new FileWriter(achievs)) {
                DDDUtils.writeJSONPretty(fw, jArr);
            } catch (IOException e) {
            }
        }

    }));
}

From source file:edu.iu.incntre.flowscale.util.JSONConverter.java

/**
 * convert a list of flows to JSONArray/*from  ww  w  .  j av  a 2  s.c  o  m*/
 * @param ofs
 * @return JSONArray of flows 
 */
public static JSONArray toFlowStat(List<OFStatistics> ofs) {
    JSONArray jsonArray = new JSONArray();

    for (OFStatistics ofst : ofs) {

        OFFlowStatisticsReply st = (OFFlowStatisticsReply) ofst;

        JSONObject jsonObject = new JSONObject();
        String[] a = st.getActions().toString().split("port=");
        String c;
        c = st.getActions().toString();
        if (a.length == 1) {
            c = st.getActions().toString();
        } else {

            String[] b = a[1].split(",");
            c = b[0];
        }

        // parse the output
        String outputString = "";
        try {
            Pattern pattern = Pattern.compile("port=\\w*");

            Matcher matcher = pattern.matcher(st.getActions().toString());

            while (matcher.find()) {

                outputString += matcher.group().split("=")[1] + ",";
            }

        } catch (PatternSyntaxException pse) {
            outputString = "malformed";
        }

        if (outputString.length() == 0) {
            outputString = "DROP,";
        }
        jsonObject.put("actions", outputString.substring(0, outputString.length() - 1));
        jsonObject.put("hard_timeout", st.getHardTimeout());
        jsonObject.put("idle_timeout", st.getIdleTimeout());
        jsonObject.put("match", st.getMatch().toString());
        jsonObject.put("priority", st.getPriority());
        jsonObject.put("packet_count", st.getPacketCount());
        jsonObject.put("byte_count", st.getByteCount());
        jsonObject.put("table_id", st.getTableId());

        jsonArray.add(jsonObject);

    }

    if (jsonArray.size() == 0) {
        JSONObject jso = new JSONObject();
        jso.put("data", "nono");
    }

    return jsonArray;

}

From source file:biomine.bmvis2.pipeline.DeleteElementsOperation.java

public JSONObject toJSON() {
    JSONObject ret = new JSONObject();
    JSONArray nodes = new JSONArray();
    JSONArray edges = new JSONArray();

    nodes.addAll(this.deletedNodes);
    edges.addAll(this.deletedEdges);

    ret.put(DELETED_NODES_KEY, nodes);//ww w  . j a va 2  s . c om
    ret.put(DELETED_EDGES_KEY, edges);

    return ret;
}

From source file:com.facebook.tsdb.tsdash.server.PlotEndpoint.java

@Override
@SuppressWarnings("unchecked")
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    try {//  w w w .  java  2s  .  co  m
        // decode parameters
        String jsonParams = request.getParameter("params");
        if (jsonParams == null) {
            throw new Exception("Parameters not specified");
        }
        JSONObject jsonParamsObj = (JSONObject) JSONValue.parse(jsonParams);
        long tsFrom = (Long) jsonParamsObj.get("tsFrom");
        long tsTo = (Long) jsonParamsObj.get("tsTo");
        long width = (Long) jsonParamsObj.get("width");
        long height = (Long) jsonParamsObj.get("height");
        boolean surface = (Boolean) jsonParamsObj.get("surface");
        boolean palette = false;
        if (jsonParams.contains("palette")) {
            palette = (Boolean) jsonParamsObj.get("palette");
        }
        JSONArray metricsArray = (JSONArray) jsonParamsObj.get("metrics");
        if (metricsArray.size() == 0) {
            throw new Exception("No metrics to fetch");
        }
        MetricQuery[] metricQueries = new MetricQuery[metricsArray.size()];
        for (int i = 0; i < metricsArray.size(); i++) {
            metricQueries[i] = MetricQuery.fromJSONObject((JSONObject) metricsArray.get(i));
        }
        TsdbDataProvider dataProvider = TsdbDataProviderFactory.get();
        long ts = System.currentTimeMillis();
        Metric[] metrics = new Metric[metricQueries.length];
        for (int i = 0; i < metrics.length; i++) {
            MetricQuery q = metricQueries[i];
            metrics[i] = dataProvider.fetchMetric(q.name, tsFrom, tsTo, q.tags, q.orders);
            metrics[i] = metrics[i].dissolveTags(q.getDissolveList(), q.aggregator);
            if (q.rate) {
                metrics[i].computeRate();
            }
        }
        long loadTime = System.currentTimeMillis() - ts;
        // check to see if we have data
        boolean hasData = false;
        for (Metric metric : metrics) {
            if (metric.hasData()) {
                hasData = true;
                break;
            }
        }
        if (!hasData) {
            throw new Exception("No data");
        }
        JSONObject responseObj = new JSONObject();
        JSONArray encodedMetrics = new JSONArray();
        for (Metric metric : metrics) {
            encodedMetrics.add(metric.toJSONObject());
        }
        // plot just the first metric for now
        GnuplotProcess gnuplot = GnuplotProcess.create(surface);
        GnuplotOptions options = new GnuplotOptions(surface);
        options.enablePalette(palette);
        options.setDimensions((int) width, (int) height).setTimeRange(tsFrom, tsTo);
        String plotFilename = gnuplot.plot(metrics, options);
        gnuplot.close();

        responseObj.put("metrics", encodedMetrics);
        responseObj.put("loadtime", loadTime);
        responseObj.put("ploturl", generatePlotURL(plotFilename));
        out.println(responseObj.toJSONString());
        long renderTime = System.currentTimeMillis() - ts - loadTime;
        logger.info("[Plot] time frame: " + (tsTo - tsFrom) + "s, " + "load time: " + loadTime + "ms, "
                + "render time: " + renderTime + "ms");
    } catch (Throwable e) {
        out.println(getErrorResponse(e));
    }
    out.close();
}