List of usage examples for java.io StringWriter close
public void close() throws IOException
From source file:com.tc.utils.StrUtils.java
public static String getStackTrace(Throwable t) throws IOException { StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); sw.close(); return sw.toString(); }
From source file:org.dashbuilder.dataset.json.DataSetDefJsonTest.java
protected static String getFileAsString(String file) throws Exception { InputStream mappingsFileUrl = Thread.currentThread().getContextClassLoader().getResourceAsStream(file); StringWriter writer = null; String fileContent = null;// w ww . ja va 2 s . c o m try { writer = new StringWriter(); IOUtils.copy(mappingsFileUrl, writer, UTF_8); fileContent = writer.toString(); } finally { if (writer != null) writer.close(); } // Ensure newline characters meet the HTTP specification formatting requirements. return fileContent.replaceAll("\n", "\r\n"); }
From source file:org.sakaiproject.sitestats.impl.parser.DigesterUtil.java
public static String convertReportDefsToXml(List<ReportDef> reportDef) throws Exception { String xml = null;//ww w.j a v a2 s. co m StringWriter outputWriter = null; try { outputWriter = new StringWriter(); outputWriter.write("<?xml version='1.0' ?>"); BeanWriter beanWriter = getBeanWriter(outputWriter); beanWriter.write("List", reportDef); xml = outputWriter.toString(); } finally { outputWriter.close(); } return xml; }
From source file:org.sakaiproject.sitestats.impl.parser.DigesterUtil.java
public static String convertReportParamsToXml(ReportParams reportParams) throws Exception { String xml = null;// ww w .ja v a 2s.co m StringWriter outputWriter = null; try { outputWriter = new StringWriter(); outputWriter.write("<?xml version='1.0' ?>"); BeanWriter beanWriter = getBeanWriter(outputWriter); beanWriter.write("ReportParams", reportParams); xml = outputWriter.toString(); } finally { outputWriter.close(); } return xml; }
From source file:io.fabric8.tooling.archetype.generator.ArchetypeTest.java
@AfterClass public static void afterAll() throws Exception { // now let invoke the projects final int[] resultPointer = new int[1]; StringWriter sw = new StringWriter(); Set<String> modules = new HashSet<String>(); for (final String outDir : outDirs) { String module = new File(outDir).getName(); if (modules.add(module)) { sw.append(String.format(" <module>%s</module>\n", module)); }/* w ww . java 2 s . c o m*/ } sw.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(ArchetypeTest.class.getResourceAsStream("/archetypes-test-pom.xml"), baos); String pom = new String(baos.toByteArray()).replace(" <!-- to be replaced -->", sw.toString()); FileWriter modulePom = new FileWriter("target/archetypes-test-pom.xml"); IOUtils.copy(new StringReader(pom), modulePom); modulePom.close(); final String outDir = new File("target").getCanonicalPath(); // thread locals are evil (I'm talking to you - org.codehaus.plexus.DefaultPlexusContainer#lookupRealm!) Thread t = new Thread(new Runnable() { @Override public void run() { System.out.println("Invoking projects in " + outDir); MavenCli maven = new MavenCli(); resultPointer[0] = maven.doMain( new String[] { "clean", "package", "-f", "archetypes-test-pom.xml" }, outDir, System.out, System.out); System.out.println("result: " + resultPointer[0]); } }); t.start(); t.join(); assertEquals("Build of project " + outDir + " failed. Result = " + resultPointer[0], 0, resultPointer[0]); }
From source file:de.tu_dortmund.ub.data.util.TPUUtil.java
public static String getResponseMessage(final HttpEntity httpEntity) throws IOException { final StringWriter writer = new StringWriter(); IOUtils.copy(httpEntity.getContent(), writer, APIStatics.UTF_8); final String response = writer.toString(); writer.flush();/*from w w w . j ava 2 s . c o m*/ writer.close(); return response; }
From source file:com.wavemaker.json.JSONMarshaller.java
/** * Marshal the given Object into a JSON-formatted character stream (written out onto the writer parameter). * //w ww. j a v a 2 s . co m * @param obj The Object to marshal; this must be an JavaBean-style Object, a Collection, or an array. * @param jsonState Any configuration. * @param sort True if the output should be sorted (only bean properties will be sorted, currently). * @return The JSON-formatted String representation of obj. */ public static String marshal(Object obj, JSONState jsonState, boolean sort, boolean prettyPrint) throws IOException { StringWriter sw = new StringWriter(); marshal(sw, obj, jsonState, sort, prettyPrint); String ret = sw.toString(); sw.close(); return ret; }
From source file:jenkins.plugins.coverity.CoverityUtils.java
/** * Gets the stacktrace from an exception, so that this exception can be handled. */// w w w . ja v a 2s . c o m public static String getStackTrace(Exception e) { StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); e.printStackTrace(printWriter); printWriter.flush(); String stackTrace = writer.toString(); try { writer.close(); printWriter.close(); } catch (IOException e1) { } return stackTrace; }
From source file:com.predic8.membrane.core.util.TextUtil.java
public static String formatXML(Reader reader, boolean asHTML) { StringWriter out = new StringWriter(); try {/* w w w . ja va 2 s . co m*/ XMLBeautifierFormatter formatter = asHTML ? new HtmlBeautifierFormatter(out, 0) : new PlainBeautifierFormatter(out, 0); XMLBeautifier beautifier = new XMLBeautifier(formatter); beautifier.parse(reader); } catch (Exception e) { log.error("", e); } finally { try { out.close(); reader.close(); } catch (IOException e) { log.error("", e); } } return out.toString(); }
From source file:com.wavemaker.json.JSONMarshaller.java
/** * Marshal the given Object into a JSON-formatted character stream (written out onto the writer parameter). * /* w w w. j a v a2 s. c o m*/ * @param obj The Object to marshal; this must be an JavaBean-style Object, a Collection, or an array. * @param jsonState Any configuration. * @param sort True if the output should be sorted (only bean properties will be sorted, currently). * @return The JSON-formatted String representation of obj. */ public static String marshal(Object obj, JSONState jsonState, FieldDefinition fieldDefinition, boolean sort) throws IOException { StringWriter sw = new StringWriter(); marshal(sw, obj, jsonState, fieldDefinition, sort, DEFAULT_PRETTY_PRINT); String ret = sw.toString(); sw.close(); return ret; }