List of usage examples for java.io StringWriter getBuffer
public StringBuffer getBuffer()
From source file:com.prowidesoftware.swift.io.ConversionService.java
/** * Given a SwiftMessage object returns a String containing its SWIFT message representation. * * @see com.prowidesoftware.swift.io.IConversionService#getFIN(com.prowidesoftware.swift.model.SwiftMessage) */// w w w .ja va 2s .c o m public String getFIN(final SwiftMessage msg) { Validate.notNull(msg); final SwiftWriter w = new SwiftWriter(); final StringWriter writer = new StringWriter(); w.writeMessage(msg, writer); final String fin = writer.getBuffer().toString(); return ensureEols(fin); }
From source file:com.cloudera.sqoop.cli.ToolOptions.java
@Override public String toString() { StringWriter sw = new StringWriter(); printHelp(new HelpFormatter(), new PrintWriter(sw)); sw.flush();//from w w w .j ava2 s . co m return sw.getBuffer().toString(); }
From source file:org.dawnsci.marketplace.endpoints.MarketplaceEndpoint.java
private String serialize(Marketplace rootElement) throws IOException { Map<String, Object> saveOptions = new HashMap<String, Object>(); saveOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE); // UTF-8 encoding is required per specification saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); XMLResource resource = new XMLResourceImpl(); resource.getContents().add(rootElement); StringWriter stringWriter = new StringWriter(); resource.save(new URIConverter.WriteableOutputStream(stringWriter, resource.getEncoding()), saveOptions); return stringWriter.getBuffer().toString(); }
From source file:org.apache.asterix.event.management.EventExecutor.java
public void executeEvent(Node node, String script, List<String> args, boolean isDaemon, Cluster cluster, Pattern pattern, IOutputHandler outputHandler, AsterixEventServiceClient client) throws IOException { List<String> pargs = new ArrayList<>(); pargs.add("/bin/bash"); pargs.add(client.getEventsHomeDir() + File.separator + AsterixEventServiceUtil.EVENT_DIR + File.separator + EXECUTE_SCRIPT);/* w ww. j a v a 2 s.co m*/ StringBuilder envBuffer = new StringBuilder(IP_LOCATION + "=" + node.getClusterIp() + " "); boolean isMasterNode = node.getId().equals(cluster.getMasterNode().getId()); if (!node.getId().equals(EventDriver.CLIENT_NODE_ID) && cluster.getEnv() != null) { for (Property p : cluster.getEnv().getProperty()) { if (p.getKey().equals("JAVA_HOME")) { String val = node.getJavaHome() == null ? p.getValue() : node.getJavaHome(); envBuffer.append(p.getKey() + "=" + val + " "); } else if (p.getKey().equals(EventUtil.NC_JAVA_OPTS)) { if (!isMasterNode) { appendJavaOpts(node, envBuffer, p); } } else if (p.getKey().equals(EventUtil.CC_JAVA_OPTS)) { if (isMasterNode) { appendJavaOpts(node, envBuffer, p); } } else if (p.getKey().equals("LOG_DIR")) { String val = node.getLogDir() == null ? p.getValue() : node.getLogDir(); envBuffer.append(p.getKey() + "=" + val + " "); } else { envBuffer.append(p.getKey() + "=" + p.getValue() + " "); } } pargs.add(cluster.getUsername() == null ? System.getProperty("user.name") : cluster.getUsername()); } StringBuilder argBuffer = new StringBuilder(); if (args != null && args.size() > 0) { for (String arg : args) { argBuffer.append(arg + " "); } } ProcessBuilder pb = new ProcessBuilder(pargs); pb.environment().put(IP_LOCATION, node.getClusterIp()); pb.environment().put(CLUSTER_ENV, envBuffer.toString()); pb.environment().put(SCRIPT, script); pb.environment().put(ARGS, argBuffer.toString()); pb.environment().put(DAEMON, Boolean.toString(isDaemon)); Process p = pb.start(); if (!isDaemon) { BufferedInputStream bis = new BufferedInputStream(p.getInputStream()); StringWriter writer = new StringWriter(); IOUtils.copy(bis, writer, "UTF-8"); String result = writer.getBuffer().toString(); OutputAnalysis analysis = outputHandler.reportEventOutput(pattern.getEvent(), result); if (!analysis.isExpected()) { throw new IOException(analysis.getErrorMessage() + result); } } }
From source file:eu.europa.esig.dss.DSSXMLUtils.java
/** * This method allows to convert an XML {@code Node} to a {@code String}. * * @param node {@code Node} to be converted * @return {@code String} representation of the node */// ww w . j a v a 2 s. com public static String xmlToString(final Node node) { try { final Source source = new DOMSource(node); final StringWriter stringWriter = new StringWriter(); final Result result = new StreamResult(stringWriter); final TransformerFactory factory = TransformerFactory.newInstance(); final Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); } catch (Exception e) { throw new DSSException(e); } }
From source file:android.databinding.tool.LayoutXmlProcessor.java
private String toXML(ResourceBundle.LayoutFileBundle layout, Marshaller marshaller) throws JAXBException { StringWriter writer = new StringWriter(); marshaller.marshal(layout, writer);/*w w w . j a v a 2 s.c om*/ return writer.getBuffer().toString(); }
From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfigurationTest.java
@Test public void shouldLoadSaveConfiguration() throws Exception { final YamlConfiguration config = new YamlConfiguration(); final String testData = this.getTestInputData(); final StringWriter writer = new StringWriter(); config.load(new StringReader(testData)); config.save(writer);/*w w w . jav a2 s .c o m*/ assertEquals(testData, writer.getBuffer().toString()); }
From source file:biz.c24.io.spring.batch.writer.C24ItemWriter.java
/** * Writes the contents of the StringWriter to our output file * //from www . ja v a 2s. c om * @param writer The StringWriter to read the data from */ private void write(Sink sink) throws IOException { StringWriter writer = (StringWriter) sink.getWriter(); writer.flush(); StringBuffer buffer = writer.getBuffer(); // Sadly StringBuffer doesn't allow us read-only access to its internal array, so we have to copy String element = buffer.toString(); Writer outputWriter = writerSource.getWriter(); synchronized (outputWriter) { outputWriter.write(element); } // Reset the buffer for next time buffer.setLength(0); }
From source file:it.bz.tis.integreen.carsharingbzit.tis.FakeConnector.java
@Override public Object pushData(String datasourceName, Object[] data) { StringWriter sw = new StringWriter(); try {/*from ww w . j av a 2 s . c om*/ this.mapper.writeValue(sw, data); } catch (IOException e) { throw new IllegalStateException("Why???"); } String txt = sw.getBuffer().toString(); logger.debug("FakeConnector.pushData: " + datasourceName + " - " + txt); return null; }
From source file:it.bz.tis.integreen.carsharingbzit.tis.FakeConnector.java
@Override public Object syncStations(String datasourceName, Object[] data) { StringWriter sw = new StringWriter(); try {/*from w w w . j ava 2 s.co m*/ this.mapper.writeValue(sw, data); } catch (IOException e) { throw new IllegalStateException("Why???"); } String txt = sw.getBuffer().toString(); logger.debug("FakeConnector.syncStations: " + datasourceName + " - " + txt); return null; }