List of usage examples for java.io PrintWriter flush
public void flush()
From source file:com.honnix.cheater.admin.AdminClient.java
public void run() { try {// ww w. ja va 2s . co m BufferedReader br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); PrintWriter pw = new PrintWriter(clientSocket.getOutputStream()); pw.print(PROMPT); pw.flush(); while (true) { String command = br.readLine(); if ("status".equals(command)) { pw.println(CheaterConstant.STATUS_MAP.get(server.getCheater().getCurrentStatus())); pw.print(PROMPT); pw.flush(); } else if ("help".equals(command)) { pw.println("status to show current status of cheater"); pw.println("quit to quit administration connection"); pw.println("shutdown to shutdown cheater"); pw.println("help to show this message"); pw.print(PROMPT); pw.flush(); } else if ("shutdown".equals(command)) { clientSocket.close(); server.stop(); server.getCheater().stop(); break; } else if ("quit".equals(command) || command == null) { server.setHasClient(false); clientSocket.close(); break; } else { pw.println(new StringBuilder("Unknown command,").append(" use \"status|quit|shutdown|help\".") .toString()); pw.print(PROMPT); pw.flush(); } } } catch (IOException e) { LOG.error("Error operating client socket.", e); } finally { try { clientSocket.close(); } catch (IOException e) { LOG.error("Error closing client socket.", e); } } }
From source file:org.eurekastreams.server.service.servlets.GetThemeCssServlet.java
/** * {@inheritDoc}/*from ww w .j a va 2 s .c om*/ */ @Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { // grab items from spring context if not initialized, 500 error if unable try { initializeSpringObjects(); } catch (Exception e) { httpError(HttpStatus.SC_INTERNAL_SERVER_ERROR, response); return; } // Convert request to theme uuid, 400 if error. String themeUuid = null; try { themeUuid = requestUriToThemeUuIdTransformer.transform(request.getRequestURI()); // StringUtils.isEmpty checks for null or empty string, String.isEmtpy only checks length if (StringUtils.isEmpty(themeUuid)) { httpError(HttpStatus.SC_BAD_REQUEST, response); return; } } catch (Exception e) { httpError(HttpStatus.SC_BAD_REQUEST, response); return; } // get the string css by theme uuid, 404 on error. String themeCss = null; try { themeCss = getThemeCssByUuidMapper.execute(themeUuid); } catch (Exception e) { httpError(HttpStatus.SC_NOT_FOUND, response); return; } response.setContentType("text/css"); response.setContentLength(themeCss.getBytes().length); PrintWriter out = response.getWriter(); out.write(themeCss); out.flush(); }
From source file:edu.cornell.mannlib.vitro.webapp.sparql.GetClazzObjectProperties.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!isAuthorizedToDisplayPage(request, response, SimplePermission.USE_MISCELLANEOUS_PAGES.ACTION)) { return;//from www. j ava2s. co m } VitroRequest vreq = new VitroRequest(request); String vClassURI = vreq.getParameter("vClassURI"); if (vClassURI == null || vClassURI.trim().equals("")) { return; } String respo = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; respo += "<options>"; 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>" + "</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:gov.hhs.fha.nhinc.lift.proxy.util.DemoProtocol.java
@Override public void sendLine(String mess) throws IOException { log.debug("Protocol handshake on socket " + socket.getInetAddress() + ": " + socket.getPort()); socket.startHandshake();/*from w w w . j av a 2 s .c om*/ PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()))); out.println(mess); out.flush(); }
From source file:es.eucm.mokap.backend.server.MokapBackend.java
/** * Method: POST Processes post requests. * //from ww w. j a v a2 s . c om * <pre> * - Requests must be multipart/form-data. * - The field with the file must be named "file". * - The file must be a .zip compressed file with the structure * defined in {@link UploadZipStructure}. * </pre> */ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { MokapInsertController iCont = new MokapInsertController(); // Check api key if (!ApiKeyVerifier.checkApiKey(req, resp)) { return; } else { try { // Get the uploaded file stream FileItemStream fis = getUploadedFile(req); if (fis != null) { // Actually process the uploaded resource String str = iCont.processUploadedResource(fis); // Send the response PrintWriter out = resp.getWriter(); out.print(str); out.flush(); out.close(); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, ServerReturnMessages.INVALID_UPLOAD_FILENOTFOUND); } } catch (Exception e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ServerReturnMessages.m(ServerReturnMessages.GENERIC_INTERNAL_ERROR, e.getMessage())); } } }
From source file:com.linuxbox.enkive.message.AbstractMessage.java
protected String getUnpatchedEmail() throws IOException { StringWriter out = new StringWriter(); PrintWriter writer = new PrintWriter(out); writer.print(originalHeaders);/*from ww w. j a va2s. com*/ writer.flush(); contentHeader.pushReconstitutedEmail(writer); return out.toString(); }
From source file:bookUtilities.HomePageBooksServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . j a v a 2 s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); //Get the top four most recently added books JSONArray newestBooks = getNewestBooks(); //Gets the top four most checked out books getPopularBooks(newestBooks); //Returns the data to the front end PrintWriter printout = response.getWriter(); printout.print(newestBooks); printout.flush(); }
From source file:gov.nih.nci.cabig.caaers.tools.spring.tabbedflow.SimpleFormAjaxableController.java
protected void respondAjaxFreeText(ModelAndView modelAndView, HttpServletResponse response) throws Exception { PrintWriter pr = response.getWriter(); pr.println(modelAndView.getModel().get(getFreeTextModelName())); pr.flush(); pr.close();/*from w ww . j av a 2s . com*/ }
From source file:presentation.webgui.vitroappservlet.VisualStyles.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); this.uStyleId = request.getParameter("suid"); Model3dStylesList myStylesIndex = Model3dStylesList.getModel3dStylesList(); Model3dStylesEntry currStyleEntry = myStylesIndex.getStyleWithId(this.uStyleId); if (currStyleEntry != null) { response.setContentType("image/png"); OutputStream out = response.getOutputStream(); try {/*from ww w .ja v a 2s. c om*/ JFreeChart chart = StyleCreator.createDatasetAndChart(currStyleEntry); int chartHeight = 40; if (chart.getCategoryPlot().getDataset().getColumnKeys().size() > 1) { chartHeight = chart.getCategoryPlot().getDataset().getColumnKeys().size() * 22; } ChartUtilities.writeChartAsPNG(out, chart, 300, chartHeight); } catch (Exception e) { System.err.println(e.toString()); response.setContentType("text/html"); PrintWriter outPrintWriter = response.getWriter(); outPrintWriter.print("<b>Error</b>:" + e.toString()); outPrintWriter.flush(); outPrintWriter.close(); } finally { out.close(); } return; } else { response.setContentType("text/html"); PrintWriter outPrintWriter = response.getWriter(); outPrintWriter.print("<b>No style defined</b>"); outPrintWriter.flush(); outPrintWriter.close(); } }
From source file:es.eucm.mokap.backend.server.MokapBackend.java
/** * Method: GET Processes get requests to perform a search. It performs an * index search with the keyword in that header. Requires a valid api key to * work.//from w ww.ja v a2s.c om */ @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) { MokapSearchController sCont = new MokapSearchController(); // Check api key try { if (!ApiKeyVerifier.checkApiKey(req, resp)) { PrintWriter out = resp.getWriter(); out.print("Wrong API key."); out.flush(); out.close(); } else { PrintWriter out = resp.getWriter(); // Get the parameters from the header / parameter SearchParams sp = SearchParamsFactory.create(req); String str = sCont.performSearch(sp); // Set the response encoding resp.setCharacterEncoding("UTF-8"); resp.setContentType("application/json"); out.print(str); out.flush(); out.close(); } } catch (Exception e) { e.printStackTrace(); } }