List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:com.jaspersoft.jasperserver.war.CSVServlet.java
private void printCSV(ResultSet rs, PrintWriter out) throws Exception { ResultSetMetaData md = rs.getMetaData(); int numCols = md.getColumnCount(); // print column headers for (int i = 1; i < numCols; i++) { out.write(quoteString(md.getColumnName(i))); out.write(SEP);// w w w. java 2s .com } out.write(quoteString(md.getColumnName(numCols))); out.write(NEWLINE); // print row data while (rs.next()) { for (int i = 1; i < numCols; i++) { out.write(quoteString("" + rs.getObject(i))); out.write(SEP); } out.write(quoteString("" + rs.getObject(numCols))); out.write(NEWLINE); } }
From source file:com.recomdata.datasetexplorer.proxy.XmlHttpProxyServlet.java
private void getServices(HttpServletResponse res) { InputStream is = null;/*from w ww . ja v a 2 s . c om*/ try { URL url = ctx.getResource(resourcesDir + XHP_CONFIG); // use classpath if not found locally. if (url == null) url = XmlHttpProxyServlet.class.getResource(classpathResourcesDir + XHP_CONFIG); is = url.openStream(); } catch (Exception ex) { try { getLogger().severe("XmlHttpProxyServlet error loading xhp.json : " + ex); PrintWriter writer = res.getWriter(); writer.write( "XmlHttpProxyServlet Error: Error loading xhp.json. Make sure it is available in the /resources directory of your applicaton."); writer.flush(); } catch (Exception iox) { } } services = xhp.loadServices(is); }
From source file:org.openmrs.module.logmanager.web.view.AutocompleteView.java
@SuppressWarnings("rawtypes") @Override/*from ww w. ja v a 2s .co m*/ protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { PrintWriter writer = response.getWriter(); Object source = model.get(sourceKey); // Disable caching response.setHeader("Pragma", "No-cache"); response.setDateHeader("Expires", 0); response.setHeader("Cache-Control", "no-cache"); response.setContentType("application/json"); writer.write("["); if (source != null) { if (source instanceof Collection) { Collection<?> collection = (Collection<?>) source; Object[] items = collection.toArray(); for (int i = 0; i < items.length; i++) { Object item = items[i]; String label = (item instanceof LoggerProxy) ? ((LoggerProxy) item).getName() : item.toString(); if (i > 0) writer.write(','); writer.write("{\"label\":\"" + label + "\", \"value\":\"" + label + "\"}"); } } } else writer.write("\"ERROR: Source object is null\""); writer.write("]"); }
From source file:com.appunity.ant.util.NewClass.java
/** */// w ww. j a v a2 s .c o m private void parse2UTF_8(File file, File destFile) throws IOException { StringBuffer msg = new StringBuffer(); // PrintWriter ps = new PrintWriter(new OutputStreamWriter(new FileOutputStream(destFile, false), "utf8")); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "gbk")); // String line = br.readLine(); while (line != null) { msg.append(line).append("\r\n"); line = br.readLine(); } ps.write(msg.toString()); br.close(); ps.flush(); ps.close(); }
From source file:com.esri.gpt.control.arcims.ServletConnectorProxy.java
/** * Sends request to the opened HTTP connection. * //from ww w . j a v a 2 s . co m * @param input * data as stream * @param outputWriter * to send back response * * @throws java.io.IOException * if sending data failed */ private void send(InputStream input, PrintWriter outputWriter) throws IOException { try { outputWriter.write(readInputCharacters(input)); outputWriter.flush(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.doculibre.constellio.wicket.servlet.SolrServletEmulator.java
final void sendErr(int rc, String msg, HttpServletResponse response, OutputStream outputStream) { // try {/*from ww w . ja v a 2s . co m*/ // hmmm, what if this was already set to text/xml? try { response.setContentType(QueryResponseWriter.CONTENT_TYPE_TEXT_UTF8); // response.setCharacterEncoding("UTF-8"); } catch (Exception e) { } try { response.setStatus(rc); } catch (Exception e) { } // PrintWriter writer = response.getWriter(); PrintWriter writer = new PrintWriter(outputStream); writer.write(msg); // } catch (IOException e) { // LOGGER.log(Level.SEVERE, SolrException.toStr(e), e); // } }
From source file:CourseFileManagementSystem.Upload.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.write("<html><head></head><body>"); // Check that we have a file upload request if (!ServletFileUpload.isMultipartContent(request)) { // if not, we stop here PrintWriter writer = response.getWriter(); writer.println("Error: Form must has enctype=multipart/form-data."); writer.flush();/*w w w . java 2 s .c o m*/ return; } // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // Sets the size threshold beyond which files are written directly to // disk. factory.setSizeThreshold(MAX_MEMORY_SIZE); // Sets the directory used to temporarily store files that are larger // than the configured size threshold. We use temporary directory for // java factory.setRepository(new File(System.getProperty("java.io.tmpdir"))); // constructs the folder where uploaded file will be stored String temp_folder = " "; try { String dataFolder = getServletContext().getRealPath("") + File.separator + DATA_DIRECTORY; temp_folder = dataFolder; File uploadD = new File(dataFolder); if (!uploadD.exists()) { uploadD.mkdir(); } ResultList rs5 = DB.query( "SELECT * FROM course AS c, section AS s, year_semester AS ys, upload_checklist AS uc WHERE s.courseCode = c.courseCode " + "AND s.semesterID = ys.semesterID AND s.courseID = c.courseID AND s.sectionID=" + sectionID); rs5.next(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Sets maximum size of upload file upload.setFileSizeMax(MAX_FILE_SIZE); // Set overall request size constraint upload.setSizeMax(MAX_REQUEST_SIZE); // creates the directory if it does not exist String path1 = getServletContext().getContextPath() + "/" + DATA_DIRECTORY + "/"; String temp_semester = rs5.getString("year") + "-" + rs5.getString("semester"); String real_path = temp_folder + File.separator + temp_semester; File semester = new File(real_path); if (!semester.exists()) { semester.mkdir(); } path1 += temp_semester + "/"; real_path += File.separator; String temp_course = rs5.getString("courseCode") + rs5.getString("courseID") + "-" + rs5.getString("courseName"); String real_path1 = real_path + temp_course; File course = new File(real_path1); if (!course.exists()) { course.mkdir(); } path1 += temp_course + "/"; real_path1 += File.separator; String temp_section = "section-" + rs5.getString("sectionNo"); String real_path2 = real_path1 + temp_section; File section = new File(real_path2); if (!section.exists()) { section.mkdir(); } path1 += temp_section + "/"; real_path2 += File.separator; String sectionPath = path1; // Parse the request List<FileItem> items = upload.parseRequest(request); if (items != null && items.size() > 0) { // iterates over form's fields for (FileItem item : items) { // processes only fields that are not form fields if (!item.isFormField() && !item.getName().equals("")) { String DBPath = ""; System.out.println(item.getName() + " file is for " + item.getFieldName()); Scanner field_name = new Scanner(item.getFieldName()).useDelimiter("[^0-9]+"); int id = field_name.nextInt(); fileName = new File(item.getName()).getName(); ResultList rs = DB.query("SELECT * FROM upload_checklist WHERE checklistID =" + id); rs.next(); String temp_file = rs.getString("label"); String real_path3 = real_path2 + temp_file; File file_type = new File(real_path3); if (!file_type.exists()) file_type.mkdir(); DBPath = sectionPath + "/" + temp_file + "/"; String context_path = DBPath; real_path3 += File.separator; String filePath = real_path3 + fileName; DBPath += fileName; String temp_DBPath = DBPath; int count = 0; File f = new File(filePath); String temp_fileName = f.getName(); String fileNameWithOutExt = FilenameUtils.removeExtension(temp_fileName); String extension = FilenameUtils.getExtension(filePath); String newFullPath = filePath; String tempFileName = " "; while (f.exists()) { ++count; tempFileName = fileNameWithOutExt + "_(" + count + ")."; newFullPath = real_path3 + tempFileName + extension; temp_DBPath = context_path + tempFileName + extension; f = new File(newFullPath); } filePath = newFullPath; System.out.println("New path: " + filePath); DBPath = temp_DBPath; String changeFilePath = filePath.replace('/', '\\'); String changeFilePath1 = changeFilePath.replace("Course_File_Management_System\\", ""); File uploadedFile = new File(changeFilePath1); System.out.println("Change filepath = " + changeFilePath1); System.out.println("DBPath = " + DBPath); // saves the file to upload directory item.write(uploadedFile); String query = "INSERT INTO files (fileDirectory) values('" + DBPath + "')"; DB.update(query); ResultList rs3 = DB.query("SELECT label FROM upload_checklist WHERE id=" + id); while (rs3.next()) { String label = rs3.getString("label"); out.write("<a href=\"Upload?fileName=" + changeFilePath1 + "\">Download " + label + "</a>"); out.write("<br><br>"); } ResultList rs4 = DB.query("SELECT * FROM files ORDER BY fileID DESC LIMIT 1"); rs4.next(); String query2 = "INSERT INTO lecturer_upload (fileID, sectionID, checklistID) values(" + rs4.getString("fileID") + ", " + sectionID + ", " + id + ")"; DB.update(query2); } } } } catch (FileUploadException ex) { throw new ServletException(ex); } catch (Exception ex) { throw new ServletException(ex); } response.sendRedirect(request.getHeader("Referer")); }
From source file:javax.portlet.tck.portlets.HeaderPortletTests_SPEC14_HeaderReq.java
@Override public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException, IOException { PrintWriter writer = renderResponse.getWriter(); String msg = (String) renderRequest .getAttribute(RESULT_ATTR_PREFIX + "HeaderPortletTests_SPEC14_HeaderReq"); writer.write("<p>" + msg + "</p>\n"); renderRequest.removeAttribute(RESULT_ATTR_PREFIX + "HeaderPortletTests_SPEC14_HeaderReq"); }
From source file:de.openknowledge.jaxrs.versioning.AddressResourceTest.java
private InputStream send(URL url, String method, String resource) throws IOException { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true);//from w w w .j a v a 2s . c o m connection.setRequestMethod(method); connection.setRequestProperty("Content-Type", "application/json"); PrintWriter writer = new PrintWriter(connection.getOutputStream()); for (String line : IOUtils.readLines(AddressV1.class.getResourceAsStream(resource))) { writer.write(line); } writer.close(); return connection.getInputStream(); }
From source file:com.ephesoft.dcma.gwt.admin.bm.server.ImportBatchClassUploadServlet.java
private void printWriterMethod(PrintWriter printWriter, String zipWorkFlowName, String tempOutputUnZipDir, String systemFolderPath, List<String> uncList, boolean isWorkflowDeployed, boolean isWorkflowEqual) { printWriter.write("workFlowName:" + zipWorkFlowName); printWriter.append("|"); printWriter.append("filePath:").append(tempOutputUnZipDir); printWriter.append("|"); printWriter.write("workflowDeployed:" + isWorkflowDeployed); printWriter.append("|"); printWriter.write("workflowEqual:" + isWorkflowEqual); printWriter.append("|"); printWriter.write("workflowExistInBatchClass:" + ((uncList == null || uncList.size() == 0) ? false : true)); printWriter.append("|"); printWriter.write("systemFolderPath:" + systemFolderPath); printWriter.append("|"); printWriter.flush();/*from w w w. j a va 2 s. c o m*/ }