List of usage examples for java.io Writer toString
public String toString()
From source file:org.apache.tinkerpop.gremlin.structure.io.IoTest.java
private static String streamToString(final InputStream in) throws IOException { final Writer writer = new StringWriter(); final char[] buffer = new char[1024]; try (final Reader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"))) { int n;//from ww w .j a v a 2s. com while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } return writer.toString(); }
From source file:nl.cyso.vcloud.client.docs.ManPage.java
private String getSynopsisSection() { StringBuilder section = new StringBuilder(); section.append(".SH SYNOPSIS\n"); HelpFormatter help = new HelpFormatter(); help.setSyntaxPrefix(""); Writer str = new StringWriter(); PrintWriter pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.PROJECT_NAME, ConfigModes.getMode(ModeType.ROOT)); section.append(str.toString() + "\n"); for (ModeType m : ModeType.values()) { if (m == ModeType.ROOT) { continue; }/*from w w w .ja v a 2 s .com*/ section.append(String.format(".B %s\n", m.toString())); str = new StringWriter(); pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.PROJECT_NAME, ConfigModes.getMode(m)); section.append(".RS 4\n"); section.append(str.toString() + "\n"); section.append(".RE\n"); } return section.toString().replace("-", "\\-"); }
From source file:Base64.java
public static String throwableToString(Throwable t) { if (t != null) { Writer exception = new StringWriter(); PrintWriter printWriter = new PrintWriter(exception); t.printStackTrace(printWriter);//from w w w .ja va 2 s.c o m return exception.toString(); } return ""; }
From source file:org.eclipse.smila.connectivity.framework.agent.feed.test.TestConfigMarshall.java
/** * Test load.// w ww .ja v a 2 s.co m * * @throws Exception * the exception */ public void testLoadMarshall() throws Exception { final DataSourceConnectionConfig configuration = ConfigurationLoader .unmarshall(TestConfigMarshall.class.getResourceAsStream("ConfigExample.xml")); _log.info("Marshalling......"); final Writer writer = new StringWriter(); final Marshaller marshaller = ConfigurationLoader.crateMarshaller(configuration); assertNotNull(marshaller); _log.info("Marshaller created......"); marshaller.marshal(configuration, writer); _log.info("Marshalled"); _log.info(writer.toString()); }
From source file:org.eclipse.smila.connectivity.framework.crawler.jdbc.test.TestConfigMarshall.java
/** * Tests if the DataSourceConnectionConfig can be unmarshalled. * //w w w . ja v a 2s . c o m * @throws Exception * If anything goes wrong ... */ public void testLoadMarshall() throws Exception { final DataSourceConnectionConfig configuration = ConfigurationLoader .unmarshall(TestConfigMarshall.class.getResourceAsStream("JdbcDerbyWithGrouping.xml")); _log.info("Marshalling......"); final Writer writer = new StringWriter(); final Marshaller marshaller = ConfigurationLoader.crateMarshaller(configuration); assertNotNull(marshaller); _log.info("Marshaller created......"); marshaller.marshal(configuration, writer); _log.info("Marshalled"); _log.info(writer.toString()); }
From source file:nl.cyso.vcloud.client.docs.Readme.java
private String getSynopsisSection() { StringBuilder section = new StringBuilder(); section.append("SYNOPSIS\n"); section.append("--------\n"); HelpFormatter help = new HelpFormatter(); help.setSyntaxPrefix(""); Writer str = new StringWriter(); PrintWriter pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.PROJECT_NAME, ConfigModes.getMode(ModeType.ROOT)); section.append("\t\n\t" + str.toString() + "\n"); for (ModeType m : ModeType.values()) { if (m == ModeType.ROOT) { continue; }//from ww w .j ava 2 s.c om str = new StringWriter(); pw = new PrintWriter(str); help.printUsage(pw, 1000, Version.PROJECT_NAME, ConfigModes.getMode(m)); section.append(String.format("**%s**\n\n", m.toString())); section.append("\t" + str.toString() + "\n"); } return section.toString(); }
From source file:org.atricore.idbus.capabilities.sso.ui.page.error.IdBusErrorPage.java
/** * For now, only the root cause will be displayed * @param cause/* ww w. j av a 2s.c o m*/ * @return */ protected List<String> buildCauses(Throwable cause) { List<String> causes = new ArrayList<String>(); Throwable rootCause = cause; while (cause != null) { // Writer errorWriter = new StringWriter(); // PrintWriter errorPrintWriter = new PrintWriter(errorWriter); // cause.printStackTrace(errorPrintWriter); // causes.add(errorWriter.toString()); rootCause = cause; cause = cause.getCause(); } Writer errorWriter = new StringWriter(); PrintWriter errorPrintWriter = new PrintWriter(errorWriter); rootCause.printStackTrace(errorPrintWriter); causes.add(errorWriter.toString()); return causes; }
From source file:com.github.wesjd.overcastmappacker.xml.DocumentHandler.java
public void saveDocument() { try {/*from w ww . j a v a2 s .co m*/ final Writer writer = new StringWriter(); new XMLSerializer(writer, XMLConstants.INDENTED_OUTPUT_FORMAT).serialize(document); document = documentBuilder.parse(new InputSource(new StringReader(writer.toString()))); transformer.transform(new DOMSource(document), new StreamResult(documentFile)); } catch (TransformerException | IOException | SAXException ex) { ex.printStackTrace(); } }
From source file:ch.silviowangler.dox.export.DoxExporterImpl.java
private void logXml(XStream xStream, Serializable instanceToDump) { if (logger.isTraceEnabled()) { Writer writer = new StringWriter(); xStream.marshal(instanceToDump, new PrettyPrintWriter(writer)); logger.trace("Created XML for repository.xml '{}'", writer.toString()); }/*from w w w. ja v a 2s . c om*/ }
From source file:br.unicamp.cst.trafficUnjammer.experiments.communication.JsonHandler.java
/** * Convert an object to String json formatted using GOOGLE GSON API * @param object/*from w w w.j ava2 s. c o m*/ * @return */ public String fromObjectToJsonData(Object object) { ObjectMapper mapper = new ObjectMapper(); Writer strWriter = new StringWriter(); try { mapper.writeValue(strWriter, object); } catch (JsonGenerationException e) { } catch (JsonMappingException e) { } catch (IOException e) { } String jsonData = strWriter.toString(); return jsonData; }