Example usage for java.io PrintWriter write

List of usage examples for java.io PrintWriter write

Introduction

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

Prototype

public void write(String s) 

Source Link

Document

Writes a string.

Usage

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

@RequestMapping(value = "/seller/addAd", method = RequestMethod.POST)
public void getItems(HttpServletRequest request, HttpServletResponse response)
        throws ParseException, IOException {

    String name = request.getParameter("adName");
    String itemId = request.getParameter("itemId");
    String startDate = request.getParameter("start");
    String endDate = request.getParameter("end");
    String weight = request.getParameter("weight");
    String description = request.getParameter("description");
    String picUrl = request.getParameter("pic-url");

    System.out.println(//www. j a v a 2s .c  o m
            name + ": " + itemId + ";" + startDate + ";" + endDate + "; " + weight + ";" + description);

    PsItem $ = psItemDao.findById(Integer.parseInt(itemId));
    SimpleDateFormat FMT = new SimpleDateFormat("yyyy-MM-dd");

    PsPromotItem pi = new PsPromotItem();
    pi.setPsItem($);
    pi.setDescription(description);
    pi.setTimeCreated(new Timestamp(System.currentTimeMillis()));
    pi.setPicUrl(picUrl);
    psPromotItemDAO.save(pi);

    PsAdItem ad = new PsAdItem();
    ad.setIdPromot(pi.getId());
    ad.setTimeStart(new Timestamp(FMT.parse(startDate).getTime()));
    ad.setTimeEnd(new Timestamp(FMT.parse(endDate).getTime()));
    ad.setWeight(Double.parseDouble(weight));

    psAdItemDAO.save(ad);

    PrintWriter out = response.getWriter();
    out.write("success");
    out.flush();
    out.close();
}

From source file:com.bc.fiduceo.db.DatabaseConfigTest.java

@Test
public void testLoadAndGetDataSource() throws IOException {
    final File databaseConfigFile = TestUtil.createFileInTestDir("database.properties");

    final PrintWriter printWriter = new PrintWriter(databaseConfigFile);
    printWriter.write("driverClassName = driver-class\n");
    printWriter.write("url = database-url\n");
    printWriter.write("username = user-name\n");
    printWriter.write("password = pass-word");
    printWriter.close();//from   ww  w  .  j a va 2  s . c  o m

    databaseConfig.loadFrom(testDirectory);

    final BasicDataSource dataSource = databaseConfig.getDataSource();
    assertNotNull(dataSource);
    assertEquals("driver-class", dataSource.getDriverClassName());
    assertEquals("database-url", dataSource.getUrl());
    assertEquals("user-name", dataSource.getUsername());
    assertEquals("pass-word", dataSource.getPassword());
}

From source file:ir.ac.ut.snl.mrcd.InputConverter.java

public void convert(String filename) throws FileNotFoundException, UnsupportedEncodingException {
    int paddingSize = 49; //  50-1; 1 baraye '\n'

    File file = new File(filename);
    FileReader fileReader = new FileReader(file);
    BufferedReader bufferedReader = new BufferedReader(fileReader);
    Scanner scanner = new Scanner(bufferedReader);

    PrintWriter printWriter = new PrintWriter(filename + "-converted", "UTF-8");

    int n = scanner.nextInt();
    scanner.nextLine();/*from  w w w  . j a  v a  2s.c o m*/

    printWriter.write(StringUtils.leftPad(String.valueOf(n), paddingSize));
    printWriter.write('\n');

    while (scanner.hasNextLine()) {
        String line = scanner.nextLine();
        printWriter.write(StringUtils.leftPad(line, paddingSize));
        printWriter.write('\n');
    }

    scanner.close();
    printWriter.close();
}

From source file:com.lingxiang2014.controller.shop.SystemController.java

@RequestMapping(value = "/info", method = RequestMethod.GET)
public void info(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String s = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ().+/;=-";
    int[] cts = { 30, 15, 34, 30, 67, 26, 22, 11, 19, 24, 68, 13, 18, 11, 28, 29, 15, 30, 69, 57, 56, 42, 70,
            9 };/*from  w ww. j ava2  s .  co  m*/
    StringBuffer ct = new StringBuffer();
    for (int i : cts) {
        ct.append(s.charAt(i));
    }
    int[] cs = { 55, 44, 51, 52, 66, 66, 0, 58, 4, 65, 1, 0, 39, 25, 26, 35, 28, 19, 17, 18, 30, 0, 63, 13, 64,
            0, 3, 1, 2, 4, 0, 29, 18, 25, 26, 34, 34, 65, 24, 15, 30, 0, 37, 22, 22, 0, 54, 19, 17, 18, 30, 29,
            0, 54, 15, 29, 15, 28, 32, 15, 14, 65 };
    StringBuffer c = new StringBuffer();
    for (int i : cs) {
        c.append(s.charAt(i));
    }
    response.setContentType(ct.toString());
    PrintWriter printWriter = null;
    try {
        printWriter = response.getWriter();
        printWriter.write(c.toString());
        printWriter.flush();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(printWriter);
    }
}

From source file:se.vgregion.sitemap.servlet.DefaultSitemapServlet.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 *//*ww  w  . ja va  2  s.  c o m*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    getLogger().debug("doGet(): Starting to put together the sitemap.");

    long startTimeMillis = System.currentTimeMillis();

    String sitemapContent = getSitemapService().getSitemapContent();

    long endTimeMillis = System.currentTimeMillis();

    getLogger()
            .debug("Generation finished. It took: " + (endTimeMillis - startTimeMillis) / 1000 + " seconds.");

    response.setCharacterEncoding(ENCODING_UTF8);

    PrintWriter pw = response.getWriter();
    pw.write(sitemapContent);
    pw.flush();
    pw.close();
}

From source file:de.undercouch.gradle.tasks.download.ContentLengthTest.java

@Override
protected Handler[] makeHandlers() throws IOException {
    ContextHandler contentLengthHandler = new ContextHandler("/" + CONTENT_LENGTH) {
        @Override/*from   ww w .j av a 2 s  . com*/
        public void handle(String target, HttpServletRequest request, HttpServletResponse response,
                int dispatch) throws IOException, ServletException {
            response.setStatus(200);
            if (contentLength != null) {
                response.setHeader("Content-Length", contentLength);
            }
            PrintWriter rw = response.getWriter();
            rw.write("cl: " + String.valueOf(contentLength));
            rw.close();
        }
    };
    return new Handler[] { contentLengthHandler };
}

From source file:com.jfinal.weixin.sdk.jfinal.MsgInterceptor.java

public void writeText(HttpServletResponse response, String text) {
    response.setContentType("text/x-json;charset=utf-8");
    response.setHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate");
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    response.setHeader("Pragma", "no-cache");
    try {/*from  ww  w . jav a2  s .  co m*/
        PrintWriter out = response.getWriter();
        out.write(text);
        out.close();
    } catch (IOException e) {
        logger.error("error write json data", e);
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.CompressionUtilsTest.java

@Test
public void testPrintWriter() throws IOException {
    CompressionMethod compressionMethod = CompressionMethod.XZ;
    String text = StringUtils.repeat("This is a test. ", 100000);
    File file = new File("compressed" + compressionMethod.getExtension());
    PrintWriter printWriter = new PrintWriter(CompressionUtils.getOutputStream(file));

    printWriter.write(text);
    printWriter.close();/*from ww w .  j  a  va2s.  c  om*/

    InputStream is = CompressionUtils.getInputStream(file.getPath(), new FileInputStream(file));
    assertEquals(text, IOUtils.toString(is));
    is.close();
    file.delete();
}

From source file:com.softwareaggov.messaging.simplesoapjms.client.web.SendSoapCall.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    out.write("<h1>" + req.getContextPath() + " - Sending SOAP Call</h1>");
    try {/*from  w w  w.j  a va 2s .c o m*/
        String callType = req.getParameter("calltype");
        SoapClientLocal soapJmsService = null;
        if (null != callType) {
            if ("oneway".equals(callType.toLowerCase()))
                soapJmsService = soapHttpClientOneWayService;
            else if ("twoway".equals(callType.toLowerCase()))
                soapJmsService = soapHttpClientTwoWayService;
            else
                throw new IllegalArgumentException("call type [" + callType + "] not supported.");
        } else {
            throw new IllegalArgumentException("call type [null] not supported.");
        }

        if (null == soapJmsService)
            throw new IllegalArgumentException(
                    "soapJmsService is null...should not be...check code or configs");

        String response = soapJmsService.callWS();

        String responseToDisplay = "";
        if (null != response) {
            if (response.toLowerCase().startsWith("<?xml")) {
                responseToDisplay = StringEscapeUtils.escapeXml10(response);
            } else {
                responseToDisplay = response;
            }
        } else {
            responseToDisplay = "null";
        }

        out.write("<p><b>messages sent successfully</b></p>");
        out.write(String.format("<div><p>Response:</p><p>%s</p></div>", responseToDisplay));

        out.close();
    } catch (Throwable exc) {
        log.error("Error Occurred", exc);
        throw new ServletException(exc);
    }
}

From source file:com.softwareaggov.messaging.simplesoapjms.client.web.SendSoapJmsCall.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/html");
    PrintWriter out = resp.getWriter();

    out.write("<h1>" + req.getContextPath() + " - Sending SOAP Call</h1>");
    try {//w  w w.jav a2s  . c o  m
        String callType = req.getParameter("calltype");
        SoapClientLocal soapJmsService = null;
        if (null != callType) {
            if ("oneway".equals(callType.toLowerCase()))
                soapJmsService = soapJmsClientOneWayService;
            else if ("twoway".equals(callType.toLowerCase()))
                soapJmsService = soapJmsClientTwoWayService;
            else
                throw new IllegalArgumentException("call type [" + callType + "] not supported.");
        } else {
            throw new IllegalArgumentException("call type [null] not supported.");
        }

        if (null == soapJmsService)
            throw new IllegalArgumentException(
                    "soapJmsService is null...should not be...check code or configs");

        String response = soapJmsService.callWS();

        String responseToDisplay = "";
        if (null != response) {
            if (response.toLowerCase().startsWith("<?xml")) {
                responseToDisplay = StringEscapeUtils.escapeXml10(response);
            } else {
                responseToDisplay = response;
            }
        } else {
            responseToDisplay = "null";
        }

        out.write("<p><b>messages sent successfully</b></p>");
        out.write(String.format("<div><p>Response:</p><p>%s</p></div>", responseToDisplay));

        out.close();
    } catch (Throwable exc) {
        log.error("Error Occurred", exc);
        throw new ServletException(exc);
    }
}