Example usage for java.io PrintWriter print

List of usage examples for java.io PrintWriter print

Introduction

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

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

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

public void run() {
    try {/*from w w  w  .  j  a  va  2 s .c o m*/
        BufferedReader br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        PrintWriter pw = new PrintWriter(clientSocket.getOutputStream());

        pw.print(PROMPT);
        pw.flush();

        while (true) {
            String command = br.readLine();

            if ("status".equals(command)) {
                pw.println(CheaterConstant.STATUS_MAP.get(server.getCheater().getCurrentStatus()));
                pw.print(PROMPT);
                pw.flush();
            } else if ("help".equals(command)) {
                pw.println("status    to show current status of cheater");
                pw.println("quit      to quit administration connection");
                pw.println("shutdown  to shutdown cheater");
                pw.println("help      to show this message");
                pw.print(PROMPT);
                pw.flush();
            } else if ("shutdown".equals(command)) {
                clientSocket.close();
                server.stop();
                server.getCheater().stop();

                break;
            } else if ("quit".equals(command) || command == null) {
                server.setHasClient(false);
                clientSocket.close();

                break;
            } else {
                pw.println(new StringBuilder("Unknown command,").append(" use \"status|quit|shutdown|help\".")
                        .toString());
                pw.print(PROMPT);
                pw.flush();
            }
        }
    } catch (IOException e) {
        LOG.error("Error operating client socket.", e);
    } finally {
        try {
            clientSocket.close();
        } catch (IOException e) {
            LOG.error("Error closing client socket.", e);
        }
    }
}

From source file:com.ponysdk.core.export.xml.XMLExporter.java

public void exportXMLString(final String fileName, final String content) throws Exception {
    // Set MIME type to binary data to prevent opening of PDF in browser window
    UIContext.get().stackStreamRequest((req, response) -> {
        response.reset();//from   ww w.  ja v  a 2 s .c o  m
        response.setContentType("application/xml");
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        PrintWriter printer;
        try {
            printer = response.getWriter();
            printer.print(content);
            printer.flush();
            printer.close();
        } catch (final IOException e) {
            log.error("Error when exporting", e);
        }
    });
}

From source file:Json.Type.java

public Type(String type) {
    JSONObject obj = new JSONObject();
    obj.put("type", type);
    File file = new File("type");

    try {//ww w  .j  a  va 2s . c  om
        //?,  ?   ??  ? 
        if (!file.exists()) {
            file.createNewFile();
        }

        //PrintWriter ? ? ?  
        PrintWriter out = new PrintWriter(file.getAbsoluteFile());

        try {
            //? ?  
            out.print(obj);
        } finally {
            //?     
            //   ??
            out.close();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.buaa.cfs.conf.ReconfigurationServlet.java

private void printFooter(PrintWriter out) {
    out.print("</body></html>\n");
}

From source file:me.tfeng.toolbox.dust.NodeEngine.java

private void printRenderScript(PrintWriter writer, String template, String json) {
    writer.print("(function(){var v; dust.render('");
    writer.print(StringEscapeUtils.escapeJson(template));
    writer.print("', JSON.parse('");
    writer.print(StringEscapeUtils.escapeJson(json));
    writer.print("'), function(err, data) {v = data;}); return v})()");
}

From source file:be.fedict.eid.idp.sp.ConfigServlet.java

private void addTextInput(PrintWriter out, String label, String name, String value) {

    out.print(label + "&nbsp; &nbsp;");
    String valueString = null != value ? value : "";
    out.println("<input type=\"text\" size=\"40\" name=\"" + name + "\" value=\"" + valueString + "\" />");
    out.println("<br />");
}

From source file:com.aptechfpt.controller.InsertSalePerson.java

private void checkEmail(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String email = request.getParameter("value");
    boolean isExisted = accountFacade.isExistedEmail(email);
    response.setContentType("application/json");
    PrintWriter out = response.getWriter();
    out.print(!isExisted);
    out.close();/*from   www . jav  a  2s  .  co m*/
}

From source file:it.cilea.osd.jdyna.web.controller.ExportConfigurazioneSoggettari.java

/**
 * Metodo di supporto per esportare un soggettario nella sua
 * "bean definition". /*from  w w w. j av  a 2  s  . co m*/
 * 
 * @param writer
 * @param soggettario
 *            l'albero da esportare
 */
//FIXME valutare la possibilita' di utilizzare il polimorfismo implementando un'interfaccia IExportableBeanDefinition
private void toXML(PrintWriter writer, Soggettario soggettario) {
    writer.print("    <bean id=\"" + Soggettario.class.getSimpleName() + soggettario.getId() + "\" class=\""
            + Soggettario.class.getCanonicalName() + "\">\n");
    writer.print("               <property name=\"nome\" value=\"" + soggettario.getNome() + "\" />\n");
    writer.print("               <property name=\"attivo\" value=\"" + soggettario.isAttivo() + "\" />\n");
    writer.print("               <property name=\"chiuso\" value=\"" + soggettario.isChiuso() + "\" />\n");

    if (soggettario.getDescrizione() != null) {
        writer.print("               <property name=\"descrizione\"><value><![CDATA["
                + soggettario.getDescrizione() + "]]></value></property>\n");
    }

    writer.print("    </bean>\n\n");
    writer.print("    <!-- Soggetti del soggettario:" + soggettario.getNome() + " -->\n\n");

    for (Soggetto classificazione : soggettario.getSoggetti()) {
        toXML(writer, classificazione);
    }
    writer.print("    <!-- FINE Soggetti del soggettario:" + soggettario.getNome() + " -->\n\n");

}

From source file:be.fedict.eid.idp.sp.ConfigServlet.java

private void addCheckbox(PrintWriter out, String label, String name, boolean checked) {

    out.print(label + "&nbsp; &nbsp;");
    if (checked) {
        out.println("<input type=\"checkbox\" name=\"" + name + "\" value=\"" + name + "\" checked=\"yes\" />");
    } else {//from  ww  w. java2  s  . c  om
        out.println("<input type=\"checkbox\" name=\"" + name + "\" value=\"" + name + "\" />");
    }
    out.println("<br />");
}

From source file:com.amazon.alexa.avs.FileDataStore.java

public synchronized void writeToDisk(T payload, final ResultListener<T> listener) {
    sExecutor.execute(new Runnable() {
        @Override//  w w w  . j  a  v a2s  . c o m
        public void run() {
            ObjectWriter writer = ObjectMapperFactory.getObjectWriter();
            PrintWriter out = null;
            try {
                out = new PrintWriter(file);
                out.print(writer.writeValueAsString(payload));
                out.flush();
                listener.onSuccess(payload);
            } catch (IOException e) {
                log.error("Failed to write to disk", e);
                listener.onFailure();
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    });
}