List of usage examples for java.io PrintWriter flush
public void flush()
From source file:com.sap.prd.mobile.ios.ota.webapp.OtaPlistService.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from w w w . j a v a2 s . com*/ Map<String, String> params = getParametersAndReferer(request, response, false); Map<String, String> slashedParams = extractSlashedEncodedParametersFromUri(request, getPlistServletMappingUrlPattern(request)); dubParameters(KEY_REFERER, params, slashedParams, false); dubParameters(KEY_TITLE, params, slashedParams, true); dubParameters(KEY_BUNDLE_IDENTIFIER, params, slashedParams, true); dubParameters(KEY_BUNDLE_VERSION, params, slashedParams, true); dubParameters(KEY_IPA_CLASSIFIER, params, slashedParams, true); dubParameters(KEY_OTA_CLASSIFIER, params, slashedParams, true); dubParameters(KEY_ACTION, params, slashedParams, true); LOG.info(String.format("GET request from '%s' with referer '%s' and parameters %s", request.getRemoteAddr(), params.get(KEY_REFERER), params)); if (params.get(KEY_REFERER) == null) { response.sendError(400, "Referer required"); return; } final String action = params.get(KEY_ACTION); if (StringUtils.equals(action, KEY_QRCODE)) { String plistUrl = generatePlistRequestUrl(getPlistServiceBaseUrl(request), params).toExternalForm(); String data = plistUrl + "?action=itmsRedirect"; LOG.fine("Sending QRCode for " + data); sendQRCode(request, response, data, getMatrixToImageConfig(request), new Dimension(400, 400)); } else if (StringUtils.equals(action, KEY_ITMS_REDIRECT)) { URL plistUrl = generatePlistRequestUrl(getPlistServiceBaseUrl(request), params); String itmsServiceLink = "itms-services:///?action=download-manifest&url=" + plistUrl.toExternalForm(); LOG.fine("Sending ItmsServiceRedirect for " + itmsServiceLink); response.sendRedirect(itmsServiceLink); } else { response.setContentType("application/xml"); PrintWriter writer = response.getWriter(); OtaPlistGenerator.getInstance().generate(writer, new Parameters(params)); writer.flush(); } } catch (Exception e) { LOG.log(SEVERE, format("Exception while processing GET request from '%s' (%s)", request.getRemoteAddr(), Utils.getRequestInfosForLog(request)), e); } }
From source file:org.mule.module.http.functional.listener.HttpListenerPersistentConnectionsTestCase.java
private void sendRequest(Socket socket, HttpVersion httpVersion) throws IOException { PrintWriter writer = new PrintWriter(socket.getOutputStream()); writer.println("GET / " + httpVersion); writer.println("Host: www.example.com"); writer.println(""); writer.flush(); }
From source file:org.clothocad.phagebook.controllers.AutoCompleteController.java
@RequestMapping(value = "/autoCompleteVendors", method = RequestMethod.GET) protected void autoCompleteVendors(@RequestParam Map<String, String> params, HttpServletResponse response) throws ServletException, IOException { //I WILL RETURN THE MAP AS A JSON OBJECT.. it is client side's issue to parse all data for what they need! //they could check over there if the schema matches what they are querying for and so i can do this generically! //user should be logged in so I will log in as that user. String name = params.get("name") != null ? params.get("name") : ""; boolean isValid = false; System.out.println("Name is: " + name); if (!name.equals("")) { isValid = true;/*from ww w .ja v a 2 s . co m*/ } if (isValid) { ClothoConnection conn = new ClothoConnection(Args.clothoLocation); Clotho clothoObject = new Clotho(conn); //TODO: we need to have an authentication token at some point String username = this.backendPhagebookUser; String password = this.backendPhagebookPassword; Map loginMap = new HashMap(); loginMap.put("username", username); loginMap.put("credentials", password); clothoObject.login(loginMap); Map query = new HashMap(); query.put("query", name); // the value for which we are querying. query.put("key", "name"); // the key of the object we are querying List<Vendor> vendors = ClothoAdapter.queryVendor(query, clothoObject, ClothoAdapter.QueryMode.STARTSWITH); org.json.JSONArray responseArray = new org.json.JSONArray(); for (Vendor vend : vendors) { JSONObject obj = new JSONObject(); obj.put("id", vend.getId()); obj.put("name", vend.getName()); responseArray.put(obj); } response.setStatus(HttpServletResponse.SC_ACCEPTED); response.setContentType("application/json"); PrintWriter out = response.getWriter(); out.print(responseArray); out.flush(); out.close(); clothoObject.logout(); conn.closeConnection(); } response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.setContentType("application/json"); JSONObject reply = new JSONObject(); reply.put("message", "Auto Complete requires a query parameter"); PrintWriter out = response.getWriter(); out.print(reply); out.flush(); out.close(); }
From source file:org.clothocad.phagebook.controllers.AutoCompleteController.java
@RequestMapping(value = "/autoCompleteProjects", method = RequestMethod.GET) protected void autoCompleteProjects(@RequestParam Map<String, String> params, HttpServletResponse response) throws ServletException, IOException { //I WILL RETURN THE MAP AS A JSON OBJECT.. it is client side's issue to parse all data for what they need! //they could check over there if the schema matches what they are querying for and so i can do this generically! //user should be logged in so I will log in as that user. String name = params.get("name") != null ? params.get("name") : ""; boolean isValid = false; System.out.println("Name is: " + name); if (!name.equals("")) { isValid = true;/*from w w w .j av a 2s .co m*/ } if (isValid) { ClothoConnection conn = new ClothoConnection(Args.clothoLocation); Clotho clothoObject = new Clotho(conn); //TODO: we need to have an authentication token at some point String username = this.backendPhagebookUser; String password = this.backendPhagebookPassword; Map loginMap = new HashMap(); loginMap.put("username", username); loginMap.put("credentials", password); clothoObject.login(loginMap); Map query = new HashMap(); query.put("query", name); // the value for which we are querying. query.put("key", "name"); // the key of the object we are querying List<Project> projects = ClothoAdapter.queryProject(query, clothoObject, ClothoAdapter.QueryMode.STARTSWITH); org.json.JSONArray responseArray = new org.json.JSONArray(); for (Project proj : projects) { JSONObject obj = new JSONObject(); obj.put("id", proj.getId()); obj.put("name", proj.getName()); responseArray.put(obj); } response.setStatus(HttpServletResponse.SC_ACCEPTED); response.setContentType("application/json"); PrintWriter out = response.getWriter(); out.print(responseArray); out.flush(); out.close(); clothoObject.logout(); conn.closeConnection(); } response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.setContentType("application/json"); JSONObject reply = new JSONObject(); reply.put("message", "Auto Complete requires a query parameter"); PrintWriter out = response.getWriter(); out.print(reply); out.flush(); out.close(); }
From source file:cc.creativecomputing.io.CCIOUtil.java
static public void saveStrings(OutputStream output, String strings[]) { PrintWriter writer = new PrintWriter(new OutputStreamWriter(output)); for (int i = 0; i < strings.length; i++) { writer.println(strings[i]);//from w w w .ja va 2 s . c o m } writer.flush(); }
From source file:chat.com.server.ChatServer.java
private void updateUserOnline() { int s = map.size(); JSONArray arr = new JSONArray(); for (String key : map.keySet()) { // add user online arr.add(key);// ww w . jav a 2s . co m } JSONObject jsonUpdateUser = new JSONObject(); jsonUpdateUser.put("type", "userOnline"); jsonUpdateUser.put("listUser", arr); String json = jsonUpdateUser.toString(); for (String key : map.keySet()) { // send message to all PrintWriter writer = map.get(key); writer.println(json); writer.flush(); } }
From source file:de.erdesignerng.test.BaseERDesignerTestCaseImpl.java
protected String statementListToString(StatementList aStatements, SQLGenerator aGenerator) { StringWriter theStringWriter = new StringWriter(); PrintWriter thePrintWriter = new PrintWriter(theStringWriter); for (Statement theStatement : aStatements) { thePrintWriter.print(theStatement.getSql()); thePrintWriter.println(aGenerator.createScriptStatementSeparator()); }//ww w. j av a2 s . c om thePrintWriter.flush(); return theStringWriter.toString().trim(); }
From source file:edu.cornell.mannlib.vitro.webapp.sparql.GetClazzAllProperties.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!isAuthorizedToDisplayPage(request, response, SimplePermission.USE_MISCELLANEOUS_PAGES.ACTION)) { return;/* w ww . ja va2 s .c o m*/ } VitroRequest vreq = new VitroRequest(request); String vClassURI = vreq.getParameter("vClassURI"); if (vClassURI == null || vClassURI.trim().equals("")) { return; } Map<String, String> hm = new HashMap(); // Get Data Properties // Add rdfs:label to the list hm.put("label", "http://www.w3.org/2000/01/rdf-schema#label0"); /* * respo += "<option>" + "<key>" + "label" + "</key>" + "<value>" + * "http://www.w3.org/2000/01/rdf-schema#label" + "</value>" + * "<type>0</type>" + "</option>"; */ DataPropertyDao ddao = vreq.getUnfilteredWebappDaoFactory().getDataPropertyDao(); Collection<DataProperty> dataProps = ddao.getDataPropertiesForVClass(vClassURI); Iterator<DataProperty> dataPropIt = dataProps.iterator(); HashSet<String> dpropURIs = new HashSet<String>(); while (dataPropIt.hasNext()) { DataProperty dp = dataPropIt.next(); if (!(dpropURIs.contains(dp.getURI()))) { dpropURIs.add(dp.getURI()); DataProperty dprop = (DataProperty) ddao.getDataPropertyByURI(dp.getURI()); if (dprop != null) { if (dprop.getLocalName() != null || !dprop.getLocalName().equals("")) { hm.put(dprop.getLocalName(), dprop.getURI() + "0"); } /* * respo += "<option>" + "<key>" + dprop.getLocalName() + * "</key>" + "<value>" + dprop.getURI() + "</value>" + * "<type>0</type>" + "</option>"; */ } } } // Get Object Properties ObjectPropertyDao odao = vreq.getUnfilteredWebappDaoFactory().getObjectPropertyDao(); PropertyInstanceDao piDao = vreq.getUnfilteredWebappDaoFactory().getPropertyInstanceDao(); VClassDao vcDao = vreq.getUnfilteredWebappDaoFactory().getVClassDao(); // incomplete list of classes to check, but better than before List<String> superclassURIs = vcDao.getAllSuperClassURIs(vClassURI); superclassURIs.add(vClassURI); superclassURIs.addAll(vcDao.getEquivalentClassURIs(vClassURI)); Map<String, PropertyInstance> propInstMap = new HashMap<String, PropertyInstance>(); for (String classURI : superclassURIs) { Collection<PropertyInstance> propInsts = piDao.getAllPropInstByVClass(classURI); try { for (PropertyInstance propInst : propInsts) { propInstMap.put(propInst.getPropertyURI(), propInst); } } catch (NullPointerException ex) { continue; } } List<PropertyInstance> propInsts = new ArrayList<PropertyInstance>(); propInsts.addAll(propInstMap.values()); Collections.sort(propInsts); Iterator propInstIt = propInsts.iterator(); HashSet opropURIs = new HashSet(); while (propInstIt.hasNext()) { PropertyInstance pi = (PropertyInstance) propInstIt.next(); if (!(opropURIs.contains(pi.getPropertyURI()))) { opropURIs.add(pi.getPropertyURI()); ObjectProperty oprop = (ObjectProperty) odao.getObjectPropertyByURI(pi.getPropertyURI()); if (oprop != null) { /* * respo += "<option>" + "<key>" + oprop.getLocalName() + * "</key>" + "<value>" + oprop.getURI() + "</value>" + * "<type>1</type>" + "</option>"; */ if (oprop.getLocalName() != null || !oprop.getLocalName().equals("")) { hm.put(oprop.getLocalName(), oprop.getURI() + "1"); } } } } String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; respo += "<options>"; Object[] keys = hm.keySet().toArray(); Arrays.sort(keys); for (int i = 0; i < keys.length; i++) { String key = (String) keys[i]; String value = hm.get(key); respo += "<option>" + "<key>" + key + "</key>" + "<value>" + value.substring(0, value.length() - 1) + "</value>" + "<type>" + value.charAt(value.length() - 1) + "</type>" + "</option>"; } respo += "</options>"; response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.println(respo); out.flush(); out.close(); }
From source file:com.library.essay.tinymce.spellchecker.GoogleSpellChekerServlet.java
private void sendData(String xml) throws IOException { uc.setDoOutput(true);/* w w w . ja v a 2s.c om*/ PrintWriter pw = new PrintWriter(uc.getOutputStream()); System.out.println("-------------------" + xml); pw.print(xml); pw.flush(); }
From source file:com.sccl.attech.common.web.BaseController.java
/** * ?response?/*from w w w. j a v a2 s. c o m*/ * * @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(); }