List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:com.epam.wilma.webapp.config.servlet.stub.upload.MultiPartFormUploadServlet.java
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); boolean isMultipartContent = ServletFileUpload.isMultipartContent(request); if (!isMultipartContent) { out.println("You are not trying to upload"); } else {/* www. ja va 2 s . c o m*/ try { List<FileItem> fields = upload.parseRequest(request); String msg = filesParser.parseMultiPartFiles(fields); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, msg)); out.write(msg); } catch (Exception e) { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); out.write("File uploading failed! cause: " + e.getMessage()); LOGGER.info(urlAccessLogMessageAssembler.assembleMessage(request, e.getMessage()), e); } } }
From source file:com.googlecode.jmxtrans.model.output.OpenTSDBWriter.java
@Override public void internalWrite(Server server, Query query, ImmutableList<Result> results) throws Exception { Socket socket = null;/*w w w .j a v a2 s .c o m*/ PrintWriter writer = null; try { socket = pool.borrowObject(address); writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), UTF_8), true); for (String formattedResult : messageFormatter.formatResults(results, server)) { log.debug("OpenTSDB Message: {}", formattedResult); writer.write("put " + formattedResult + "\n"); } } catch (ConnectException e) { log.error("Error while connecting to OpenTSDB", e); } finally { if (writer != null && writer.checkError()) { log.error("Error writing to OpenTSDB, clearing OpenTSDB socket pool"); pool.invalidateObject(address, socket); } else { pool.returnObject(address, socket); } } }
From source file:forumbox.PostingnewpostServlet.java
public void filewrite(String url, String username, String title, String description, HttpServletResponse response, String id) throws IOException { count++;/* www . j a v a 2 s. c om*/ /* BufferedWriter out ; out = new BufferedWriter(new FileWriter(url,true)); out.write(count+"/"+array[0]+"/"+array[1]+"/"+array[2]+";"); out.close(); }catch (Exception e) { System.out.println("Error: " + e.getMessage()); } */ JSONObject post = new JSONObject(); JSONArray comments = new JSONArray(); JSONArray toapprove = new JSONArray(); JSONParser parser = new JSONParser(); JSONObject list = null; post.put("title", title); post.put("description", description); post.put("id", id); post.put("username", username); // post.put("comments",comments); // post.put("toapprove",toapprove); try { Object obj = parser.parse(new FileReader(url + "list.json")); list = (JSONObject) obj; JSONArray msg = (JSONArray) list.get("list"); msg.add(id); list.remove("list"); list.put("list", msg); } catch (Exception e) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("Adding new ID is unsuccessful"); out.println(e); out.println("......................"); } try { File file = new File(url + id + ".json"); file.createNewFile(); BufferedWriter out; out = new BufferedWriter(new FileWriter(file)); out.write(post.toJSONString()); out.close(); File fileList = new File(url + "list.json"); // fileList.createNewFile(); // BufferedWriter outin ; // outin = new BufferedWriter(new FileWriter(fileList)); // outin.write(post.toJSONString()); FileWriter listwrite = new FileWriter(fileList); listwrite.write(list.toJSONString()); listwrite.flush(); listwrite.close(); //outin.close(); } catch (IOException e) { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("adding new post is unsuccessful"); out.println(e); out.println("......................"); } }
From source file:com.healthcit.cacure.web.interceptor.BreadCrumbsSupportInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (handler instanceof BreadCrumbsSupporter) { String nameAllJson = request.getParameter("name_all_json"); if (StringUtils.isNotBlank(nameAllJson) && "true".equalsIgnoreCase(nameAllJson)) { BreadCrumbsSupporter controller = (BreadCrumbsSupporter) handler; List<BreadCrumb.Link> links = controller.getAllLinks(request); response.setContentType("application/json"); PrintWriter writer = response.getWriter(); try { String contextPath = request.getContextPath(); JSONArray linksArray = new JSONArray(); for (BreadCrumb.Link link : links) { JSONObject obj = new JSONObject(); obj.put("name", link.getName()); obj.put("url", contextPath + link.getUrl()); linksArray.add(obj); }// w w w .j a v a 2s.c o m writer.write(linksArray.toString()); } finally { writer.close(); } return false; } } return super.preHandle(request, response, handler); }
From source file:UniqueInstance.java
/** * Envoie un message l'instance de l'application dj ouverte. */// w w w . j av a2s .c om private void send() { PrintWriter pw = null; try { /* On se connecte sur la machine locale. */ Socket socket = new Socket("localhost", port); /* On dfinit un PrintWriter pour crire sur la sortie de la socket. */ pw = new PrintWriter(socket.getOutputStream()); /* On crit le message sur la socket. */ pw.write(message); } catch (IOException e) { Logger.getLogger("UniqueInstance").warning("criture sur flux de sortie de la socket chou."); } finally { if (pw != null) { pw.close(); } } }
From source file:au.org.ala.biocache.web.ExploreController.java
/** * Returns the species that only have occurrences in the supplied WKT. * @return/*from w ww .j av a 2 s . co m*/ */ @RequestMapping(value = "/explore/endemic/species.csv", method = RequestMethod.GET) public void getEndemicSpeciesCSV(SpatialSearchRequestParams requestParams, HttpServletResponse response) throws Exception { requestParams.setFacets(new String[] { SearchDAOImpl.NAMES_AND_LSID }); requestParams.setFq((String[]) ArrayUtils.add(requestParams.getFq(), "species_guid:[* TO *]")); List<FieldResultDTO> list = getSpeciesOnlyInWKT(requestParams, response); response.setCharacterEncoding("UTF-8"); response.setContentType("text/plain"); java.io.PrintWriter writer = response.getWriter(); writer.write("Family,Scientific name,Common name,Taxon rank,LSID,# Occurrences"); for (FieldResultDTO item : list) { String s = item.getLabel(); if (s.startsWith("\"") && s.endsWith("\"") && s.length() > 2) s = s.substring(1, s.length() - 1); String[] values = s.split("\\|", 6); if (values.length >= 5) { writer.write("\n" + values[4] + ",\"" + values[0] + "\",\"" + values[2] + "\",," + values[1] + "," + item.getCount()); } } writer.flush(); writer.close(); }
From source file:eu.stratosphere.nephele.jobmanager.web.JobmanagerInfoServlet.java
/** * Writes Json with a list of currently archived jobs, sorted by time * /*from ww w . j ava2s.c o m*/ * @param wrt * @param jobs */ private void writeJsonForArchive(PrintWriter wrt, List<RecentJobEvent> jobs) { wrt.write("["); // sort jobs by time Collections.sort(jobs, new Comparator<RecentJobEvent>() { @Override public int compare(RecentJobEvent o1, RecentJobEvent o2) { if (o1.getTimestamp() < o2.getTimestamp()) { return 1; } else { return -1; } } }); // Loop Jobs for (int i = 0; i < jobs.size(); i++) { RecentJobEvent jobEvent = jobs.get(i); //Serialize job to json wrt.write("{"); wrt.write("\"jobid\": \"" + jobEvent.getJobID() + "\","); wrt.write("\"jobname\": \"" + jobEvent.getJobName() + "\","); wrt.write("\"status\": \"" + jobEvent.getJobStatus() + "\","); wrt.write("\"time\": " + jobEvent.getTimestamp()); wrt.write("}"); //Write seperator between json objects if (i != jobs.size() - 1) { wrt.write(","); } } wrt.write("]"); }
From source file:com.imagelake.android.category.Servlet_categories.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); CategoriesDAOImp categoryDAOImp = new CategoriesDAOImp(); JSONArray ja = new JSONArray(); ArrayList<Categories> categoriesList = (ArrayList<Categories>) categoryDAOImp.listAllCategories(); if (!categoriesList.isEmpty()) { for (Categories cc : categoriesList) { JSONObject jo = new JSONObject(); jo.put("id", cc.getCategory_id()); jo.put("cat", cc.getCategory()); ja.add(jo);//from www . j a v a 2 s . co m } out.write("json=" + ja.toJSONString()); } else { JSONObject jo = new JSONObject(); jo.put("id", 0); jo.put("cat", "No category found."); ja.add(jo); out.write("json=" + ja.toJSONString()); } }
From source file:eu.stratosphere.nephele.jobmanager.web.JobmanagerInfoServlet.java
/** * Writes ManagementGraph as Json for all recent jobs * /*from w ww .jav a 2 s . c o m*/ * @param wrt * @param jobs */ private void writeJsonForJobs(PrintWriter wrt, List<RecentJobEvent> jobs) { try { wrt.write("["); // Loop Jobs for (int i = 0; i < jobs.size(); i++) { RecentJobEvent jobEvent = jobs.get(i); writeJsonForJob(wrt, jobEvent); //Write seperator between json objects if (i != jobs.size() - 1) { wrt.write(","); } } wrt.write("]"); } catch (EofException eof) { // Connection closed by client LOG.info("Info server for jobmanager: Connection closed by client, EofException"); } catch (IOException ioe) { // Connection closed by client LOG.info("Info server for jobmanager: Connection closed by client, IOException"); } }
From source file:com.suntek.gztpb.controller.ChangeContactControll.java
@RequestMapping(value = "success.htm", method = RequestMethod.POST) public @ResponseBody String saveTest(DriverChangeModel driverInfo, HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); String applyNum = IdGenerator.getInstance().getBizCode("ITMS_SEQ", 5); driverInfo.setApplynum(applyNum);/* ww w . jav a 2s . co m*/ System.out.println("applyNum=" + applyNum); driverInfo.setBiztype("3001"); driverInfo.setCreatedtime(new Date()); driverInfo.setCreator("admin"); driverInfo.setSource(0); driverInfo.setSubmittime(new Date()); driverInfo.setFinish(0); try { driverChangeService.signUp(driverInfo); out.write("<script>parent.saveCallback(1,'" + applyNum + "')</script>"); } catch (Exception e) { e.printStackTrace(); out.write("<script>parent.saveCallback(0)</script>"); } return null; }