List of usage examples for java.io CharArrayWriter CharArrayWriter
public CharArrayWriter()
From source file:com.metaparadigm.jsonrpc.JSONRPCResult.java
@Override public String toString() { try {/* w w w .j a va2s. c o m*/ JSONObject o = new JSONObject(); if (errorCode == CODE_SUCCESS) { o.put("id", id); o.put("result", result); } else if (errorCode == CODE_REMOTE_EXCEPTION) { Throwable e = (Throwable) result; CharArrayWriter caw = new CharArrayWriter(); e.printStackTrace(new PrintWriter(caw)); JSONObject err = new JSONObject(); err.put("code", new Integer(errorCode)); err.put("msg", e.getMessage()); err.put("trace", caw.toString()); o.put("id", id); o.put("error", err); } else { JSONObject err = new JSONObject(); err.put("code", new Integer(errorCode)); err.put("msg", result); o.put("id", id); o.put("error", err); } return o.toString(); } catch (Exception exc) { exc.printStackTrace(); } return null; }
From source file:org.dd4t.core.util.XSLTransformer.java
public String transformSourceFromFilesource(String source, String resource, Map<String, Object> params) throws TransformerException { // attain writer to place result in CharArrayWriter caw = new CharArrayWriter(); StreamResult result = new StreamResult(caw); // get XSL transformer Transformer trans = getTransformer(resource); for (Map.Entry<String, Object> entry : params.entrySet()) { trans.setParameter(entry.getKey(), entry.getValue()); }/* w w w. j a v a 2s . c o m*/ // if found, transform if (trans != null) { StringReader reader = new StringReader(source); StreamSource xmlSource = new StreamSource(reader); // transform trans.transform(xmlSource, result); } return caw.toString(); }
From source file:com.edgenius.wiki.ext.textnut.BPListParaserHandler.java
public void startDocument() throws SAXException { characters = new CharArrayWriter(); files = new HashMap<String, File>(); }
From source file:org.sakaiproject.search.component.adapter.contenthosting.PDFContentDigester.java
public String getContent(ContentResource contentResource) { if (contentResource == null) { throw new RuntimeException("Null contentResource passed to getContent"); }/*from w w w .java2 s . c o m*/ InputStream contentStream = null; PDFParser parser = null; PDDocument pddoc = null; try { contentStream = contentResource.streamContent(); parser = new PDFParser(new BufferedInputStream(contentStream)); parser.parse(); pddoc = parser.getPDDocument(); if (pddoc != null) { PDFTextStripper stripper = new PDFTextStripper(); stripper.setLineSeparator("\n"); CharArrayWriter cw = new CharArrayWriter(); stripper.writeText(pddoc, cw); return SearchUtils.appendCleanString(cw.toCharArray(), null).toString(); } } catch (ServerOverloadException e) { String eMessage = e.getMessage(); if (eMessage == null) { eMessage = e.toString(); } throw new RuntimeException( "Failed to get content for indexing: cause: ServerOverloadException: " + eMessage, e); } catch (IOException e) { String eMessage = e.getMessage(); if (eMessage == null) { eMessage = e.toString(); } throw new RuntimeException("Failed to get content for indexing: cause: IOException: " + eMessage, e); } finally { if (pddoc != null) { try { pddoc.close(); } catch (IOException e) { log.debug(e); } } if (contentStream != null) { try { contentStream.close(); } catch (IOException e) { log.debug(e); } } } return null; }
From source file:org.displaytag.filter.BufferedResponseWrapper12Impl.java
/** * @param httpServletResponse the response to wrap *//*ww w.j ava2 s. c om*/ public BufferedResponseWrapper12Impl(HttpServletResponse httpServletResponse) { this.response = httpServletResponse; this.outputWriter = new CharArrayWriter(); this.servletOutputStream = new SimpleServletOutputStream(); }
From source file:de.betterform.agent.web.filter.XSLTFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; ServletContext servletContext = filterConfig.getServletContext(); /* TODO: clean up, styleFile is never used */ String stylePath = null;//from w w w . java 2s . c o m try { stylePath = WebFactory.getRealPath(xsltPath, servletContext); } catch (XFormsConfigException e) { throw new ServletException(e); } File styleFile = new File(stylePath, xslFile); PrintWriter out = response.getWriter(); CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) response); try { URI uri = new File(WebFactory.getRealPath(xsltPath, servletContext)).toURI().resolve(new URI(xslFile)); XSLTGenerator generator = WebFactory.setupTransformer(uri, servletContext); wrapper.setContentType("text/html"); chain.doFilter(request, wrapper); StringReader sr = new StringReader(wrapper.toString()); generator.setInput(sr); // Source xmlSource = new StreamSource((Reader) sr); CharArrayWriter caw = new CharArrayWriter(); generator.setOutput(caw); // StreamResult result = new StreamResult(caw); // transformer.transform(xmlSource, result); generator.generate(); response.setContentLength(caw.toString().length()); out.write(caw.toString()); } catch (URISyntaxException e) { out.println(e.toString()); out.write(wrapper.toString()); } catch (XFormsException e) { out.println(e.toString()); out.write(wrapper.toString()); } }
From source file:org.chtijbug.drools.platform.web.filter.DynamicBaseFilter.java
public CharResponseWrapper(HttpServletResponse response) { super(response); this.output = new CharArrayWriter(); }
From source file:com.serotonin.bacnet4j.util.sero.StreamUtils.java
public static char[] read(Reader reader) throws IOException { CharArrayWriter writer = new CharArrayWriter(); transfer(reader, writer);//from ww w. j a v a 2 s.co m return writer.toCharArray(); }
From source file:importer.filters.PoemFilter.java
/** * Convert to standoff properties/*from w ww . j av a2 s. co m*/ * @param input the raw text input string * @param name the name of the new version * @param cortext a cortex mvd archive * @param corcode a corcode mvd archive * @return log output */ @Override public String convert(String input, String name, Archive cortex, Archive corcode) throws ImporterException { try { CharArrayWriter txt = new CharArrayWriter(); String[] lines = input.split("\n"); init(); analyseStanzas(lines); int state = (hasHeading) ? 0 : 1; for (int i = 0; i < lines.length; i++) { String str = lines[i].trim(); char[] current = str.toCharArray(); switch (state) { case 0: if (lines[i].length() > 0) { writeCurrent(txt, current); writeCurrent(txt, CR); numHeadingLines++; if (numHeadingLines == minStanzaLength) { markup.add("head", 0, written); state = 1; } } break; case 1: // new stanza lgStart = written; markup.add("l", written, current.length); writeCurrent(txt, current); writeCurrent(txt, CR); state = 2; break; case 2: // body of stanza if (lines[i].length() > 0) { markup.add("l", written, current.length); writeCurrent(txt, current); writeCurrent(txt, CR); } else { markup.add("lg", lgStart, written - lgStart); writeCurrent(txt, CR); state = 1; } break; } } if (state == 2) { markup.add("lg", lgStart, written - lgStart); writeCurrent(txt, CR); } markup.sort(); cortex.put(name, txt.toCharArray()); String json = markup.toSTILDocument().toString(); corcode.put(name, json.toCharArray()); return ""; } catch (Exception e) { throw new ImporterException(e); } }
From source file:org.dhatim.SmooksUtil.java
/** * Utility method to filter the content in the specified {@link InputStream} for the specified {@link org.dhatim.container.ExecutionContext}. * <p/>//from w w w. j a va 2 s . c o m * Useful for testing purposes. In a real scenario, use * {@link Smooks#filter(org.dhatim.container.ExecutionContext,javax.xml.transform.Source,javax.xml.transform.Result)}. * <p/> * The content of the returned String is totally dependent on the configured * {@link org.dhatim.delivery.dom.DOMElementVisitor} and {@link org.dhatim.delivery.dom.serialize.SerializationUnit} * implementations. * * @param executionContext Execution context for the filter. * @param stream Stream to be processed. Will be closed before returning. * @param smooks The {@link Smooks} instance through which to perform the filter and serialize operations. * @return The Smooks processed content buffer. * @throws IOException Exception using or closing the supplied InputStream. * @throws SmooksException Excepting processing content stream. */ public static String filterAndSerialize(ExecutionContext executionContext, InputStream stream, Smooks smooks) throws SmooksException { String responseBuf = null; CharArrayWriter writer = new CharArrayWriter(); try { smooks.filterSource(executionContext, new StreamSource(stream), new StreamResult(writer)); responseBuf = writer.toString(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { new SmooksException("Failed to close stream...", e); } } writer.close(); } return responseBuf; }