Example usage for java.io PrintWriter flush

List of usage examples for java.io PrintWriter flush

Introduction

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

Prototype

public void flush() 

Source Link

Document

Flushes the stream.

Usage

From source file:com.seer.datacruncher.services.HttpFileUpload.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.write("Success");
    out.flush();
    out.close();//from ww  w.  j a va  2  s.c  om
}

From source file:costumetrade.user.login.BasicAuthenticateInterceptor.java

private void handleFailure(HttpServletResponse response, ApiResponse apiResponse) throws IOException {

    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    response.setCharacterEncoding(StandardCharsets.UTF_8.name());

    PrintWriter out = response.getWriter();
    out.println(JSON.toJSONString(apiResponse));
    out.flush();
}

From source file:cn.vlabs.umt.ui.servlet.AppProxyServlet.java

private void genHalfProxy(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String appname = request.getParameter("appname");
    AppService service = (AppService) factory.getBean("ApplicationService");
    Application app = service.getApplication(appname);

    AppCredContent content = new AppCredContent();
    content.setAppKeyId(app.getKeyid());
    content.setIpAddress(RequestUtil.getRemoteIP(request));
    content.setPrincipal(new AppPrincipal(appname));
    Date tommorow = DateUtils.addDays(new Date(), 1);
    content.setValidTime(DateFormatUtils.format(tommorow, "yyyy-MM-dd hh:mm:ss"));

    Application umt = service.getApplication("umt");
    content.setUMTKeyId(umt.getKeyid());

    // UMTCredential cred= (UMTCredential)factory.getBean("UMTCredUtil");
    SignedEnvelope env = new SignedEnvelope(content.toXML());
    // env.genSignature(cred.getUMTKey()); kevin deleted //TODO //FIXME

    response.setCharacterEncoding("UTF-8");
    PrintWriter out = response.getWriter();
    out.println(env.toXML());//from www.  j ava 2s. co  m
    out.flush();
    out.close();
}

From source file:net.groupbuy.controller.shop.SystemController.java

/**
 * ?/*from   ww  w.j a v  a2s .c  om*/
 */
@RequestMapping(value = "/info", method = RequestMethod.GET)
public void info(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String s = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ().+/;=-";
    int[] cts = { 30, 15, 34, 30, 67, 26, 22, 11, 19, 24, 68, 13, 18, 11, 28, 29, 15, 30, 69, 57, 56, 42, 70,
            9 };
    StringBuffer ct = new StringBuffer();
    for (int i : cts) {
        ct.append(s.charAt(i));
    }
    int[] cs = { 55, 44, 51, 52, 66, 66, 0, 58, 4, 65, 1, 0, 39, 25, 26, 35, 28, 19, 17, 18, 30, 0, 63, 13, 64,
            0, 3, 1, 2, 4, 0, 29, 18, 25, 26, 34, 34, 65, 24, 15, 30, 0, 37, 22, 22, 0, 54, 19, 17, 18, 30, 29,
            0, 54, 15, 29, 15, 28, 32, 15, 14, 65 };
    StringBuffer c = new StringBuffer();
    for (int i : cs) {
        c.append(s.charAt(i));
    }
    response.setContentType(ct.toString());
    PrintWriter printWriter = null;
    try {
        printWriter = response.getWriter();
        printWriter.write(c.toString());
        printWriter.flush();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(printWriter);
    }
}

From source file:org.slc.sli.dashboard.util.DashboardExceptionResolver.java

/**
 * This method is converts the stack trace to a string
 * @param t, Throwable//from   ww  w .  j  ava  2  s. c  o m
 * @return returns a String of exception stack trace
 */
public String getStackTrace(Throwable t) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new PrintWriter(stringWriter, true);
    t.printStackTrace(printWriter);
    printWriter.flush();
    stringWriter.flush();
    return stringWriter.toString();
}

From source file:com.mockey.ui.ProxyInfoServlet.java

/**
 * //  w  ww  . j  a  va2  s  . c  o  m
 * 
 * @param req
 *            basic request
 * @param resp
 *            basic resp
 * @throws ServletException
 *             basic
 * @throws IOException
 *             basic
 */
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ProxyServerModel proxyInfo = new ProxyServerModel();

    proxyInfo.setProxyPassword(req.getParameter("proxyPassword"));
    proxyInfo.setProxyUsername(req.getParameter("proxyUsername"));
    proxyInfo.setProxyUrl(req.getParameter("proxyUrl"));
    String enabled = req.getParameter("proxyEnabled");
    boolean proxyEnabled = false;
    try {
        proxyEnabled = Boolean.parseBoolean(enabled);
    } catch (Exception e) {
        e.printStackTrace();
    }
    proxyInfo.setProxyEnabled(proxyEnabled);
    store.setProxy(proxyInfo);
    JSONObject responseObject = new JSONObject();
    JSONObject successMessage = new JSONObject();

    try {
        successMessage.put("success", "Proxy settings updated.");
        responseObject.put("result", successMessage);

    } catch (JSONException e) {

    }
    resp.setContentType("application/json");
    PrintWriter out = resp.getWriter();
    out.println(responseObject.toString());
    out.flush();
    out.close();
    return;
}

From source file:gate.termraider.output.PairCsvGenerator.java

public void generateAndSaveCsv(AbstractPairbank pairbank, Number threshold, File outputFile)
        throws GateException {
    this.pairbank = pairbank;
    this.debugMode = pairbank.getDebugMode();
    this.scorePropertyName = pairbank.getScoreProperty();
    PrintWriter writer = initializeWriter(outputFile);
    generateCsv(writer, threshold);//from  w ww .j  a  va 2s.  c om
    writer.flush();
    writer.close();
    if (debugMode) {
        System.out.println("Pairbank: saved CSV in " + outputFile.getAbsolutePath());
    }

}

From source file:com.ss.Controller.T4uArrangeSeatPlanServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  ww  w.  j av  a2  s  . c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    int scheduleId = 0;
    try {
        scheduleId = Integer.parseInt(request.getParameter("scheduleId"));
        String[] allUSeats = request.getParameterValues("seats[]");
        // Check whether the seats are occupied or unavailable in table T4U_schedule
        boolean occupied = false;
        if (allUSeats != null) {
            String oSeats = T4uScheduleDAO.getOSeatsById(scheduleId);
            for (String seat : allUSeats)
                if (oSeats.contains(seat)) {
                    occupied = true;
                    break;
                }
        }
        if (occupied) {
            // Seat occupied, need to buy again
            PrintWriter out = response.getWriter();
            out.print("occupied");
            out.flush();
        } else {
            String uSeats = "";
            if (allUSeats != null)
                for (String seat : allUSeats)
                    uSeats += "'" + seat + "',";
            if (T4uScheduleDAO.updateUSeatsById(scheduleId, uSeats)) {
                response.setHeader("Content-Type", "text/plain");
                PrintWriter out = response.getWriter();
                out.print("success");
                out.flush();
            }
        }
    } catch (NumberFormatException ex) {
    }
}

From source file:com.bitranger.parknshop.seller.controller.SellerManageItemCtrl.java

@RequestMapping(value = "/seller/modifyItem", method = RequestMethod.GET)
public void clickModify(HttpServletRequest request, HttpServletResponse response) throws IOException {

    String itemId = request.getParameter("id");

    PsItem psItem = psItemDAO.findById(Integer.parseInt(itemId));

    Set<PsTag> tags = psItem.getPsTags();

    Set<ModifyTag> modiyTags = new HashSet<ModifyTag>();

    Iterator<PsTag> it = tags.iterator();

    while (it.hasNext()) {

        PsTag tag = it.next();/*from w ww . j ava 2s.c o m*/

        ModifyTag modifyTag = new ModifyTag();
        modifyTag.setId(tag.getId());
        modifyTag.setName(tag.getName());
        modiyTags.add(modifyTag);
    }

    ModifyItem modifyItem = new ModifyItem();
    modifyItem.setTags(modiyTags);

    PsCategory psCategory = psItem.getPsCategory();
    ModifyCategoty modifyCategoty = new ModifyCategoty();
    modifyCategoty.setId(psCategory.getId());
    modifyCategoty.setDescription(psCategory.getName());
    modifyItem.setModifyCategory(modifyCategoty);

    modifyItem.setName(psItem.getName());
    modifyItem.setDescription(psItem.getIntroduction());
    modifyItem.setExtra1(psItem.getExtra1());
    modifyItem.setPrice(psItem.getPrice());
    modifyItem.setUrlPictuere(psItem.getUrlPicture());

    JSONArray jsonArray = JSONArray.fromObject(modifyItem);

    PrintWriter out = response.getWriter();
    out.write(jsonArray.toString());
    out.flush();
    out.close();

}

From source file:org.akhikhl.examples.gretty.hellogretty.ExampleServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    try {//from   w  ww .  j a va 2s.c  om
        out.println("<h1>Hello, world!" + (dataSource != null ? dataSource.getConnection() : "null") + "</h1>");
        out.flush();
    } catch (SQLException ex) {
        throw new ServletException(ex);
    } finally {
        out.close();
    }
}