List of usage examples for java.io PrintWriter write
public void write(String s)
From source file:edu.byu.nlp.crowdsourcing.SerializableCrowdsourcingState.java
public void serializeTo(PrintWriter serializeOut) { serializeOut.write(new Gson().toJson(perDocumentState)); }
From source file:com.suntek.gztpb.controller.DriverLicenseController.java
@RequestMapping(value = "upload.htm", method = RequestMethod.POST) // public String handleFormUpload(HttpServletRequest request, HttpServletResponse response) throws IOException { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; String inputName = request.getParameter("name"); CommonsMultipartFile mFile = (CommonsMultipartFile) multipartRequest.getFile(inputName); if (!mFile.isEmpty()) { String path = this.servletContext.getRealPath("/picUpload/"); SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); String fileName = format.format(new Date()) + "_" + mFile.getOriginalFilename(); File fold = new File(path); if (!fold.exists()) { fold.mkdir();//from www .ja v a 2 s .co m } path = path + "\\" + fileName; // ? File file = new File(path); // response.setContentType("text/html"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); try { mFile.getFileItem().write(file); // out.write("<script>parent.callback(1,'" + fileName + "','" + inputName + "')</script>"); } catch (Exception e) { logger.error(e.getMessage()); out.write("<script>parent.callback(0)</script>"); } } return null; }
From source file:de.phoenix.rs.entity.PhoenixText.java
public File writeToFile(File target) throws IOException { PrintWriter writer = new PrintWriter(target, "UTF-8"); writer.write(text); writer.close();/*from ww w .j a v a 2 s . co m*/ return target; }
From source file:cn.vlabs.umt.ui.actions.ManageUserAction.java
public ActionForward loadUser(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { BeanFactory factory = (BeanFactory) getServlet().getServletContext() .getAttribute(Attributes.APPLICATION_CONTEXT_KEY); UserService us = (UserService) factory.getBean("UserService"); String username = request.getParameter("q"); User u = us.getUserByUid(Integer.valueOf(username)); //JSON/*from ww w . j a v a2s . c o m*/ StringBuffer buffer = new StringBuffer(); buffer.append("[{"); buffer.append("username:'" + u.getCstnetId() + "'"); buffer.append(",truename:'" + u.getTrueName() + "'"); buffer.append(",email:'" + u.getCstnetId() + "'"); buffer.append("}]"); // response.setCharacterEncoding("UTF-8"); PrintWriter writer = response.getWriter(); writer.write(buffer.toString()); writer.flush(); writer.close(); return null; }
From source file:edu.vt.vbi.patric.portlets.JmolPortlet.java
protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { SiteHelper.setHtmlMetaElements(request, response, "3D Structure"); response.setContentType("text/html"); String pdbID = request.getParameter("pdb_id"); if (pdbID != null) { String chainID = request.getParameter("chain_id"); String _context_path = request.getContextPath(); String _codebase = _context_path + "/jmol"; String _datafile = "https://" + request.getServerName() + _context_path + "/jsp/readPDB.jsp?pdbID=" + pdbID;// ww w.j a v a 2 s .com String urlNCBIStructure = "http://www.ncbi.nlm.nih.gov/sites/entrez?db=structure&cmd=DetailsSearch&term="; String urlPDB = "http://www.pdb.org/pdb/explore/explore.do?structureId="; String urlSSGCID = "http://www.ssgcid.org/"; String urlCSGID = "http://www.csgid.org/"; String nameSSGCID = "Seattle Structural Genomics Center for Infectious Disease"; String nameCSGID = "Center for Structural Genomics of Infectious Diseases"; PDBInterface api = new PDBInterface(); Map<String, String> description = api.getDescription(pdbID); if (description != null) { DataApiHandler dataApi = new DataApiHandler(request); List<GenomeFeature> features = new ArrayList<>(); List<String> targetIDs = new ArrayList<>(); // 1. read associated features for given PDB ID // 1.1 read uniprotkb_accession List<String> uniprotKbAccessions = new ArrayList<>(); SolrQuery query = new SolrQuery("id_type:PDB AND id_value:" + pdbID); LOGGER.trace("[{}] {}", SolrCore.ID_REF.getSolrCoreName(), query.toString()); String apiResponse = dataApi.solrQuery(SolrCore.ID_REF, query); Map resp = jsonReader.readValue(apiResponse); Map respBody = (Map<String, Object>) resp.get("response"); int numFound = (Integer) respBody.get("numFound"); if (numFound > 0) { List<Map> records = (List<Map>) respBody.get("docs"); for (Map item : records) { uniprotKbAccessions.add(item.get("uniprotkb_accession").toString()); } } // 1.2 read features with uniprotkb_accession if (!uniprotKbAccessions.isEmpty()) { query = new SolrQuery( "uniprotkb_accession:(" + StringUtils.join(uniprotKbAccessions, " OR ") + ")"); LOGGER.trace("[{}] {}", SolrCore.FEATURE.getSolrCoreName(), query.toString()); apiResponse = dataApi.solrQuery(SolrCore.FEATURE, query); resp = jsonReader.readValue(apiResponse); respBody = (Map<String, Object>) resp.get("response"); features = dataApi.bindDocuments((List<Map>) respBody.get("docs"), GenomeFeature.class); } // 2. retrieve structural meta data if (!uniprotKbAccessions.isEmpty()) { List<String> ids = new ArrayList<>(); for (String uniprotkbAccession : uniprotKbAccessions) { ids.add("\"UniProt:" + uniprotkbAccession + "\""); } query = new SolrQuery("gene_symbol_collection:(" + StringUtils.join(ids, " OR ") + ")"); query.setRows(uniprotKbAccessions.size()); LOGGER.trace("[{}] {}", SolrCore.STRUCTURE.getSolrCoreName(), query.toString()); apiResponse = dataApi.solrQuery(SolrCore.STRUCTURE, query); resp = jsonReader.readValue(apiResponse); respBody = (Map<String, Object>) resp.get("response"); List<Map> sdl = (List<Map>) respBody.get("docs"); for (Map doc : sdl) { targetIDs.add(doc.get("target_id").toString()); } } // request.setAttribute("pdbID", pdbID); request.setAttribute("chainID", chainID); request.setAttribute("_codebase", _codebase); request.setAttribute("_datafile", _datafile); request.setAttribute("urlNCBIStructure", urlNCBIStructure); request.setAttribute("urlPDB", urlPDB); request.setAttribute("urlSSGCID", urlSSGCID); request.setAttribute("urlCSGID", urlCSGID); request.setAttribute("nameSSGCID", nameSSGCID); request.setAttribute("nameCSGID", nameCSGID); request.setAttribute("description", description); // Map<String, String> request.setAttribute("features", features); // List<GenomeFeature> request.setAttribute("targetIDs", targetIDs); // List<String> PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/jmol.jsp"); prd.include(request, response); } else { PrintWriter writer = response.getWriter(); writer.write("No data available."); writer.close(); } } else { PrintWriter writer = response.getWriter(); writer.write("Invalid Parameter - missing context information"); writer.close(); } }
From source file:com.sccl.attech.common.web.BaseController.java
/** * ?response?//from w w w . j av a 2 s . c om * * @param message * @throws IOException */ protected void sendObjectToJson(Object object, HttpServletResponse response) throws IOException { response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter pw = response.getWriter(); String message = JsonMapper.getInstance().toJson(object); pw.write(message); pw.flush(); pw.close(); }
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 ww .j a va 2s . c om*/ //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:com.crawljax.plugins.aji.executiontracer.JSExecutionTracer.java
/** * Retrieves the JavaScript instrumentation array from the webbrowser and writes its contents in * Daikon format to a file./* w ww. jav a 2s . c o m*/ * * @param session * The crawling session. * @param candidateElements * The candidate clickable elements. */ @Override public void preStateCrawling(CrawlSession session, List<CandidateElement> candidateElements) { String filename = getOutputFolder() + EXECUTIONTRACEDIRECTORY + "jsexecutiontrace-"; filename += session.getCurrentState().getName(); DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); Date date = new Date(); filename += dateFormat.format(date) + ".dtrace"; try { LOGGER.info("Reading execution trace"); LOGGER.info("Parsing JavaScript execution trace"); /* FIXME: Frank, hack to send last buffer items and wait for them to arrive */ session.getBrowser().executeJavaScript("sendReally();"); Thread.sleep(ONE_SEC); Trace trace = Trace.parse(points); PrintWriter file = new PrintWriter(filename); file.write(trace.getDeclaration()); file.write('\n'); file.write(trace.getData(points)); file.close(); LOGGER.info("Saved execution trace as " + filename); points = new JSONArray(); } catch (CrawljaxException we) { we.printStackTrace(); LOGGER.error("Unable to get instrumentation log from the browser"); return; } catch (Exception e) { e.printStackTrace(); } }
From source file:controllers.ServerController.java
public void listPrinter(HttpServletRequest request, HttpServletResponse response) { try {/*from w ww. j a v a 2 s. c o m*/ CupsClient client = new CupsClient("192.168.1.230", 631); PrinterBean pb = new PrinterBean(); for (CupsPrinter printer : client.getPrinters()) { String className = printer.getName(); pb.setPrinterList("<div class='printer-menu' id='" + className + "'>" + "<div class='printer-info'>" + "<h3>" + className + "</h3>" + "<div class='queue'>Queue: " + printer.getJobs(WhichJobsEnum.NOT_COMPLETED, null, true).size() + "</div>" + "<div class='status'>Status: On</div>" + "</div>" + "<button class='show-hide-button' onclick=\"showHide('settings-" + className + "')\">Show/Hide settings</button>" + "<span class='delete-printer-button' onclick=\"deletePrinter('" + className + "')\">Delete</span>" + "<div class='settings-statements' id='settings-" + className + "' >" + "<ul>" + "<li><a href='#settings-" + className + "-permissions'>Admin</a></li>" + "<li><a href='#settings-" + className + "-printers'>Design</a></li>" + "<li><a href='#settings-" + className + "-groups'>Sales</a></li>" + "</ul>" + "<div id='settings-" + className + "-permissions'></div>" + "<div id='settings-" + className + "-printers'></div>" + "<div id='settings-" + className + "-groups'></div>" + "</div>" + "</div>"); } if (request.getParameter("fromAjax") == null) { request.setAttribute("printerList", pb); } else { PrintWriter out = response.getWriter(); out.write(pb.getPrinterList()); out.close(); } } catch (Exception ex) { Logger.getLogger(ServerController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.codesourcery.asm.controlflow.ControlFlowGrapher.java
private void MethodDOTRender(MethodNode method, String owner) throws AnalyzerException, FileNotFoundException { ControlFlowGraph graph = analyzer.graphmap.get(formatname(owner) + "#" + method.name); final String dot = new DOTRenderer().render(graph, analyzer.graphmap); final File outputFile; if (outputDir != null) { outputFile = new File(outputDir, toFilename(method) + ".dot"); } else {/*w ww . ja v a 2s .co m*/ outputFile = new File(toFilename(method) + ".dot"); } logVerbose("Writing " + outputFile.getAbsolutePath()); if (!outputFile.getParentFile().exists()) { outputFile.getParentFile().mkdirs(); } final PrintWriter writer = new PrintWriter(outputFile); writer.write(dot); writer.close(); }