List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:ca.sqlpower.architect.transformation.VelocityTransformationTest.java
public void testTransform() throws Exception { File tempdir = new File(System.getProperty("java.io.tmpdir")); File vm = new File(tempdir, "test_template.vm"); OutputStream out = new FileOutputStream(vm); PrintWriter writer = new PrintWriter(new OutputStreamWriter(out, ENCODING)); writer.print("#foreach ($table in $tables) \n" + "Table: $table.name\n" + "#foreach ($col in $table.columns)\n" + " $col.shortDisplayName\n" + "#end\n" + "#end\n"); writer.close();//from ww w . j av a 2 s . c o m File output = new File(tempdir, "test-output.txt"); VelocityTransformation vt = new VelocityTransformation(); vt.transform(vm, output, session); assertTrue(output.exists()); FileInputStream fi = new FileInputStream(output); InputStreamReader in = new InputStreamReader(fi, "UTF-8"); List<String> lines = IOUtils.readLines(in); assertEquals("Table: Customers", lines.get(0)); assertEquals(" id: VARCHAR(10)", lines.get(1)); assertEquals(" name: VARCHAR(10)", lines.get(2)); assertEquals("Table: Orders", lines.get(3)); assertEquals(" id: VARCHAR(10)", lines.get(4)); assertEquals(" customer_id: INTEGER", lines.get(5)); assertEquals(" purchase_date: DATE", lines.get(6)); assertEquals("Table: mm_project", lines.get(7)); assertEquals(" project_oid: INTEGER", lines.get(8)); assertEquals(" FOLDER_OID: INTEGER", lines.get(9)); assertEquals(" project_name: VARCHAR(80)", lines.get(10)); assertEquals(" vision: DECIMAL(20, 20)", lines.get(11)); }
From source file:fr.ippon.wip.http.reponse.Response.java
/** * Print the response content to and HttpServletResponse * /* w ww .ja va2 s . c o m*/ * Set appropriate Content-Type, Charset and HTTP status code. Force * Content-Disposition to "attachment". Can handle binary content. * * @param httpServletResponse * @throws IOException */ public void sendResponse(HttpServletResponse httpServletResponse) throws IOException { httpServletResponse.setContentType(mimeType); httpServletResponse.setCharacterEncoding(charset.name()); httpServletResponse.setStatus(responseCode); if (isBinary()) { httpServletResponse.setHeader("Content-Disposition", "attachment; filename=\"" + getFileName() + "\""); OutputStream os = httpServletResponse.getOutputStream(); IOUtils.copy(new ByteArrayInputStream(content), os); os.close(); } else { String textContent = new String(content, charset); httpServletResponse.setContentLength(textContent.length()); PrintWriter writer = httpServletResponse.getWriter(); writer.print(textContent); } }
From source file:com.concursive.connect.web.webdav.resources.WebdavResource.java
protected void sendContentFinish(final PrintWriter printer) { printer.print("</body></html>"); printer.flush();// w w w . j av a 2s. co m }
From source file:com.concursive.connect.web.webdav.resources.WebdavResource.java
protected void sendContentMiddle(final PrintWriter printer) { printer.print("rename"); printer.print("<form method='POST' action='" + this.getHref() + "'><input type='text' name='name' value='" + this.getName() + "'/><input type='submit'></form>"); }
From source file:com.concursive.connect.web.webdav.resources.WebdavResource.java
protected void sendContentStart(final PrintWriter printer) { printer.print("<html><body>"); printer.print("<h1>" + getName() + "</h1>"); sendContentMenu(printer);/* w w w.j a v a2 s . c om*/ }
From source file:io.lightlink.servlet.JsMethodsDefinitionServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("application/javascript"); resp.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); resp.setHeader("Pragma", "no-cache"); resp.setDateHeader("Expires", 0); Cookie[] cookies = req.getCookies(); String debugMethods = ""; for (int i = 0; cookies != null && i < cookies.length; i++) { Cookie cookie = cookies[i];/*ww w.j a v a 2 s . com*/ if ("lightlink.debug".equalsIgnoreCase(cookie.getName())) debugMethods = cookie.getValue(); } PrintWriter writer = resp.getWriter(); writer.print(getDeclarationScript(debugMethods, req)); if (StringUtils.isNotEmpty(debugMethods) && ConfigManager.isInDebugMode()) { writer.print("\n// DEBUG PART \n"); writer.print("\n\n /***** io/lightlink/core/sqlFunctions.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/sqlFunctions.js")); writer.print("\n\n /***** io/lightlink/core/debugProxy.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/debugProxy.js")); writer.print("\n\n /***** io/lightlink/core/LightLinkDebugSession.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/LightLinkDebugSession.js")); } if (ConfigManager.isInDebugMode()) { writer.print("\n\n /***** io/lightlink/core/IDDQD.js - for debugging *****/\n"); writer.print(Utils.getResourceContent("io/lightlink/core/IDDQD.js")); } writer.print("\n" + "LL.JsApi.CSRF_Token = '" + CSRFTokensContainer.getInstance(req.getSession()).createNewToken() + "'\n"); writer.close(); resp.flushBuffer(); }
From source file:com.laxser.blitz.web.instruction.TextInstruction.java
private void sendResponse(HttpServletResponse response, String text) throws IOException { if (StringUtils.isNotEmpty(text)) { PrintWriter out = response.getWriter(); if (logger.isDebugEnabled()) { logger.debug("write text to response:" + text); }/*from w ww .ja va 2 s . c o m*/ out.print(text); } }
From source file:com.ehi.carshare.Main.java
private void run(String logformat, String inputFile, String outputFile) throws Exception { printAllPossibles(logformat);/*ww w .java 2 s .co m*/ Parser<ApacheHttpLog> parser = new ApacheHttpdLoglineParser<ApacheHttpLog>(ApacheHttpLog.class, logformat); parser.ignoreMissingDissectors(); // Load file in memory File file = new File(inputFile); if (!file.exists()) { throw new RuntimeException("Input file does not exist"); } BufferedReader reader = new BufferedReader(new FileReader(file)); List<String> readLines = new ArrayList<String>(); String line = reader.readLine(); while (line != null) { readLines.add(line); line = reader.readLine(); } reader.close(); // Parse apache logs List<ApacheHttpLog> myRecords = new ArrayList<ApacheHttpLog>(); for (String readLine : readLines) { try { ApacheHttpLog myRecord = new ApacheHttpLog(); parser.parse(myRecord, readLine); if (myRecord.getAction() != null && "200".equals(myRecord.getStatus()) && myRecord.getPath() != null) { myRecords.add(myRecord); } } catch (Exception e) { /// e.printStackTrace(); } } // Group by action Map<String, List<ApacheHttpLog>> map = new HashMap<String, List<ApacheHttpLog>>(); for (ApacheHttpLog item : myRecords) { String key = item.getAction(); if (map.get(key) == null) { map.put(key, new ArrayList<ApacheHttpLog>()); } map.get(key).add(item); } // Collect stats List<ApacheHttpLogStats> recordStats = new ArrayList<ApacheHttpLogStats>(); for (Entry<String, List<ApacheHttpLog>> entry : map.entrySet()) { ApacheHttpLogStats stats = new ApacheHttpLogStats(); stats.setActionName(entry.getKey()); long responseCount = entry.getValue().size(); stats.setResponseCount(responseCount); long sum = 0; for (ApacheHttpLog myRecord : entry.getValue()) { sum = sum + myRecord.getResponseTime(); } BigDecimal average = new BigDecimal(sum) .divide(new BigDecimal(responseCount * 1000000), 2, RoundingMode.HALF_UP) .setScale(2, RoundingMode.UP); stats.setAverageResponseTime(average.toPlainString()); recordStats.add(stats); } // Write lines to file PrintWriter f0 = new PrintWriter(new FileWriter(outputFile)); f0.print(ApacheHttpLogStats.headerString()); for (ApacheHttpLogStats myRecordStats : recordStats) { f0.print(myRecordStats.toString()); } f0.close(); }
From source file:com.seer.datacruncher.profiler.spring.StringAnalyticsController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Hashtable<String, String> dbParams = (Hashtable<String, String>) request.getSession(true) .getAttribute("dbConnectionData"); String dsn = ""; if (dbParams != null) { dsn = CommonUtil.notNullValue(dbParams.get("Database_DSN")); }//from ww w.ja v a2 s. c om String condition = CommonUtil.notNullValue(request.getParameter("condition")); String table = CommonUtil.notNullValue(request.getParameter("table")); String column = CommonUtil.notNullValue(request.getParameter("column")).split("\\:")[0]; String type = CommonUtil.notNullValue(request.getParameter("column")).split("\\:")[1]; String noGrid = CommonUtil.notNullValue(request.getParameter("action")); String qp_1 = CommonUtil.notNullValue(request.getParameter("qp_1")); String qp_2 = CommonUtil.notNullValue(request.getParameter("qp_2")); String qp_3 = CommonUtil.notNullValue(request.getParameter("qp_3")); String qc_1 = CommonUtil.notNullValue(request.getParameter("qc_1")); String qc_2 = CommonUtil.notNullValue(request.getParameter("qc_2")); String qc_3 = CommonUtil.notNullValue(request.getParameter("qc_3")); String q_s = CommonUtil.notNullValue(request.getParameter("q_s")); String _distinct = CommonUtil.notNullValue(request.getParameter("_distinct")); StringAnalyticsBL sabl = new StringAnalyticsBL(dsn, type, condition, table, column); sabl.setQp_1(qp_1); sabl.setQp_2(qp_2); sabl.setQp_3(qp_3); sabl.setQ_s(q_s); sabl.setQc_1(qc_1); sabl.setQc_2(qc_2); sabl.setQc_3(qc_3); sabl.set_distinct(_distinct); PrintWriter out = response.getWriter(); if (noGrid.equals("noGrid")) { if (q_s.equals("2")) { out.print(sabl.reCreateBotPane_regex(true)); } else { out.print(sabl.reCreateBotPane_like(true)); } } else { ObjectMapper mapper = new ObjectMapper(); if (q_s.equals("2")) { out.print(mapper.writeValueAsBytes((GridInfoDTO) sabl.reCreateBotPane_regex(false))); } else { out.print(mapper.writeValueAsBytes((GridInfoDTO) sabl.reCreateBotPane_like(false))); } } return null; }
From source file:net.cellcloud.http.AbstractJSONHandler.java
/** * ????// ww w . ja v a2 s . c o m * @param response * @param status */ protected void respond(HttpResponse response, int status) { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.setStatus(status); PrintWriter out = null; try { out = response.getWriter(); out.print("{}"); } catch (IOException e) { Logger.log(AbstractJSONHandler.class, e, LogLevel.ERROR); } finally { try { out.close(); } catch (Exception e) { // Nothing } } }