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:org.sakaiproject.imagegallery.web.MultiFileUploaderController.java

public void multiFileUpload(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (log.isInfoEnabled())
        log.info("req contextPath=" + request.getContextPath() + ", pathInfo=" + request.getPathInfo()
                + ", query=" + request.getQueryString() + ", URI=" + request.getRequestURI() + ", URL="
                + request.getRequestURL() + ", servlet=" + request.getServletPath());
    if (request instanceof MultipartHttpServletRequest) {
        String newImageId = storeNewImage((MultipartHttpServletRequest) request);
        response.setContentType("text/plain");
        PrintWriter responseWriter = response.getWriter();
        responseWriter.print(newImageId);
        responseWriter.close();//from   w w  w. java 2 s. c  o m
    }
}

From source file:bookUtilities.RemoveBookServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  www. j  ava2 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 {
    response.setContentType("text/html;charset=UTF-8");
    JSONObject message = removeBook(request.getParameter("bookId"));
    PrintWriter printout = response.getWriter();
    printout.print(message);
    printout.flush();
}

From source file:com.att.api.immn.controller.LoadController.java

public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final HttpSession session = request.getSession();
    OAuthToken token = (OAuthToken) session.getAttribute("token");
    final Boolean authenticated = (token != null && !token.isAccessTokenExpired());

    final String FQDN = appConfig.getOauthFQDN();
    final String clientId = appConfig.getClientId();
    final String scope = appConfig.getProperty("scope");
    final String redirectUri = appConfig.getProperty("redirectUri");
    final String redirect_url = FQDN + "/oauth/v4/authorize?client_id=" + clientId + "&scope=" + scope
            + "&redirect_uri=" + redirectUri;
    final boolean subscriptionActive = session.getAttribute("subscriptionId") != null;

    JSONObject jchannel = new JSONObject().put("channelId", appConfig.getProperty("channelId"))
            .put("channelType", appConfig.getProperty("channelType"))
            .put("maxEvents", appConfig.getProperty("maxEvents"))
            .put("contentType", appConfig.getProperty("contentType"));

    JSONObject jresponse = new JSONObject().put("authenticated", authenticated)
            .put("redirect_url", redirect_url).put("server_time", DateUtil.getTime())
            .put("download", this.appConfig.getProperty("linkDownload"))
            .put("github", this.appConfig.getProperty("linkGithub")).put("notificationChannel", jchannel)
            .put("subscriptionActive", subscriptionActive);

    final String savedData = (String) session.getAttribute("savedData");
    if (savedData != null) {
        final JSONObject jsavedData = new JSONObject(savedData);
        jresponse.put("savedData", jsavedData);
    }/*www.  ja  v  a  2s.c  o m*/

    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.print(jresponse);
    writer.flush();
}

From source file:de.weltraumschaf.groundzero.opt.commons.CustomHelpFormatter.java

@Override
public void printWrapped(final PrintWriter pw, final int width, final int nextLineTabStop, final String text) {
    pw.print(text);
}

From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java

/**
 * Writes the data to <a href="http://databionic-esom.sourceforge.net/user.html#File_formats">ESOM lrn/cls
 * format</a>./*from   www.j  av  a  2 s.c om*/
 */
public static void writeAsESOM(InputData data, String fileName) throws IOException, SOMLibFileFormatException {
    String fileNameLrn = StringUtils.appendExtension(fileName, ".lrn");

    // write the header, see http://databionic-esom.sourceforge.net/user.html#File_formats
    Logger.getLogger("at.tuwien.ifs.somtoolbox")
            .info("Writing input data as ESOM file to '" + fileNameLrn + "'.");
    PrintWriter writer = FileUtils.openFileForWriting("ESOM lrn", fileNameLrn, false);
    if (org.apache.commons.lang.StringUtils.isNotBlank(data.getDataSource())) {
        writer.println("# Converted from " + data.getDataSource() + ".");
    }
    writer.println("% " + data.numVectors());
    writer.println("% " + (data.dim() + 1));
    writer.println("% 9" + StringUtils.repeatString(data.dim(), "\t 1"));
    writer.println("% Key\t" + StringUtils.interleave(data.templateVector().getLabels(), "\t"));
    for (int i = 0; i < data.numVectors(); i++) {
        writer.print(String.valueOf(i + 1)); // index in the lrn file will start with 1, make sure this is in synch
        // with ESOMMapOutputter
        for (int j = 0; j < data.dim(); j++) {
            writer.print("\t" + data.getValue(i, j));
        }
        writer.println();
    }
    writer.close();

    // write the names file
    String fileNameNames = StringUtils.appendOrReplaceExtension(fileName, ".lrn", ".names");
    Logger.getLogger("at.tuwien.ifs.somtoolbox").info("Writing names as ESOM file to '" + fileNameNames + "'.");
    writer = FileUtils.openFileForWriting("ESOM names", fileNameNames, false);
    if (org.apache.commons.lang.StringUtils.isNotBlank(data.getDataSource())) {
        writer.println("# Converted from " + data.getDataSource() + ".");
    }
    writer.println("% " + data.numVectors());
    for (int i = 0; i < data.numVectors(); i++) {
        // index in the names file starts at 1, make sure this is in synch with lrn file and ESOMMapOutputter
        writer.println(String.valueOf(i + 1) + "\t" + data.getLabel(i));
    }
    writer.close();

    if (data.classInformation() != null) {
        // guess a good filename
        String fileNameCls = StringUtils.appendOrReplaceExtension(fileName, ".lrn", ".cls");
        Logger.getLogger("at.tuwien.ifs.somtoolbox")
                .info("Writing class info as ESOM file to '" + fileNameCls + "'.");
        writeAsESOM(data.classInformation(), fileNameCls);
    }

}

From source file:bookUtilities.BookListServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  ww w.j  ava2s .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 {
    response.setContentType("text/html;charset=UTF-8");
    JSONArray books = getBooks();
    PrintWriter printout = response.getWriter();
    printout.print(books);
    printout.flush();
}

From source file:ai.susi.server.api.susi.GenericScraper.java

/**
  * PrintJSON// w  w  w  . j a v a 2s  .  c  om
  * @param response
  * @param JSONObject genericScraperData
  */
public void printJSON(HttpServletResponse response, JSONObject genericScraperData)
        throws ServletException, IOException {
    response.setCharacterEncoding("UTF-8");
    PrintWriter sos = response.getWriter();
    sos.print(genericScraperData.toString(2));
    sos.println();
}

From source file:com.netsteadfast.greenstep.base.interceptor.UserLoginMobileInterceptor.java

@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
    AccountObj accountObj = UserAccountHttpSessionSupport.get(ServletActionContext.getRequest());
    String accountId = accountObj.getAccount();
    if (SecurityUtils.getSubject().isAuthenticated() && !StringUtils.isBlank(accountId)) {
        return actionInvocation.invoke();
    }/*from   w  ww .  j  ava2  s .c  o m*/
    String header = ServletActionContext.getRequest().getHeader("X-Requested-With");
    if ("XMLHttpRequest".equalsIgnoreCase(header)) {
        PrintWriter printWriter = ServletActionContext.getResponse().getWriter();
        printWriter.print(Constants.NO_LOGIN_JSON_DATA);
        printWriter.flush();
        printWriter.close();
        return null;
    }
    return "logout";
}

From source file:clientpaxos.ClientPaxos.java

public static void sendToServer(String msg) throws Exception {
    //create output stream attached to socket
    PrintWriter outToServer = new PrintWriter(new OutputStreamWriter(tcpSocket.getOutputStream()));
    //send msg to server
    outToServer.print(msg + '\n');
    outToServer.flush();/* ww  w. j ava  2s  .co  m*/
}

From source file:com.betfair.cougar.test.socket.app.TestCombo.java

public void emitResults(PrintWriter pw, String indent) throws IOException {
    pw.println(" {");
    pw.print(indent + "\"client\": ");
    client.emitInfo(pw, indent + "  ");
    pw.println(",");
    pw.println(indent + "\"serverVersion\": " + jsonString(server.getVersion()) + ",");
    pw.println(indent + "\"tests\": [");
    pw.println(IOUtils.toString(new FileInputStream(client.getResultsJsonFile())));
    pw.println(indent + "]");
    pw.println(indent.substring(2) + "}");
}