Example usage for java.io Writer flush

List of usage examples for java.io Writer flush

Introduction

In this page you can find the example usage for java.io Writer flush.

Prototype

public abstract void flush() throws IOException;

Source Link

Document

Flushes the stream.

Usage

From source file:net.cit.tetrad.resource.SubResource.java

@RequestMapping("/drawDaemonInfoGraph.do")
public void drawDaemonInfoGraph(CommonDto dto, HttpServletResponse response) throws Exception {
    log.debug("start - drawDaemonInfoGraph()");
    String dsType = dto.getDstype();
    String queryOption = dto.getSearch_option();
    if (queryOption == null)
        queryOption = "N";

    dto.setSearch_sdate(DateUtil.getCurrentDate(DateUtil.dateformat(dto.getSdate(), "yyyy-MM-dd HH:mm"),
            "yyyyMMddHHmmssSSS"));
    dto.setSearch_edate(DateUtil.getCurrentDate(DateUtil.dateformat(dto.getEdate(), "yyyy-MM-dd HH:mm"),
            "yyyyMMddHHmmssSSS"));

    List<DBObject> resultList = null;
    if (dsType.equals(GRAPH_ACCUM)) {
        if (queryOption.equals("Y")) {
            resultList = (List<DBObject>) subDao.getAccumResult(dto);
        } else {/*from w  w  w .  jav  a 2  s  .c  om*/
            resultList = (List<DBObject>) subDao.getIncludeOptionResult(dto);
        }
    } else if (dsType.equals(GRAPH_CURENT)) {
        resultList = (List<DBObject>) subDao.getCurrentResult(dto);
    }

    Map<String, StatusDatasourceName> allDatasource = new AllStatusRule().allStatusDatasourceNameByMap();
    StatusDatasourceName statusInfo = allDatasource.get(dto.getDsname());
    String dsUnit = statusInfo.getYunit();

    if (resultList != null) {
        settingXaixUnit(resultList);
    }

    DhtmlJson dhtmlJson = new DhtmlJson();
    dhtmlJson.setDataUnit(dsUnit);
    dhtmlJson.setResultData(resultList);
    JSONObject jsonObject = JSONObject.fromObject(dhtmlJson);

    response.setContentType("text/html;charset=utf-8");
    response.setCharacterEncoding("UTF-8");

    response.setContentType("text/html");
    response.setHeader("Cache-Control", "no-cache");

    Writer writer = response.getWriter();
    writer.write(jsonObject.toString());

    log.debug(jsonObject.toString());
    writer.flush();

    log.debug("end - drawDaemonInfoGraph()");
}

From source file:net.cit.tetrad.resource.SubResource.java

@RequestMapping("/subAlarmList.do")
public void subAlarmList(HttpServletRequest request, HttpServletResponse response, CommonDto dto)
        throws Exception {
    log.debug("start - subAlarmList()");

    //iDisplayStart iDisplayLength datatable? ??     
    int pageNumber = Integer.parseInt(Utility.isNullNumber(request.getParameter("iDisplayStart")));
    int nPerPage = Integer.parseInt(Utility.isNullNumber(request.getParameter("iDisplayLength")));
    int sEcho = Integer.parseInt(Utility.isNullNumber(request.getParameter(REQ_SECHO)));
    log.debug("pageNumber=" + pageNumber + ", nPerPage=" + nPerPage);

    Enumeration parameter = request.getParameterNames();
    log.debug(parameter.toString());/*from  www .java 2  s  .c o m*/
    while (parameter.hasMoreElements()) {
        String pName = (String) parameter.nextElement();
        String pValue = request.getParameter(pName);
        log.debug(pName + " = " + pValue);
    }

    try {
        Class<?> classname = Alarm.class;
        Query query = new Query();

        query = setAlarmSearch(dto);// ? ?  +       
        int cnt = (int) monadService.getCount(query, classname);
        List<Object> resultList = monadService.getList(query.skip(pageNumber).limit(nPerPage), classname);

        PersonJson result = setPersonJson(cnt, sEcho, pageNumber, nPerPage, resultList);
        JSONObject jsonObject = JSONObject.fromObject(result);

        Writer writer = setResponse(response).getWriter();
        writer.write(jsonObject.toString());

        log.debug(jsonObject.toString());
        writer.flush();
    } catch (Exception e) {
        log.error(e, e);
    }

    log.debug("end - subAlarmList()");
}

From source file:com.sun.faban.harness.webclient.CLIServlet.java

private void doSubmit(String[] reqC, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (reqC.length < 3) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                "Benchmark and profile not provided in request.");
        return;//  www.j a va  2s  .  co  m
    }
    // first is the bench name
    BenchmarkDescription desc = BenchmarkDescription.getDescription(reqC[1]);
    if (desc == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Benchmark " + reqC[1] + " not deployed.");
        return;
    }
    try {
        String user = null;
        String password = null;
        boolean hasPermission = true;

        ArrayList<String> runIdList = new ArrayList<String>();

        DiskFileUpload fu = new DiskFileUpload();
        // No maximum size
        fu.setSizeMax(-1);
        // maximum size that will be stored in memory
        fu.setSizeThreshold(8192);
        // the location for saving data larger than getSizeThreshold()
        fu.setRepositoryPath(Config.TMP_DIR);

        List fileItems = null;
        try {
            fileItems = fu.parseRequest(request);
        } catch (FileUploadException e) {
            throw new ServletException(e);
        }

        for (Iterator i = fileItems.iterator(); i.hasNext();) {
            FileItem item = (FileItem) i.next();
            String fieldName = item.getFieldName();
            if (item.isFormField()) {
                if ("sun".equals(fieldName)) {
                    user = item.getString();
                } else if ("sp".equals(fieldName)) {
                    password = item.getString();
                }
                continue;
            }
            if (reqC[2] == null) // No profile
                break;

            if (desc == null)
                break;

            if (!"configfile".equals(fieldName))
                continue;

            if (Config.SECURITY_ENABLED) {
                if (Config.CLI_SUBMITTER == null || Config.CLI_SUBMITTER.length() == 0
                        || !Config.CLI_SUBMITTER.equals(user)) {
                    hasPermission = false;
                    break;
                }
                if (Config.SUBMIT_PASSWORD == null || Config.SUBMIT_PASSWORD.length() == 0
                        || !Config.SUBMIT_PASSWORD.equals(password)) {
                    hasPermission = false;
                    break;
                }
            }

            String usrDir = Config.PROFILES_DIR + reqC[2];
            File dir = new File(usrDir);
            if (dir.exists()) {
                if (!dir.isDirectory()) {
                    logger.severe(usrDir + " should be a directory");
                    dir.delete();
                    logger.fine(dir + " deleted");
                } else
                    logger.fine("Saving parameter file to" + usrDir);
            } else {
                logger.fine("Creating new profile directory for " + reqC[2]);
                if (dir.mkdirs())
                    logger.fine("Created new profile directory " + usrDir);
                else
                    logger.severe("Failed to create profile " + "directory " + usrDir);
            }

            // Save the latest config file into the profile directory
            String dstFile = Config.PROFILES_DIR + reqC[2] + File.separator + desc.configFileName + "."
                    + desc.shortName;

            item.write(new File(dstFile));
            runIdList.add(RunQ.getHandle().addRun(user, reqC[2], desc));
        }

        response.setContentType("text/plain");
        Writer writer = response.getWriter();

        if (!hasPermission) {
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            writer.write("Permission denied!\n");
        }

        if (runIdList.size() == 0)
            writer.write("No runs submitted.\n");
        for (String newRunId : runIdList) {
            writer.write(newRunId);
        }

        writer.flush();
        writer.close();
    } catch (ServletException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
        throw e;
    } catch (IOException e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
        throw new ServletException(e);
    }
}

From source file:net.cit.tetrad.resource.SubResource.java

/**
 *  ?  ??  json //from w  ww . j  ava 2s.  co m
 * @param dto
 * @return
 * @throws Exception
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@RequestMapping("/subGraphList.do")
public void subGraphList(HttpServletRequest request, HttpServletResponse response, CommonDto dto)
        throws Exception {
    log.debug("start - subGraphList()");

    //iDisplayStart iDisplayLength datatable? ??     
    int pageNumber = Integer.parseInt(Utility.isNullNumber(request.getParameter("iDisplayStart")));
    int nPerPage = Integer.parseInt(Utility.isNullNumber(request.getParameter("iDisplayLength")));
    log.debug("pageNumber=" + pageNumber + ", nPerPage=" + nPerPage);

    Enumeration parameter = request.getParameterNames();
    log.debug(parameter.toString());
    while (parameter.hasMoreElements()) {
        String pName = (String) parameter.nextElement();
        String pValue = request.getParameter(pName);
        log.debug(pName + " = " + pValue);
    }

    GraphDefInfo gdInfo = subDao.getGraphDefInfoForSubGraph(dto);
    GraphDto graphDto = getSubGraphList(gdInfo, dto);

    List<Object> statusList = (List<Object>) graphDto.getStatusListObj();
    int cnt = statusList.size();
    Class<?> classname;
    if (dto.getDsname().equals("db")) {
        classname = DbStatus.class;
    } else {
        classname = ServerStatus.class;
    }

    try {
        int sEcho = Integer.parseInt(Utility.isNullNumber(request.getParameter(REQ_SECHO)));

        PersonJson result = setPersonJson(cnt, sEcho, pageNumber, nPerPage, statusList);
        JSONObject jsonObject = JSONObject.fromObject(result);

        Writer writer = setResponse(response).getWriter();
        writer.write(jsonObject.toString());

        log.debug(jsonObject.toString());
        writer.flush();
    } catch (Exception e) {
        log.error(e, e);
    }

    log.debug("end - subGraphList()");

}

From source file:com.microsoftopentechnologies.intellij.helpers.azure.AzureRestAPIManager.java

@Override
public void downloadAPIScript(UUID subscriptionId, String serviceName, String scriptName, String downloadPath)
        throws AzureCmdException {
    try {//w  w  w  .  j  av  a 2 s . c o m
        String apiName = scriptName.split("\\.")[0];

        String path = String.format("/%s/services/mobileservices/mobileservices/%s/apis/%s/script",
                subscriptionId.toString(), serviceName, apiName);
        String script = AzureRestAPIHelper.getRestApiCommand(path, subscriptionId.toString());

        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(downloadPath), "utf-8"));
        writer.write(script);
        writer.flush();
        writer.close();
    } catch (Exception e) {
        throw new AzureCmdException("Error getting API list", e);
    }
}

From source file:com.microsoftopentechnologies.intellij.helpers.azure.AzureRestAPIManager.java

@Override
public void downloadTableScript(UUID subscriptionId, String serviceName, String scriptName, String downloadPath)
        throws AzureCmdException {
    try {/*from   w w w  .  j  a  v  a  2s .c  o m*/
        String tableName = scriptName.split("\\.")[0];
        String operation = scriptName.split("\\.")[1];

        String path = String.format("/%s/services/mobileservices/mobileservices/%s/tables/%s/scripts/%s/code",
                subscriptionId.toString(), serviceName, tableName, operation);
        String script = AzureRestAPIHelper.getRestApiCommand(path, subscriptionId.toString());

        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(downloadPath), "utf-8"));
        writer.write(script);
        writer.flush();
        writer.close();
    } catch (Exception e) {
        //On error, create script for template
    }
}

From source file:com.microsoftopentechnologies.intellij.helpers.azure.AzureRestAPIManager.java

@Override
public void downloadJobScript(UUID subscriptionId, String serviceName, String scriptName, String downloadPath)
        throws AzureCmdException {
    try {/*www.  j  a va 2s.c om*/
        String jobName = scriptName.split("\\.")[0];

        String path = String.format("/%s/services/mobileservices/mobileservices/%s/scheduler/jobs/%s/script",
                subscriptionId.toString(), serviceName, jobName);
        String script = AzureRestAPIHelper.getRestApiCommand(path, subscriptionId.toString());

        Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(downloadPath), "utf-8"));
        writer.write(script);
        writer.flush();
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
        //On error, create script for template
    }
}

From source file:net.cit.tetrad.resource.GraphResource.java

@RequestMapping("/getStateLst.do")
public void getStateLst(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String checkState = request.getParameter("checkState");
    try {//from w  w  w  .  j  av a  2s .c o m
        PersonJson result = new PersonJson();
        if (checkState.equals("master")) {
            result.setAaData(masterLst);
        } else if (checkState.equals("slave")) {
            result.setAaData(slaveLst);
        }
        JSONObject jsonObject = JSONObject.fromObject(result);

        Writer writer = setResponse(response).getWriter();
        writer.write(jsonObject.toString());
        writer.flush();
    } catch (Exception e) {
        log.error(e, e);
    }
}

From source file:net.cit.tetrad.resource.GraphResource.java

@RequestMapping("/checkAlarmDevice.do")
public void checkAliveDevice(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int deviceCode = Integer.parseInt(request.getParameter("deviceCode"));

    int result = 1;
    if (!deviceCheck(deviceCode)) {
        result = -1;/* ww  w  .  j  a  v  a  2  s.c  om*/
    }

    Writer writer = setResponse(response).getWriter();
    writer.write(result + "");

    log.debug(result);
    writer.flush();
}