List of usage examples for java.io PrintWriter flush
public void flush()
From source file:com.thoughtworks.studios.journey.importexport.DataImportExport.java
public void export(PrintWriter writer) { Result result = graphDB.execute(exportCypher()); writer.println(app.nameSpace());//from w w w . j a va 2s . c o m SubGraph subGraph = CypherResultSubGraph.from(result, graphDB, false); new MultipleLineSubGraphExporter(subGraph).export(writer); writer.flush(); }
From source file:de.nbi.ontology.test.TextEnhancerTest.java
/** * Test, if texts are enhances properly. * //from w w w .ja v a2 s .c o m * @param inFile * a text * @throws IOException */ @Test(dataProviderClass = TestFileProvider.class, dataProvider = "enhanceTestFiles", groups = { "functest" }) public void exactMatch(File inFile) throws IOException { log.info("Processing " + inFile.getName()); String basename = FilenameUtils.removeExtension(inFile.getAbsolutePath()); File outFile = new File(basename + ".out"); File resFile = new File(basename + ".res"); PrintWriter w = new PrintWriter(new FileWriter(outFile)); XWikiTextEnhancer enhancer = new XWikiTextEnhancer(); String text = FileUtils.readFileToString(inFile); String newText = enhancer.enhance(text); w.print(newText); w.flush(); w.close(); Assert.assertTrue(FileUtils.contentEquals(outFile, resFile)); }
From source file:net.duckling.ddl.web.controller.team.CreateTeamController.java
@RequestMapping(params = "func=validateTeamId") public void validateTeamId(HttpServletRequest request, HttpServletResponse response) throws IOException { String teamId = request.getParameter("teamId"); boolean flag = teamService.isValidateNewTeamName(teamId); PrintWriter writer = response.getWriter(); writer.print(flag);/*from w w w . j a v a 2 s .co m*/ writer.flush(); writer.close(); }
From source file:org.posterita.core.AbstractChart.java
public String saveImageMap(String imageMapPath) throws OperationException { String fileSeparator = System.getProperty("file.separator"); int index = imageMapPath.lastIndexOf(fileSeparator) + 1; String imageMapName = imageMapPath.substring(index); try {// ww w . j av a 2 s . c o m FileOutputStream fos = new FileOutputStream(new File(imageMapPath)); PrintWriter printWriter = new PrintWriter(fos); ChartUtilities.writeImageMap(printWriter, imageMapName, renderingInfo, false); printWriter.flush(); fos.close(); return imageMapName; } catch (IOException e) { throw new OperationException("Problem occured while writing imagemap", e); } }
From source file:com.mmj.app.common.component.ComponentController.java
@ExceptionHandler(Throwable.class) public ModelAndView handleIOException(Throwable e) throws Throwable { if (AnnotationUtils.findAnnotation(e.getClass(), ResponseStatus.class) != null) { throw e;/*ww w . j a v a 2s. com*/ } if (request == null && response == null) { throw e; } if (request == null && response != null) { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=UTF-8"); OutputStream out = response.getOutputStream(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(out, "utf-8")); pw.println("{\"code\":-1,\"message\":\",?!\",\"data\":\"\"}"); pw.flush(); pw.close(); } ModelAndView mav = new ModelAndView(); if (InvokeTypeTools.isAjax(request)) { return createJsonMav(",?!", ResultCode.ERROR, e.getMessage()); } mav.addObject("exception", e.getCause() == null ? StringUtils.EMPTY : e.getCause().toString()); mav.addObject("msg", e.getMessage()); mav.addObject("stackTrace", e.getStackTrace().toString()); if (request.getRequestURI() != null) { mav.addObject("url", request.getRequestURI().toString()); } mav.getModel().put(CustomVelocityLayoutView.USE_LAYOUT, "false"); mav.setViewName("error"); return mav; }
From source file:eu.smeny.jpapercut.smtp.MailServer.java
private void refuseConnection(Socket client) { try {/*from www . j av a 2 s. c om*/ OutputStream output = client.getOutputStream(); PrintWriter writer = new PrintWriter(output); String hostname = retrieveHostname(); writer.write("421 " + hostname + " Service not available, too much connections"); writer.flush(); client.close(); } catch (IOException ioe) { logger.error("IO Error while refusing connection", ioe); } }
From source file:ca.nrc.cadc.caom2.pkg.TarWriter.java
public void close() throws IOException { StringBuilder sb = new StringBuilder(); for (Map.Entry<String, List<TarContent>> me : map.entrySet()) { for (TarContent tc : me.getValue()) { if (tc.emsg != null) sb.append("ERROR ").append(tc.emsg); else// ww w . ja v a 2s . co m sb.append("OK ").append(tc.filename).append(" ").append(tc.contentMD5).append(" ") .append(tc.url); sb.append("\n"); } boolean openEntry = false; try { String filename = me.getKey() + "/README"; tout.putArchiveEntry(new DynamicTarEntry(filename, sb.length(), new Date())); openEntry = true; PrintWriter pw = new PrintWriter(new TarStreamWrapper(tout)); pw.print(sb.toString()); pw.flush(); pw.close(); // safe } finally { if (openEntry) tout.closeArchiveEntry(); } } tout.finish(); tout.close(); }
From source file:net.joinedminds.tools.evet.TimeValueTable.java
protected void generateJsonResponse(StaplerResponse rsp) throws IOException { rsp.setContentType("application/json"); PrintWriter out = rsp.getWriter(); JSONObject data = getJsonObject();//from w ww . j a va 2 s . co m data.write(out); out.flush(); }
From source file:com.bitranger.parknshop.seller.controller.SellerPublishProductCtrl.java
@RequestMapping(value = "/seller/publishPro", method = RequestMethod.POST) public void savePro(HttpServletRequest request, HttpServletResponse response) throws IOException { // http://c1-parknshop.qiniudn.com/ceg_huafengv700_1.jpg String prefixUrlPic = "http://c1-parknshop.qiniudn.com/"; PsSeller psSeller = (PsSeller) request.getSession().getAttribute("currentSeller"); String name = request.getParameter("name"); String categoryId = request.getParameter("categoryId"); String[] tagsId = request.getParameterValues("tags[]"); String[] urlPics = new String[5]; String[] pics = request.getParameterValues("pics[]"); String price = request.getParameter("price"); String firstStr = ""; // to generate the url pic for (int i = 0; i < pics.length; i++) { String str = pics[i];/*w w w .j ava 2 s . c o m*/ //String[] splitStr = str.split("\\\\"); pics[i] = prefixUrlPic + str; if (i == 0) { firstStr = pics[i]; } } for (int i = 0; i < pics.length; i++) { urlPics[i] = pics[i]; } //String promotion = request.getParameter("promotion"); String description = request.getParameter("description"); String extra1 = request.getParameter("extra1"); PsShop psShop = psShopDAO.findBySellerId(psSeller.getId()).get(0); PsItem psItem = new PsItem(); psItem.setPsShop(psShop); PsCategory psCategory = categoryDAO.findById(Integer.parseInt(categoryId)); psItem.setPsCategory(psCategory); psItem.setName(name); psItem.setIntroduction(description); psItem.setPrice(Double.parseDouble(price)); psItem.setExtra1(extra1); Set<PsTag> tags = new HashSet<PsTag>(); if (tagsId != null) { List<PsTag> tagsList = tagDAO.findTagByIds(tagsId); for (int i = 0; i < tagsList.size(); i++) { tags.add(tagsList.get(i)); } } String urlPicrures = ""; System.out.println("urlPics length : " + pics.length); if (urlPics != null) { if (pics.length < 5) { for (int j = pics.length; j < 5; j++) { urlPics[j] = firstStr; } } for (int i = 0; i < 5; i++) { urlPicrures += urlPics[i]; if (i != urlPics.length - 1) { urlPicrures += ";"; } } } psItem.setUrlPicture(urlPicrures); psItem.setPsTags(tags); psItem.setCountPurchase(0); psItem.setCountClick(0); psItem.setCountFavourite(0); psItem.setVote(new Double(0)); psItem.setTimeCreated(new Timestamp(System.currentTimeMillis())); psItemDAO.save(psItem); //System.out.println(name + "-" + categoryId); PrintWriter out = response.getWriter(); out.write("success"); out.flush(); out.close(); }
From source file:TakeAttendanceTest.java
/** * Test of processRequest method, of class TakeAttendance. *///w ww. j a v a 2 s .com @Test public void testProcessRequest() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); when(request.getParameter("asname")).thenReturn("1301010"); when(request.getParameter("day")).thenReturn("Anubhav"); when(request.getParameter("uids")).thenReturn("Attendee"); PrintWriter writer = new PrintWriter("testtakeattendance.txt"); when(response.getWriter()).thenReturn(writer); TakeAttendance instance = new TakeAttendance(); instance.doPost(request, response); verify(request, atLeast(1)).getParameter("asname"); writer.flush(); // it may not have been flushed yet... assertTrue(FileUtils.readFileToString(new File("testtakeattendance.txt"), "UTF-8") .contains("Attendance Added")); }