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.logiclander.jaasmine.authentication.http.SimpleLogoutServlet.java

/**
 * Writes a plain text message to the HttpServletResponse.
 *
 * @param resp the HttpServletResponse./*  w w w  .  j  a v a 2s  .com*/
 * @throws ServletException If a ServletException is thrown.
 * @throws IOException if an I/O error occurs.
 */
private void sendPlainTextResponse(HttpServletResponse resp) throws ServletException, IOException {

    resp.setContentType("text/plain");
    PrintWriter w = resp.getWriter();
    w.println("You have been logged out");

    w.flush();
}

From source file:be.solidx.hot.web.deprecated.ScriptExecutorController.java

public String handleScriptPOST(WebRequest webRequest, String scriptName, Writer writer) {
    try {// w  w  w  .  jav a  2  s .co m
        scriptName = scriptName + getScriptExtension();
        Script<COMPILED_SCRIPT> script = buildScript(IOUtils.toByteArray(loadResource(scriptName)), scriptName);
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        Object result = scriptExecutor.execute(script, webRequest, dbMap, printWriter);
        printWriter.flush();
        stringWriter.flush();
        if (result == null)
            throw new Exception("POST handling scripts must return a page URL to redirect to");
        return "redirect:/" + (String) result;
    } catch (Exception e) {
        printErrorPage(e, writer);
        return null;
    }
}

From source file:ch.epfl.lsir.xin.algorithm.baseline.GlobalAverage.java

@Override
public void saveModel(String file) {
    // TODO Auto-generated method stub
    try {/*from ww w. ja  v a  2  s . c o  m*/
        PrintWriter printer = new PrintWriter(file);
        printer.println(this.mean);
        printer.flush();
        printer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:de.mpg.escidoc.pubman.sword.PubManServiceDocumentServlet.java

/**
 * Process the GET request./*  w w w  . j a  v a 2  s .  c  om*/
 * @param HttpServletRequest
 * @param HttpServletResponse
 * @throws ServletException
 * @throws IOException
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Create the ServiceDocumentRequest
    ServiceDocumentRequest sdr = new ServiceDocumentRequest();
    SwordUtil util = new SwordUtil();
    AccountUserVO user = null;

    String usernamePassword = this.getUsernamePassword(request);
    if ((usernamePassword != null) && (!usernamePassword.equals(""))) {
        int p = usernamePassword.indexOf(":");
        if (p != -1) {
            sdr.setUsername(usernamePassword.substring(0, p));
            sdr.setPassword(usernamePassword.substring(p + 1));
            user = util.getAccountUser(sdr.getUsername(), sdr.getPassword());
            this.currentUser = user;
        }
    } else {
        String s = "Basic realm=\"SWORD\"";
        response.setHeader("WWW-Authenticate", s);
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return;
    }

    try {
        String doc = this.swordServer.doServiceDocument(sdr);
        this.currentUser = null;

        // Print out the Service Document
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/xml");
        PrintWriter out = response.getWriter();
        out.write(doc);
        out.flush();
    } catch (SWORDAuthenticationException sae) {
        response.setHeader("WWW-Authenticate", sae.getLocalizedMessage());
        response.setStatus(401);
        response.setCharacterEncoding("UTF-8");
        this.currentUser = null;
    } catch (Exception e) {
        this.log.error(e);
    }
}

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

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    out.println("Use PUT to deliver content to notify");
    out.flush();
    out.close();//from ww w .  java  2  s  . c o m
}

From source file:com.norconex.collector.core.AbstractCollectorLauncher.java

public void launch(String[] args) {
    CommandLine cmd = parseCommandLineArguments(args);
    String action = cmd.getOptionValue(ARG_ACTION);
    File configFile = new File(cmd.getOptionValue(ARG_CONFIG));
    File varFile = null;//from   w w w.j a v  a2  s  . c  o m
    if (cmd.hasOption(ARG_VARIABLES)) {
        varFile = new File(cmd.getOptionValue(ARG_VARIABLES));
    }

    try {
        if (!configFile.isFile()) {
            System.err.println("Invalid configuration file path: " + configFile.getAbsolutePath());
            System.exit(-1);
        }
        if (varFile != null && !varFile.isFile()) {
            System.err.println("Invalid variable file path: " + configFile.getAbsolutePath());
            System.exit(-1);
        }

        ICollectorConfig config = new CollectorConfigLoader(getCollectorConfigClass())
                .loadCollectorConfig(configFile, varFile);
        ICollector collector = createCollector(config);
        if (ARG_ACTION_START.equalsIgnoreCase(action)) {
            collector.start(false);
        } else if (ARG_ACTION_RESUME.equalsIgnoreCase(action)) {
            collector.start(true);
        } else if (ARG_ACTION_STOP.equalsIgnoreCase(action)) {
            collector.stop();
        }
    } catch (Exception e) {
        PrintStream err = System.err;
        File errorFile = new File("./error-" + System.currentTimeMillis() + ".log");
        err.println("\n\nAn ERROR occured:\n\n" + e.getLocalizedMessage());
        err.println("\n\nDetails of the error has been stored at: " + errorFile.getAbsolutePath() + "\n\n");
        try {
            PrintWriter w = new PrintWriter(errorFile, CharEncoding.UTF_8);
            e.printStackTrace(w);
            w.flush();
            w.close();
        } catch (FileNotFoundException | UnsupportedEncodingException e1) {
            err.println("\n\nCannot write error file. " + e1.getLocalizedMessage());
        }
        System.exit(-1);
    }
}

From source file:jp.aegif.liferay.experiment.mryoshio.rr.RoomPortlet.java

@Override
public void serveResource(ResourceRequest req, ResourceResponse res) throws IOException, PortletException {

    if (logger.isDebugEnabled())
        debug(req);//from   w ww .  ja  v a2s  . co  m

    try {
        String rid = req.getResourceID();
        PortletBag pbag = PortletBagPool.get(PortalUtil.getPortletId(req));
        String ajaxResponse = null;

        if ("add-view".equals(rid) || "update-view".equals(rid)) {
            ajaxResponse = PortalUtil.renderPage(pbag.getServletContext(),
                    PortalUtil.getHttpServletRequest(req), PortalUtil.getHttpServletResponse(res), editJSP,
                    false);
        } else if ("list-view".equals(rid)) {
            ajaxResponse = getListDataAsJson(Integer.parseInt(req.getParameter("itemPerPage")),
                    Integer.parseInt(req.getParameter("targetPage")));
        } else if ("update-room".equals(rid)) {
            updateRoom(req);
        } else if ("delete-room".equals(rid)) {
            deleteRoom(req);
        } else {
            ajaxResponse = ERR_NO_TYPE_SPECIFIED;
        }
        PrintWriter writer = res.getWriter();
        writer.write(ajaxResponse);
        writer.flush();
        writer.close();
    } catch (ServletException e) {
        throw new PortletException(e);
    }
}

From source file:com.controlj.green.istat.web.TreeServlet.java

public void writeLevel(final ServletOutputStream out, final String location, HttpServletRequest req)
        throws IOException, SystemException, ActionExecutionException, InvalidConnectionRequestException {
    final JSONArray arrayData = new JSONArray();

    SystemConnection connection = DirectAccess.getDirectAccess().getUserSystemConnection(req);

    connection.runReadAction(new ReadAction() {
        public void execute(@NotNull SystemAccess access) throws Exception {
            Location parent;/*from   w  ww . ja  v a  2 s  .  c o m*/
            if (location == null || location.length() == 0) {
                parent = access.getGeoRoot();
            } else {
                parent = access.getGeoRoot().getTree().resolve(location);
            }
            Collection<Location> childrenLocs = parent.getChildren(LocationSort.PRESENTATION);
            HasDecendentAspectsAcceptor acceptor = new HasDecendentAspectsAcceptor(SetPoint.class,
                    SetPointAdjust.class);

            for (Location nextLoc : childrenLocs) {
                if (!acceptor.accept(nextLoc)) {
                    continue;
                }
                JSONObject next = new JSONObject();
                next.put("display", nextLoc.getDisplayName());
                next.put("id", nextLoc.getPersistentLookupString(false));
                next.put("area", (nextLoc.getType() == LocationType.Area));
                arrayData.put(next);
            }
        }
    });

    try {
        PrintWriter writer = new PrintWriter(out);
        arrayData.write(writer);
        writer.flush();
    } catch (JSONException e) {
        FileLogger logger = AddOnInfo.getAddOnInfo().getDateStampLogger();
        logger.println("Unexpected exception:");
        logger.println(e);
    }
}

From source file:mack.servlets.TransfServlet.java

private void geraXSL() throws IOException {
    HttpClient cliente = HttpClients.createDefault();
    HttpGet httpget = new HttpGet("http://localhost:8081/AppFrontController/dados/gpx.xsl");
    HttpResponse resposta = cliente.execute(httpget);
    System.out.println("----------------------------------------");
    System.out.println(resposta.getStatusLine());
    HttpEntity entity = resposta.getEntity();
    if (entity != null) {
        InputStream instream = entity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
        StringBuilder out = new StringBuilder();
        String line;/*w  w  w . j  av a2  s  . c  o  m*/
        while ((line = reader.readLine()) != null) {
            out.append(line);
        }
        PrintWriter w = new PrintWriter("/temp/gpx.xsl");
        w.print(out.toString());
        w.flush();
        w.close();
        reader.close();
        instream.close();
    }

}

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

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

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

    PsOrder psOrder = psOrderDao.findByOrderId(Integer.parseInt(recordId));

    psOrder.setStatus(OrderStatus.DELIVERING);

    psOrderDao.update(psOrder);/*from ww w  . ja va 2s. co  m*/

    PsNoticeCustomer n = new PsNoticeCustomer(psOrder.getPsCustomer(),
            new Timestamp(System.currentTimeMillis()), psOrder.getPsShop().getName(),
            "Order[" + psOrder.getId() + "] delivered", (short) 1);
    psNoticeCustomerDAO.save(n);

    try {
        PrintWriter out = response.getWriter();
        out.write("success");
        out.flush();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

}