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:guru.nidi.raml.doc.servlet.MirrorServlet.java

private void query(HttpServletRequest req, PrintWriter out) {
    out.println("query");
    for (Map.Entry<String, String[]> entry : req.getParameterMap().entrySet()) {
        out.print(entry.getKey() + ": ");
        for (String s : entry.getValue()) {
            out.print("'" + s + "', ");
        }//  www  .  j a v a  2 s  . c  o  m
        out.println();
    }
    out.println();
}

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 a v 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:be.fedict.eid.dss.webapp.IdentityServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LOG.debug("doGet");

    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();

    KeyStore.PrivateKeyEntry activeIdentity = identityService.findIdentity();
    if (null == activeIdentity) {

        out.print("No active identity eID DSS Identity configured.");

    } else {/* w  w  w  . ja  v a2s  .  co  m*/

        String pemCertificateChain;
        try {
            pemCertificateChain = toPem(activeIdentity.getCertificateChain());
        } catch (Exception e) {
            LOG.error(e);
            return;
        }
        out.print(pemCertificateChain);
    }

    out.close();
}

From source file:org.openmrs.module.logmanager.web.view.EventsExportView.java

/**
 * @see org.springframework.web.servlet.view.AbstractView
 *///from w ww.j  av a  2  s  .com
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    // Choose format
    String format = (String) model.get("format");
    Layout layout = null;
    if (format.equals("txt")) {
        layout = new PatternLayout(Constants.DEF_LAYOUT_CONVERSION_PATTERN);
        response.setContentType("text/plain");
    } else {
        layout = new XMLLayout();
        ((XMLLayout) layout).setLocationInfo(true);
        response.setContentType("text/xml");
    }

    response.setHeader("Content-Disposition", "attachment; filename=\"" + getFilename(model) + "\"");

    // Disable caching
    response.setHeader("Pragma", "No-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache");

    PrintWriter out = response.getWriter();

    // Write each logging event using the layout
    for (EventProxy event : (List<EventProxy>) model.get("events")) {
        out.print(layout.format(event.getTarget()));

        if (format.equals("txt") && event.isThrowableAttached()) {
            for (String line : event.getThrowableLines())
                out.println(line);
        }
    }
}

From source file:ob.servlet.getuserinfo.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  www .j  ava 2  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 {
    outinfo = null;
    String loginedUserName = (String) request.getSession().getAttribute("username");
    if (loginedUserName != null && !loginedUserName.equals("")) {
        int loginedUserid = (Integer) request.getSession().getAttribute("userid");
        po = dao.getinfo(loginedUserid);
        if (po != null) {
            if (po.getUsername().equals(loginedUserName)) {
                Iterator it = po.getTask().iterator();
                while (it.hasNext()) {
                    TaskPO taskpo = (TaskPO) it.next();
                    if (RunningTask.isHere(taskpo.getTid())) {
                        taskpo.setIsrunning(true);
                        taskpo.setStatus(RunningTask.getStatus(taskpo.getTid()));
                    }
                }
                FilterProvider filters = new SimpleFilterProvider()
                        .addFilter("userFilter",
                                SimpleBeanPropertyFilter.serializeAllExcept("password", "log", "sms"))
                        .addFilter("taskFilter", SimpleBeanPropertyFilter.filterOutAllExcept("tid", "taskname",
                                "ctime", "status", "isrunning"));//?password
                outinfo = mapper.writer(filters).writeValueAsString(po);//JSON
            }
        }
    } else {
        outinfo = "false";//
    }
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        /* TODO output your page here. You may use following sample code. */
        out.print(outinfo);
    } finally {
        out.close();
    }
}

From source file:dk.nsi.haiba.lprimporter.integrationtest.RulesEngineIT.java

private void clearBusinessRuleLogFile() {
    try {/*w ww .j a va2  s  .  c  o m*/
        PrintWriter writer = new PrintWriter(FileUtils.getFile("forretningsregel-fejl.log"));
        writer.print("");
        writer.close();
    } catch (FileNotFoundException e) {
        //ignore
        e.printStackTrace();
    }
}

From source file:de.viaboxx.nlstools.formats.BundleWriterJavaInterface.java

protected void writeType(PrintWriter pw) {
    pw.print("public interface ");
    pw.print(getIClass());
}

From source file:net.joinedminds.tools.evet.TimeValueTable.java

protected void generateJsonpResponse(StaplerResponse rsp) throws IOException {
    rsp.setContentType("text/javascript");
    PrintWriter out = rsp.getWriter();
    out.print("evet = ");
    JSONObject data = getJsonObject();/* ww  w. java2 s  .  c om*/
    data.write(out);
    out.print(";");
    out.flush();
}

From source file:com.google.appinventor.server.UploadServlet.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
    setDefaultHeader(resp);//from  ww  w.ja  va  2  s . com

    UploadResponse uploadResponse;

    try {
        String uri = req.getRequestURI();
        // First, call split with no limit parameter.
        String[] uriComponents = uri.split("/");
        String uploadKind = uriComponents[UPLOAD_KIND_INDEX];

        if (uploadKind.equals(ServerLayout.UPLOAD_PROJECT)) {
            uriComponents = uri.split("/", SPLIT_LIMIT_PROJECT_SOURCE);
            String projectName = uriComponents[PROJECT_TITLE_INDEX];
            InputStream uploadedStream;
            try {
                uploadedStream = getRequestStream(req, ServerLayout.UPLOAD_PROJECT_ARCHIVE_FORM_ELEMENT);
            } catch (Exception e) {
                throw CrashReport.createAndLogError(LOG, req, null, e);
            }

            try {
                UserProject userProject = fileImporter.importProject(userInfoProvider.getUserId(), projectName,
                        uploadedStream);
                String info = userProject.toString();
                uploadResponse = new UploadResponse(UploadResponse.Status.SUCCESS, 0, info);
            } catch (FileImporterException e) {
                uploadResponse = e.uploadResponse;
            }
        } else if (uploadKind.equals(ServerLayout.UPLOAD_FILE)) {
            uriComponents = uri.split("/", SPLIT_LIMIT_FILE);
            long projectId = Long.parseLong(uriComponents[PROJECT_ID_INDEX]);
            String fileName = uriComponents[FILE_PATH_INDEX];
            InputStream uploadedStream;
            try {
                uploadedStream = getRequestStream(req, ServerLayout.UPLOAD_FILE_FORM_ELEMENT);
            } catch (Exception e) {
                throw CrashReport.createAndLogError(LOG, req, null, e);
            }

            try {
                long modificationDate = fileImporter.importFile(userInfoProvider.getUserId(), projectId,
                        fileName, uploadedStream);
                uploadResponse = new UploadResponse(UploadResponse.Status.SUCCESS, modificationDate);
            } catch (FileImporterException e) {
                uploadResponse = e.uploadResponse;
            }
        } else if (uploadKind.equals(ServerLayout.UPLOAD_USERFILE)) {
            uriComponents = uri.split("/", SPLIT_LIMIT_USERFILE);
            if (USERFILE_PATH_INDEX >= uriComponents.length) {
                throw CrashReport.createAndLogError(LOG, req, null,
                        new IllegalArgumentException("Missing user file path."));
            }
            String fileName = uriComponents[USERFILE_PATH_INDEX];
            InputStream uploadedStream;
            try {
                uploadedStream = getRequestStream(req, ServerLayout.UPLOAD_USERFILE_FORM_ELEMENT);
            } catch (Exception e) {
                throw CrashReport.createAndLogError(LOG, req, null, e);
            }

            fileImporter.importUserFile(userInfoProvider.getUserId(), fileName, uploadedStream);
            uploadResponse = new UploadResponse(UploadResponse.Status.SUCCESS);
        } else {
            throw CrashReport.createAndLogError(LOG, req, null,
                    new IllegalArgumentException("Unknown upload kind: " + uploadKind));
        }

        // Now, get the PrintWriter for the servlet response and print the UploadResponse.
        // On the client side, in the onSubmitComplete method in ode/client/utils/Uploader.java, the
        // UploadResponse value will be retrieved as a String via the
        // FormSubmitCompleteEvent.getResults() method.
        PrintWriter out = resp.getWriter();
        out.print(uploadResponse.formatAsHtml());

    } catch (IOException e) {
        throw CrashReport.createAndLogError(LOG, req, null, e);
    }

    // Set http response information
    resp.setStatus(HttpServletResponse.SC_OK);
}

From source file:demo.project.ExportTable.java

/**
 * @param w/*from w  w  w.j  av  a2 s . c om*/
 * @param ranker
 */
private void write(PrintWriter w, ColumnRanker ranker) {
    dumpHeader(w, ranker);
    int i = 0;
    for (IRow row : ranker) {
        w.print(i++);
        for (Iterator<ARankColumnModel> it = table.getColumnsOf(ranker); it.hasNext();) {
            ARankColumnModel col = it.next();
            w.append('\t').print(toValue(row, col));
            if (col instanceof ACompositeRankColumnModel) {
                addAll(w, row, ((ACompositeRankColumnModel) col).getChildren());
            }
        }
        w.println();
    }
}