List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:it.unibz.instasearch.ui.ReportErrorDialog.java
private void addProperty(PrintWriter b, String prop, String val) { b.print(prop); b.print(": "); b.println(val); }
From source file:com.test.servlet.SyncController.java
@Override public void setResponse(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action;//w w w . j a v a 2 s . com int deleteCount = -1; int addCount = -1; List<String> items = null; PrintWriter writer = response.getWriter(); if (!hasParam(RequestParam.action.toString())) { writer.print(Utility.generalErrorMessage(ResponseCode.missing_parameter.toString(), "Parameter 'action' is required")); return; } action = getParam(RequestParam.action.toString()); if ("sync".equals(action) && !hasParam(RequestParam.add.toString()) && !hasParam(RequestParam.delete.toString())) { writer.print(Utility.generalErrorMessage(ResponseCode.missing_parameter.toString(), "You must specify either 'add[]' or 'delete[]' array, or both.")); return; } DBUtility db = new DBUtility(servlet); if ("sync".equals(action)) { String[] addP = requestParams.get(RequestParam.add.toString()); String[] deleteP = requestParams.get(RequestParam.delete.toString()); if (addP != null) { db.insertItemsInTx(addP, servlet.getUserId()); addCount = addP.length; } if (deleteP != null) { List<String> delete = Arrays.asList(deleteP); db.deleteItemsInTx(deleteP, servlet.getUserId()); deleteCount = deleteP.length; } } else if ("get_all".equals(action)) { items = db.getUsersItems(servlet.getUserId()); } else { writer.print(Utility.generalErrorMessage(ResponseCode.invalid_parameter.toString(), "Invalid action '" + action + "'.")); return; } JSONObject object = new JSONObject(); object.put(JSONKey.status.toString(), 1); if (deleteCount != -1) object.put(JSONKey.deleted.toString(), deleteCount); if (addCount != -1) object.put(JSONKey.added.toString(), addCount); if (items != null) { JSONArray jsonArray = new JSONArray(items); object.put(JSONKey.items.toString(), jsonArray); } writer.print(object.toString(4)); }
From source file:org.loklak.api.server.UserServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RemoteAccess.Post post = RemoteAccess.evaluate(request); // manage DoS if (post.isDoS_blackout()) { response.sendError(503, "your request frequency is too high"); return;//from w w w . j a v a 2 s .c o m } // parameters String callback = post.get("callback", ""); boolean jsonp = callback != null && callback.length() > 0; boolean minified = post.get("minified", false); String[] screen_names = post.get("screen_name", "").split(","); String followers = screen_names.length == 1 ? post.get("followers", "0") : "0"; String following = screen_names.length == 1 ? post.get("following", "0") : "0"; int maxFollowers = Integer.parseInt(followers); int maxFollowing = Integer.parseInt(following); List<Map<String, Object>> twitterUserEntries = new ArrayList<>(); for (String screen_name : screen_names) { try { Map<String, Object> twitterUserEntry = TwitterAPI.getUser(screen_name, false); if (twitterUserEntry != null) { TwitterAPI.enrichLocation(twitterUserEntry); twitterUserEntries.add(twitterUserEntry); } } catch (TwitterException e) { } } Map<String, Object> topology = null; try { topology = TwitterAPI.getNetwork(screen_names[0], maxFollowers, maxFollowing); } catch (TwitterException e) { } post.setResponse(response, "application/javascript"); // generate json Map<String, Object> m = new LinkedHashMap<>(); Map<String, Object> metadata = new LinkedHashMap<>(); metadata.put("client", post.getClientHost()); m.put("search_metadata", metadata); if (twitterUserEntries.size() == 1) m.put("user", twitterUserEntries.iterator().next()); if (twitterUserEntries.size() > 1) m.put("users", twitterUserEntries); if (topology != null) m.put("topology", topology); // write json response.setCharacterEncoding("UTF-8"); PrintWriter sos = response.getWriter(); if (jsonp) sos.print(callback + "("); sos.print((minified ? new ObjectMapper().writer() : new ObjectMapper().writerWithDefaultPrettyPrinter()) .writeValueAsString(m)); if (jsonp) sos.println(");"); sos.println(); sos.flush(); sos.close(); post.finalize(); }
From source file:mack.servlets.TransfServlet.java
private void geraXSL() throws IOException { HttpClient cliente = HttpClients.createDefault(); HttpGet httpget = new HttpGet("http://localhost:8081/AppFrontController/dados/gpx.xsl"); HttpResponse resposta = cliente.execute(httpget); System.out.println("----------------------------------------"); System.out.println(resposta.getStatusLine()); HttpEntity entity = resposta.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); StringBuilder out = new StringBuilder(); String line;/*from w ww . j a v a 2 s . c o m*/ while ((line = reader.readLine()) != null) { out.append(line); } PrintWriter w = new PrintWriter("/temp/gpx.xsl"); w.print(out.toString()); w.flush(); w.close(); reader.close(); instream.close(); } }
From source file:controller.ProductProcess.java
public String processImage(HttpServletRequest request, HttpServletResponse response) throws IOException { if (!ServletFileUpload.isMultipartContent(request)) { PrintWriter writer = response.getWriter(); writer.print("error"); return ""; }//from w ww . j a v a 2 s. c o m String pathh = ""; DiskFileItemFactory factory = new DiskFileItemFactory(MEMORY_THRESHOLD, new File(System.getProperty("java.io.tmpdir"))); ServletFileUpload upload = new ServletFileUpload(factory); upload.setFileSizeMax(MAX_FILE_SIZE); upload.setSizeMax(MAX_REQUEST_SIZE); String uploadPath = getServletContext().getRealPath("") + File.separator + UPLOAD_DIRECTORY; File uploadDir = new File(uploadPath); if (!uploadDir.exists()) { uploadDir.mkdir(); } try { List<FileItem> formItems = upload.parseRequest(request); if (formItems != null && formItems.size() > 0) { for (FileItem formItem : formItems) { if (!formItem.isFormField()) { String a = formItem.getName(); String fileName = new File(a).getName(); pathh = fileName; String filePath = uploadPath + File.separator + fileName; File storeFile = new File(filePath); formItem.write(storeFile); } else { String nameAttribute = formItem.getFieldName(); String valueAttribute = formItem.getString("UTF-8"); request.setAttribute(nameAttribute, valueAttribute); } } } } catch (Exception e) { e.printStackTrace(); return ""; } return pathh; }
From source file:com.vmware.photon.controller.api.frontend.lib.ova.OvaTestModule.java
private void generateOvaFile(String ovaName, String ovfName, String ovfContent, String vmdkName, String vmdkContent) throws IOException, InterruptedException { PrintWriter out = new PrintWriter(new File(fileLocation, ovfName)); out.print(ovfContent); out.close();/* w w w . java2 s . com*/ out = new PrintWriter(new File(fileLocation, vmdkName)); out.print(vmdkContent); out.close(); Runtime.getRuntime().exec(String.format("tar cvf %s %s %s --format ustar", ovaName, ovfName, vmdkName), null, new File(fileLocation)).waitFor(); }
From source file:mack.servlets.TransfServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www . java 2s . com * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ private void geraXML() throws FileNotFoundException, IOException { HttpClient cliente = HttpClients.createDefault(); HttpGet httpget = new HttpGet("http://localhost:8081/AppFrontController/LP3Rest/lp3/posicoesXML/denis"); HttpResponse resposta = cliente.execute(httpget); System.out.println("----------------------------------------"); System.out.println(resposta.getStatusLine()); HttpEntity entity = resposta.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); StringBuilder out = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { out.append(line); } PrintWriter w = new PrintWriter("/temp/posicao.xml"); w.print(out.toString()); w.flush(); w.close(); reader.close(); instream.close(); } }
From source file:com.concursive.connect.web.webdav.resources.WebdavFolderResource.java
@Override protected void sendContentMiddle(final PrintWriter printer) { super.sendContentMiddle(printer); printer.print("file upload field"); printer.print("<form method='POST' enctype='multipart/form-data' action='" + this.getHref() + "'>"); printer.print("<input type='file' name='file1' /><input type='submit'>"); printer.print("</form>"); }
From source file:it.cilea.osd.jdyna.web.controller.ExportConfigurazioneSoggettari.java
/** * Esporta la configurazione corrente di tutti i soggettari o, * se la request contiene un soggettario_id, solo il soggettario con * quell'ID specifico.// w w w.j a va 2s .c om * */ @Override protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object object, BindException errors) throws RuntimeException, IOException { String soggettarioIDStr = request.getParameter("soggettario_id"); Integer soggettarioID = null; if (soggettarioIDStr != null) { soggettarioID = Integer.parseInt(soggettarioIDStr); } Soggettario soggettario = null; if (soggettarioID != null) { soggettario = applicationService.get(Soggettario.class, soggettarioID); } String filename; if (soggettario == null) { filename = "configurazione-soggettari.xml"; } else { filename = "configurazione-soggettario_" + soggettario.getNome().replaceAll(" ", "_") + ".xml"; } response.setContentType("application/xml"); response.addHeader("Content-Disposition", "attachment; filename=" + filename); PrintWriter writer = response.getWriter(); writer.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE beans PUBLIC \"-//SPRING//DTD BEAN//EN\"\n" + "\"http://www.springframework.org/dtd/spring-beans.dtd\">\n\n\n"); writer.print("<beans>\n"); writer.print(" <!-- Configurazioni per il tool di import (NON MODIFICARE) -->\n"); writer.print( " <bean id=\"customEditorConfigurer\" class=\"org.springframework.beans.factory.config.CustomEditorConfigurer\">\n"); writer.print(" <property name=\"customEditors\">\n"); writer.print(" <map>\n"); writer.print(" <entry key=\"it.cilea.osd.jdyna.model.Soggettario\">\n"); writer.print(" <ref bean=\"configurazioneSoggettarioEditor\"/>\n"); writer.print(" </entry>\n"); writer.print(" </map>\n"); writer.print(" </property>\n"); writer.print(" </bean>\n"); if (soggettario != null) { toXML(writer, soggettario); } else { List<Soggettario> allSoggettari = applicationService.getList(Soggettario.class); for (Soggettario soggettarioIter : allSoggettari) { toXML(writer, soggettarioIter); } } response.getWriter().print("</beans>"); return null; }
From source file:com.mebigfatguy.polycasso.JavaSaver.java
private String getTransparencyData(PolygonData[] data) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println();/* www .ja v a2 s .c o m*/ pw.print(TABS); String comma = ""; for (PolygonData pd : data) { pw.print(comma); pw.print(pd.getAlpha()); pw.print("f"); comma = ","; } pw.flush(); return sw.toString(); }