List of usage examples for java.io Writer write
public void write(String str) throws IOException
From source file:Main.java
public static void writeDocument(Document doc, Writer out) throws IOException { // happy to replace this code w/ the non-deprecated code, but I couldn't get the transformer // approach to work. // OutputFormat format = new OutputFormat(doc); // format.setIndenting(true); // format.setIndent(2); // XMLSerializer serializer = new XMLSerializer(out, format); // serializer.serialize(doc); DOMImplementationLS impl = (DOMImplementationLS) doc.getImplementation(); LSSerializer writer = impl.createLSSerializer(); DOMConfiguration config = writer.getDomConfig(); if (config.canSetParameter("format-pretty-print", Boolean.TRUE)) { config.setParameter("format-pretty-print", Boolean.TRUE); }/*from ww w . ja v a2 s. co m*/ // what a crappy way to force the stream to be UTF-8. yuck! ByteArrayOutputStream baos = new ByteArrayOutputStream(); LSOutput output = impl.createLSOutput(); output.setEncoding("UTF-8"); output.setByteStream(baos); writer.write(doc, output); out.write(baos.toString()); out.flush(); }
From source file:info.magnolia.cms.gui.dialog.DialogBox.java
public void drawHtmlPost(Writer out) throws IOException { out.write(this.getHtmlDescription()); out.write("</td></tr>"); //$NON-NLS-1$ }
From source file:com.ewcms.component.interaction.web.servlate.JavaScriptServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String encoding = getParameterValue(request, HEADER_ENCODING); encoding = (encoding == null ? DEFAULT_ENCODING : encoding); initResponseHeader(response, encoding); Integer type = 1;//from w w w . ja v a 2 s . c o m String interaction_type = getParameterValue(request, INTERACTION_TYPE); try { type = Integer.valueOf(interaction_type); } catch (Exception e) { } String callback = getParameterValue(request, CALLBACK_PARAMETER_NAME); String value; if (callback == null) { value = "alert('?');"; } else { InteractionServiceable service = getInteractionService(); String json = service.mainJSON(type); value = String.format("%s(%s);", callback, json); } Writer writer = response.getWriter(); writer.write(value); writer.flush(); }
From source file:com.github.dbourdette.otto.web.controller.IndexController.java
@RequestMapping("/state") public void state(HttpServletResponse response) throws IOException { Writer writer = response.getWriter(); for (Source source : Source.findAll()) { writer.write(source.toString()); }//from w ww .j a va 2s . com }
From source file:com.googlecode.jsfFlex.phaseListener.XMLServiceRequestDataRetrieverFlusher.java
@Override void retrieveFlushData(FacesContext context, String componentId, String methodToInvoke) throws ServletException, IOException { Collection<? extends Object> objectCollection = null; try {//from ww w.ja v a 2s. co m objectCollection = (Collection<? extends Object>) invokeResourceMethod(context, componentId, methodToInvoke, null, null); } catch (Exception methodInvocationException) { throw new ServletException(methodInvocationException); } HttpServletResponse response = HttpServletResponse.class.cast(context.getExternalContext().getResponse()); response.setContentType(XML_CONTENT_TYPE); StringBuilder responseContent = new StringBuilder(); responseContent.append(XML_HEAD); responseContent.append(XML_RESULT_ROOT_START_TAG); if (objectCollection != null) { for (Object currObj : objectCollection) { responseContent.append(XML_VALUE_START_TAG); responseContent.append(currObj.toString()); responseContent.append(XML_VALUE_END_TAG); } } responseContent.append(XML_RESULT_ROOT_END_TAG); _log.info("Flushing content : " + responseContent.toString()); Writer writer = response.getWriter(); writer.write(responseContent.toString()); writer.flush(); }
From source file:com.googlecode.jsfFlex.phaseListener.ObjectServiceRequestDataRetrieverFlusher.java
@Override void retrieveFlushData(FacesContext context, String componentId, String methodToInvoke) throws ServletException, IOException { JSONObject methodResult = null;/*from w ww. ja va 2 s .c om*/ try { methodResult = JSONObject.class .cast(invokeResourceMethod(context, componentId, methodToInvoke, null, null)); } catch (Exception methodInvocationException) { throw new ServletException(methodInvocationException); } HttpServletResponse response = HttpServletResponse.class.cast(context.getExternalContext().getResponse()); response.setContentType(XML_CONTENT_TYPE); StringBuilder responseContent = new StringBuilder(); responseContent.append(XML_HEAD); try { responseContent.append(JSONConverter.convertJSONObjectToXMLString(methodResult)); } catch (JSONException jsonException) { throw new ServletException(ERROR_CONVERTING_JSON_OBJECT_TO_XML, jsonException.getCause()); } _log.info("Flushing content : " + responseContent.toString()); Writer writer = response.getWriter(); writer.write(responseContent.toString()); writer.flush(); }
From source file:com.ewcms.component.comment.web.CounterServlet.java
private void responseJSON(HttpServletRequest request, HttpServletResponse response, final String encoding, final CommentCount count) throws IOException { initResponseHeader(response, encoding); String callback = request.getParameter("jsoncallback"); String value = String.format("%s({\"commentCounter\":\"%d\",\"personCounter\":\"%d\"});", callback, count.getCommentCounter(), count.getPersonCounter()); Writer writer = response.getWriter(); writer.write(value); writer.flush();// w w w.ja va 2s . c o m }
From source file:data_gen.Data_gen.java
private static void Build_dat_file(String config_dir, long startTime) throws IOException { String header = ""; File f = new File(output_dir + "/" + Default_DataSet_name); Writer wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "ISO-8859-1")); fields = Parse_Document_fields(config_dir); Iterator iterator1 = fields.keySet().iterator(); while (iterator1.hasNext()) { String Key = (String) iterator1.next(); header += '\u00FE' + Key + '\u00FE' + '\u0014'; }//from w w w .ja v a 2 s . c o m wr.write(header.trim() + (char) 13 + (char) 10); //////////////////////////////////////////////////// flow control: (for loop) for number of //////////////////////////////////////////////////// documents and (while) for each field in document for (int i = 0; i <= documents_count; i++) { String Doc = ""; fields = Parse_Document_fields(config_dir); Iterator iterator = fields.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); String v = (String) fields.get(key); String value = generate_facet_value(v); if (value.startsWith("integer.key")) { integer_key(fields, key, value); String temp = (String) fields.get(key); Doc += (char) 254 + temp + (char) 254 + '\u0014'; } if (value.startsWith("seq.integer")) { seq_integer(fields, key, value); String temp = (String) fields.get(key); Doc += (char) 254 + temp + (char) 254 + '\u0014'; } if (value.startsWith("range")) { range_integer(fields, key, value); String temp = (String) fields.get(key); Doc += (char) 254 + temp + (char) 254 + '\u0014'; } if (value.charAt(0) == '[') { single_enum(fields, key, value); String temp = (String) fields.get(key); Doc += (char) 254 + temp + (char) 254 + '\u0014'; } if (value.startsWith("multi")) { multi_enum_dat(fields, key, value); String temp = (String) (fields.get(key)); Doc += (char) 254 + temp + (char) 254 + '\u0014'; } if (value.startsWith("date")) { generate_date(fields, key, value); String temp = (String) fields.get(key); Doc += (char) 254 + temp + (char) 254 + '\u0014'; } if (value.equals("text.key")) { generate_Text_dat(fields, key); String temp = (String) fields.get(key); Doc += (char) 254 + temp + (char) 254 + '\u0014'; } if (value.equals("text")) { generate_Text_dat(fields, key); String temp = (String) fields.get(key); Doc += (char) 254 + temp + (char) 254 + '\u0014'; } if (value.startsWith("(")) { String VALUE = value.substring(1, value.length() - 1); fields.put(key, VALUE); String temp = (String) fields.get(key); Doc += (char) 254 + temp + (char) 254 + '\u0014'; } } wr.write(Doc.trim() + (char) 13 + (char) 10); fields.clear(); if (i == count_check) { System.out.println("Number of Documents created: " + count_check); System.out.println("Reading from file: (" + listOfFiles[file_index] + ")"); System.out.println("Size of all documents so far: (" + total + ") Bytes"); System.out.println("\n"); count_check += 1000; } cnt = i; } System.out.println("Total Number of Documents created: " + cnt); System.out.println("Total size of Dataset created: " + total); wr.close(); long endTime = System.nanoTime(); long duration = endTime - startTime; System.out.println("Total execuion time: " + (double) duration / 1000000000.0 + " Seconds" + "\n"); }
From source file:com.googlecode.jsfFlex.phaseListener.NameValueServiceRequestDataRetrieverFlusher.java
@Override void retrieveFlushData(FacesContext context, String componentId, String methodToInvoke) throws ServletException, IOException { Map<? extends Object, ? extends Object> objectMap = null; try {//from w w w. j a v a 2s . c om objectMap = (Map<? extends Object, ? extends Object>) invokeResourceMethod(context, componentId, methodToInvoke, null, null); } catch (Exception methodInvocationException) { throw new ServletException(methodInvocationException); } HttpServletResponse response = HttpServletResponse.class.cast(context.getExternalContext().getResponse()); response.setContentType(PLAIN_CONTENT_TYPE); if (objectMap != null) { StringBuilder responseContent = new StringBuilder(); for (Iterator<? extends Object> iterate = objectMap.keySet().iterator(); iterate.hasNext();) { Object currKey = iterate.next(); Object currValue = objectMap.get(currKey); String statementToWrite = currKey.toString() + EQUAL_CHAR + currValue.toString() + SEPARATOR_CHAR; responseContent.append(statementToWrite); } _log.info("Flushing content : " + responseContent.toString()); Writer writer = response.getWriter(); writer.write(responseContent.toString()); writer.flush(); } }
From source file:edu.wustl.bulkoperator.action.JobGridAjaxAction.java
@Override protected ActionForward executeSecureAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String index = request.getParameter("index"); String jobId = request.getParameter("jobId"); List<ArrayList> list = null; try {/* w w w . jav a 2s. co m*/ String query = "Select IDENTIFIER, JOB_NAME, JOB_STATUS, TOTAL_RECORDS_COUNT, " + "CURRENT_RECORDS_PROCESSED, FAILED_RECORDS_COUNT, TIME_TAKEN,JOB_STARTED_BY from " + "JOB_DETAILS where IDENTIFIER = " + jobId; list = AppUtility.executeSQLQuery(query); JSONObject resultObject = new JSONObject(); if (!list.isEmpty()) { List innerList = list.get(0); if (innerList != null && !innerList.isEmpty()) { resultObject.append("identifier", innerList.get(0)); resultObject.append("jobName", innerList.get(1)); resultObject.append("jobStatus", innerList.get(2)); resultObject.append("totalRecords", innerList.get(3)); resultObject.append("processedRecords", innerList.get(4)); resultObject.append("failedRecords", innerList.get(5)); resultObject.append("timeTaken", innerList.get(6)); resultObject.append("startedBy", innerList.get(7)); resultObject.append("index", index); } } response.setContentType("text/html"); response.setHeader("Cache-Control", "no-cache"); Writer writer = response.getWriter(); writer.write(new JSONObject().put("resultObject", resultObject).toString()); } catch (JSONException jsonExp) { logger.debug(jsonExp.getMessage(), jsonExp); } return null; }