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.log4ic.compressor.utils.Compressor.java

/**
 * ??/*from  w w w  . ja va 2s.co  m*/
 *
 * @param code
 * @param type
 * @param response
 * @throws com.log4ic.compressor.exception.CompressionException
 *
 */
private static void writeOutCode(String code, FileType type, HttpServletResponse response)
        throws CompressionException {
    //mine type
    try {
        switch (type) {
        case JS:
            response.setContentType("text/javascript");
            break;
        case CSS:
        case GSS:
        case LESS:
        case MSS:
            response.setContentType("text/css");
            break;
        default:
            response.setContentType("text/html");
        }
        PrintWriter writer = response.getWriter();
        writer.write(code);
        writer.flush();
        response.flushBuffer();
    } catch (IOException e) {
        throw new CompressionException("Write code to client error.", e);
    }
}

From source file:org.keycloak.testsuite.ApplicationServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String title = "";
    if (req.getRequestURI().endsWith("auth")) {
        title = "AUTH_RESPONSE";
    } else if (req.getRequestURI().endsWith("logout")) {
        title = "LOGOUT_REQUEST";
    } else {/*from ww w  .j  av  a 2 s.c o m*/
        title = "APP_REQUEST";
    }

    PrintWriter pw = resp.getWriter();
    pw.printf("<html><head><title>%s</title></head><body>", title);

    pw.printf(LINK, "http://localhost:8081/auth/rest/realms/test/account", "account", "account");

    pw.print("</body></html>");
    pw.flush();
}

From source file:com.zb.app.common.component.ComponentController.java

@ExceptionHandler(Throwable.class)
public ModelAndView handleIOException(Throwable e) throws Throwable {

    if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) {
        throw e;/*from  ww  w . j  a va 2 s.  c om*/
    }

    if (request == null && response == null) {
        throw e;
    }

    if (request == null && response != null) {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        OutputStream out = response.getOutputStream();
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "utf-8"));
        pw.println("{\"code\":1,\"msg\":\",?!\",\"data\":\"\"}");
        pw.flush();
        pw.close();
    }

    ModelAndView mav = new ModelAndView();
    if (InvokeTypeTools.isAjax(request)) {
        return createJsonMav("server exceptin or error", ResultCode.ERROR, e.getMessage());
    }

    mav.addObject("exception", e.getCause() == null ? StringUtils.EMPTY : e.getCause().toString());
    mav.addObject("msg", StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage());
    mav.addObject("stackTrace", e.getStackTrace().toString());
    if (request.getRequestURI() != null) {
        mav.addObject("url", request.getRequestURI().toString());
    }
    mav.setViewName("error");
    return mav;
}

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

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

    PsSeller seller = (PsSeller) request.getSession().getAttribute("currentSeller");
    if (seller == null) {
        //         http://bowen_ultimate:8080/C1_ParknShop/seller/sellerlogin
        response.sendRedirect("/C1_ParknShop/sellerLogin.jsp");
        return;/*from  www.  j a  va2 s . c o m*/
    }

    Set<PsShop> shops = seller.getPsShops();
    Iterator<PsShop> it = shops.iterator();
    List<PsOrder> orders = new ArrayList<PsOrder>();
    List<SellerOrderDisplay> orderDisplays = new ArrayList<SellerOrderDisplay>();

    //List<ROrderItem> orderItems = new ArrayList<ROrderItem>();

    while (it.hasNext()) {
        PsShop shop = it.next();
        orders.addAll(psOrderDao.findByShopId(shop.getId()));
    }

    for (PsOrder order : orders) {

        Iterator<ROrderItem> iterator = order.getROrderItems().iterator();
        while (iterator.hasNext()) {

            ROrderItem orderItem = iterator.next();

            SellerOrderDisplay sellerOrderDisplay = new SellerOrderDisplay();
            sellerOrderDisplay.setId(order.getId());
            sellerOrderDisplay.setItemPic(orderItem.getPsItem().getUrlPicture());
            sellerOrderDisplay.setItemName(orderItem.getPsItem().getName());
            sellerOrderDisplay.setSoldTime(order.getTimeCreated());
            sellerOrderDisplay.setPrice(orderItem.getPsItem().getPrice());
            sellerOrderDisplay.setQuantity(orderItem.getQuantitiy());
            sellerOrderDisplay.setBuyerName(order.getPsCustomer().getName());
            sellerOrderDisplay.setState(order.getStatus());
            sellerOrderDisplay.setAddress(order.getPsRecipient().getAddresss());
            sellerOrderDisplay.setPhone(order.getPsRecipient().getPhoneNumber());

            orderDisplays.add(sellerOrderDisplay);
        }
        //orderItems.addAll(iROrderItemDAO.findByOrderId(order.getId()));
    }

    System.out.println(orderDisplays.size());

    /*JsonConfig jsonConfig = new JsonConfig();
     jsonConfig.setIgnoreDefaultExcludes(false);
    jsonConfig.setExcludes(new String[]{"psShop"});
    jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);*/

    /*jsonConfig.registerJsonValueProcessor(ROrderItem.class,
    new ObjectJsonValueProcessor(new String[]{"quantity"}, ROrderItem.class));*/

    JSONArray jsonArray = JSONArray.fromObject(orderDisplays);

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

}

From source file:org.clothocad.phagebook.controllers.AutoCompleteController.java

@RequestMapping(value = "/autoComplete", method = RequestMethod.GET)
protected void autoComplete(@RequestParam Map<String, String> params, HttpServletResponse response)
        throws ServletException, IOException {

    //I WILL RETURN THE MAP AS A JSON OBJECT.. it is client side's issue to parse all data for what they need!
    //they could check over there if the schema matches what they are querying for and so i can do this generically!
    //user should be logged in so I will log in as that user.
    String query = params.get("query") != null ? params.get("query") : "";
    boolean isValid = false;
    System.out.println("Query is: " + query);
    if (!query.equals("")) {
        isValid = true;/*from  w ww  .  j  a va 2 s .  c o  m*/
    }

    if (isValid) {
        ClothoConnection conn = new ClothoConnection(Args.clothoLocation);
        Clotho clothoObject = new Clotho(conn);
        //TODO: we need to have an authentication token at some point
        String username = this.backendPhagebookUser;
        String password = this.backendPhagebookPassword;
        Map loginMap = new HashMap();
        loginMap.put("username", username);
        loginMap.put("credentials", password);

        clothoObject.login(loginMap);

        JSONArray replies = (JSONArray) clothoObject.autocomplete(query);
        conn.closeConnection();
        response.setStatus(HttpServletResponse.SC_ACCEPTED);
        response.setContentType("application/json");
        PrintWriter out = response.getWriter();
        out.print(replies);
        out.flush();
        out.close();

        clothoObject.logout();

    }
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    response.setContentType("application/json");
    JSONObject reply = new JSONObject();
    reply.put("message", "Auto Complete requires a query parameter");
    PrintWriter out = response.getWriter();
    out.print(reply);
    out.flush();
    out.close();

}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.servlet.ConfigServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse response)
        throws ServletException, IOException {
    LOGGER.trace("doGet : Getting MMX Configuration");
    response.setContentType(CONTENT_TYPE_JSON);
    PrintWriter out = response.getWriter();
    SerializableConfig sconfig = new SerializableConfig(MMXConfiguration.getConfiguration());
    GsonData.getGson().toJson(sconfig, out);
    out.flush();
    response.setStatus(HttpServletResponse.SC_OK);
    return;//from   w w  w .j ava2 s .co m
}

From source file:it.jnrpe.server.console.PluginCommand.java

public void printHelp() throws IOException {
    Group g = getCommandLineGroup();

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    HelpFormatter hf = new HelpFormatter("  ", null, null, getConsole().getTerminal().getWidth());
    hf.setGroup(g);/*from  w  w w  .  j a  v  a2 s. c  o m*/

    PrintWriter pw = new PrintWriter(new OutputStreamWriter(bout, charset));
    hf.setPrintWriter(pw);
    hf.printHelp();

    pw.flush();

    // getConsole().println("\u001B[1mCommand Line:\u001B[0m ");
    getConsole().println(highlight("Command Line: "));
    getConsole().println("  " + getName() + " " + getCommandLine());
    getConsole().println(highlight("Usage:"));
    getConsole().println(new String(bout.toByteArray(), charset));

}

From source file:com.honnix.cheater.admin.AdminServer.java

public void run() {
    while (true) {
        synchronized (lock) {
            if (!isStarted) {
                break;
            }//w ww. ja  v  a 2s  . c  o  m
        }

        Socket clientSocket = null;

        try {
            clientSocket = serverSocket.accept();
        } catch (SocketException e) {
            // Here we can assume that if there is SocketException, it means
            // the socket has been closed.
            break;
        } catch (IOException e) {
            LOG.error("Failed accepting admin socket connection.", e);

            continue;
        }

        if (hasClient) {
            try {
                PrintWriter pw = new PrintWriter(clientSocket.getOutputStream());

                pw.println("Someone else is administrating me.");
                pw.flush();

                clientSocket.close();
            } catch (IOException e) {
                LOG.warn("Error operating client socket.", e);
            }
        } else {
            hasClient = true;

            new AdminClient(this, clientSocket).start();
        }
    }
}

From source file:com.kdab.daytona.Logger.java

@Override
public void doPut(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (m_error) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        PrintWriter out = response.getWriter();
        out.println("Daytona not operational. See server log for details.");
        out.flush();
        out.close();/*from   w w  w .j a  v  a2s .co  m*/
        return;
    }

    String format = request.getParameter("format");
    if (format == null)
        format = "xml";

    if (!m_queuesByFormat.containsKey(format)) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        PrintWriter out = response.getWriter();
        out.println(String.format("Unknown format \'%s\'.", format));
        out.flush();
        out.close();
        return;
    }

    byte[] ba = IOUtils.toByteArray(request.getInputStream());
    try {
        m_queuesByFormat.get(format).put(ba);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }

    PrintWriter out = response.getWriter();
    out.println("Message received.");
    out.flush();
    out.close();
}

From source file:io.milton.cloud.server.apps.contacts.ContactResource.java

public void writeData(OutputStream out) {
    String s = contactManager.getContactAsCarddav(contact);
    PrintWriter pw = new PrintWriter(out);
    pw.print(s);//from w w  w .j a  v  a  2  s.c om
    pw.flush();

}