List of usage examples for java.io StringWriter flush
public void flush()
From source file:org.polymap.rhei.fulltext.servlet.GeoRssEncoder.java
public synchronized void flush() throws IOException { if (aboutToFlush) { super.flush(); return;//w w w . jav a 2 s.c o m } aboutToFlush = true; log.debug("flush(): ..."); SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("rss_2.0"); feed.setTitle(feadTitle != null ? feadTitle : "POLYMAP3|Atlas"); feed.setLink(baseURL); feed.setDescription(description != null ? description : ""); feed.setEntries(feedEntries); //WireFeed wiredFeed = feed.createWireFeed(); SyndFeedOutput output = new SyndFeedOutput(); try { //output.output( feed, new OutputStreamWriter( out, "ISO-8859-1" ) ); StringWriter buf = new StringWriter(); output.output(feed, buf); buf.flush(); write(buf.toString().getBytes("UTF-8")); } catch (FeedException e) { log.warn("unhandled: ", e); } aboutToFlush = false; super.flush(); // feedEntries.clear(); }
From source file:org.apache.camel.component.chunk.ChunkEndpoint.java
@Override protected void onExchange(Exchange exchange) throws Exception { boolean fromTemplate; String newResourceUri = exchange.getIn().getHeader(CHUNK_RESOURCE_URI, String.class); if (newResourceUri == null) { String newTemplate = exchange.getIn().getHeader(CHUNK_TEMPLATE, String.class); Chunk newChunk;/*from ww w . j a v a 2s . c o m*/ if (newTemplate == null) { fromTemplate = false; newChunk = getOrCreateChunk(theme, fromTemplate); } else { fromTemplate = true; newChunk = createChunk(new StringReader(newTemplate), theme, fromTemplate); exchange.getIn().removeHeader(CHUNK_TEMPLATE); } // Execute Chunk Map<String, Object> variableMap = ExchangeHelper.createVariableMap(exchange); StringWriter writer = new StringWriter(); newChunk.putAll(variableMap); newChunk.render(writer); writer.flush(); // Fill out message Message out = exchange.getOut(); out.setBody(newChunk.toString()); out.setHeaders(exchange.getIn().getHeaders()); out.setAttachments(exchange.getIn().getAttachments()); } else { exchange.getIn().removeHeader(ChunkConstants.CHUNK_RESOURCE_URI); ChunkEndpoint newEndpoint = getCamelContext().getEndpoint(CHUNK_ENDPOINT_URI_PREFIX + newResourceUri, ChunkEndpoint.class); newEndpoint.onExchange(exchange); } }
From source file:com.alu.e3.prov.service.ApiJarBuilder.java
protected void doGenXML(List<JarEntryData> entries, Api api, Map<Object, Object> variablesMap) throws IOException, TemplateException { Template template = fmConfiguration.getTemplate(ROUTE_TEMPLATE_PATH); StringWriter buffer = new StringWriter(); template.process(variablesMap, buffer); buffer.flush(); if (LOG.isDebugEnabled()) LOG.debug(buffer.getBuffer().toString()); addJarEntry(entries, buffer.getBuffer().toString().getBytes("UTF-8"), "META-INF/spring/route-context.xml"); }
From source file:com.alu.e3.prov.service.ApiJarBuilder.java
protected void doGenManifest(List<JarEntryData> entries, Api api, Map<Object, Object> variablesMap) throws IOException, TemplateException { Template template = fmConfiguration.getTemplate(MANIFEST_TEMPLATE_PATH); StringWriter buffer = new StringWriter(); template.process(variablesMap, buffer); buffer.flush(); if (LOG.isDebugEnabled()) LOG.debug(buffer.getBuffer().toString()); addJarEntry(entries, buffer.getBuffer().toString().getBytes("UTF-8"), "META-INF/MANIFEST.MF"); }
From source file:org.openmrs.module.yank.api.impl.YankServiceImpl.java
@Override public void moveYankToErrors(Yank yank, Throwable ex) { YankService service = Context.getService(YankService.class); YankError error = new YankError(yank); error.setDateAttempted(new Date()); error.setAttemptedBy(Context.getAuthenticatedUser()); error.setError(ex.getLocalizedMessage()); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); ex.printStackTrace(pw);// w w w .j ava 2 s.c o m pw.flush(); sw.flush(); error.setStacktrace(OpenmrsUtil.shortenedStackTrace(sw.toString())); service.saveYankError(error); service.purgeYank(yank); }
From source file:org.metamorfosis.template.directive.freemarker.JFileSection.java
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) { log.debug("Ejecutando <@" + getDirectiveName() + " .../>"); if (loopVars.length != 0) { throw new DirectiveException("<@" + getDirectiveName() + " .../> doesn't allow loop variables."); }/*from www . j a va2 s. co m*/ // If there is non-empty nested content: if (body != null) { try { String test = null; Set<Entry<String, SimpleScalar>> entrySet = params.entrySet(); for (Entry<String, SimpleScalar> entry : entrySet) { String key = entry.getKey(); SimpleScalar value = entry.getValue(); if (key.equals("test")) { test = value.getAsString(); } else { throw new DirectiveException( "<@" + getDirectiveName() + " .../> doesn't allow " + key + " parameter"); } } // Executes the nested body. Same as <#nested> in FTL, except // that we use our own writer instead of the current output writer. // write the file StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); body.render(bw); env.getOut().flush(); bw.flush(); sw.flush(); bw.close(); sw.close(); JProject project = (JProject) SpringUtils.getProject(); String srcPath = project.getSrcPath(); if ("true".equalsIgnoreCase(test)) { srcPath = project.getTestPath(); } String jFileName = JFileSection.getJFileName(sw.toString()); String jPackagePath = JFileSection.getPackagePath(sw.toString()); String outputFolder = File.separator + srcPath + File.separator + jPackagePath; TemplateProcessed tp = new TemplateProcessed(outputFolder, jFileName, sw.toString()); super.setChanged(); super.notifyObservers(tp); } catch (TemplateException ex) { throw new DirectiveException("Error al ejecutar la directiva '" + getDirectiveName() + "'", ex); } catch (IOException ex) { throw new DirectiveException("Error al ejecutar la directiva '" + getDirectiveName() + "'", ex); } } else { throw new DirectiveException("missing body"); } }
From source file:org.latticesoft.util.common.StringUtil.java
/** * Parse the stack trace to get the various information: * package name, class name, method name, and line number * @param t throwable to be parsed.//w ww. j a v a 2s. co m * @return a collection of string stating the results in a * string array form. The elements of the string array is as * listed above */ public static Collection parseStackTrace(Throwable t) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); pw.flush(); sw.flush(); StringBuffer sb = sw.getBuffer(); try { pw.close(); } catch (Exception ex) { } try { sw.close(); } catch (Exception ex) { } sw = null; pw = null; Collection c = StringUtil.tokenize(sb.toString(), "\n"); ArrayList a = new ArrayList(); Iterator iter = c.iterator(); iter.next(); // drop 1st element; String className = null, packageName = null; String methodName = null, lineNumber = null; int index = 0; String result[] = null; while (iter.hasNext()) { result = new String[4]; String s = (String) iter.next(); index = s.indexOf("("); lineNumber = s.substring(index, s.length()); packageName = s.substring(3, index); index = packageName.lastIndexOf("."); methodName = packageName.substring(index + 1, packageName.length()); packageName = packageName.substring(0, index); index = packageName.lastIndexOf("."); className = packageName.substring(index + 1, packageName.length()); packageName = packageName.substring(0, index); lineNumber = StringUtil.substring(lineNumber, ":", ")"); if (log.isDebugEnabled()) { log.debug("packageName:" + packageName); log.debug("className:" + className); log.debug("methodName:" + methodName); log.debug("lineNumber:" + lineNumber); } result[0] = packageName; result[1] = className; result[2] = methodName; result[3] = lineNumber; a.add(result); } return a; }
From source file:org.tequila.template.directive.freemarker.JFileSection.java
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) { log.debug("Executing <@" + getDirectiveName() + " .../>"); if (loopVars.length != 0) { throw new DirectiveException("<@" + getDirectiveName() + " .../> doesn't allow loop variables."); }/*from w w w .j a va 2 s .c o m*/ // If there is non-empty nested content: if (body != null) { try { String test = null; Set<Entry<String, SimpleScalar>> entrySet = params.entrySet(); for (Entry<String, SimpleScalar> entry : entrySet) { String key = entry.getKey(); SimpleScalar value = entry.getValue(); if (key.equals("test")) { test = value.getAsString(); } else { throw new DirectiveException( "<@" + getDirectiveName() + " .../> doesn't allow " + key + " parameter"); } } // Executes the nested body. Same as <#nested> in FTL, except // that we use our own writer instead of the current output writer. // write the file StringWriter sw = new StringWriter(); BufferedWriter bw = new BufferedWriter(sw); body.render(bw); env.getOut().flush(); bw.flush(); sw.flush(); bw.close(); sw.close(); JProject project = (JProject) projectHolder.getProject(); String srcPath = project.getSrcPath(); if ("true".equalsIgnoreCase(test)) { srcPath = project.getTestPath(); } String jFileName = JFileSection.getJFileName(sw.toString()); String jPackagePath = JFileSection.getPackagePath(sw.toString()); TemplateProcessed tp = new TemplateProcessed(); tp.setOutputFolder(File.separator + srcPath + File.separator + jPackagePath); tp.setOutputFileName(jFileName); tp.setTemplateResult(sw.toString()); super.setChanged(); super.notifyObservers(tp); } catch (TemplateException ex) { throw new DirectiveException("Error al ejecutar la directiva '" + getDirectiveName() + "'", ex); } catch (IOException ex) { throw new DirectiveException("Error al ejecutar la directiva '" + getDirectiveName() + "'", ex); } } else { throw new DirectiveException("missing body"); } }
From source file:org.broadleafcommerce.openadmin.web.resource.MessagesResourceResolver.java
protected String getResourceContents(Resource resource) throws IOException { StringWriter writer = null; String contents;/* ww w. j a v a 2s .c o m*/ try { writer = new StringWriter(); IOUtils.copy(resource.getInputStream(), writer, "UTF-8"); contents = writer.toString(); } finally { if (writer != null) { writer.flush(); writer.close(); } } return contents; }
From source file:org.broadleafcommerce.common.web.resource.AbstractGeneratedResourceHandler.java
/** * @param resource// w w w . j a va 2 s . co m * @return the UTF-8 String represetation of the contents of the resource */ protected String getResourceContents(Resource resource) throws IOException { StringWriter writer = null; try { writer = new StringWriter(); IOUtils.copy(resource.getInputStream(), writer, "UTF-8"); return writer.toString(); } finally { if (writer != null) { writer.flush(); writer.close(); } } }