List of usage examples for java.io StringWriter write
public void write(String str)
From source file:com.jaspersoft.jasperserver.ws.xml.Marshaller.java
public static void marshal(Object obj, java.io.StringWriter out) { Marshaller marshaller = new Marshaller(); if (obj instanceof Request) { out.write(marshaller.marshal((Request) obj)); } else if (obj instanceof OperationResult) { out.write(marshaller.marshal((OperationResult) obj)); }//from ww w. j a v a2 s. c o m }
From source file:com.espertech.esper.example.trivia.TriviaMain.java
private static String printMapWithTime(Map<String, Object> map) { StringWriter writer = new StringWriter(); String delimiter = ""; writer.write("{"); for (Map.Entry<String, Object> entry : map.entrySet()) { writer.write(delimiter);// www. j av a 2s .com writer.write(entry.getKey()); writer.write("="); if (entry.getKey().toLowerCase().contains("time")) { writer.write(TriviaHelper.print(entry.getValue())); } else { writer.write(entry.getValue().toString()); } delimiter = ", "; } writer.write("}"); return writer.toString(); }
From source file:com.google.gdt.eclipse.designer.wizards.model.common.AbstractCreateOperation.java
/** * @return the text converted to use system line separator. *//* www .j a v a 2 s . c om*/ private static String toSystemEOL(String text) throws Exception { StringWriter stringWriter = new StringWriter(); BufferedReader br = new BufferedReader(new StringReader(text)); while (true) { String line = br.readLine(); if (line == null) { break; } stringWriter.write(line); stringWriter.write(SystemUtils.LINE_SEPARATOR); } return stringWriter.toString(); }
From source file:org.jspresso.framework.util.html.HtmlHelper.java
/** * Escapes special characters for HTML./* ww w . jav a 2 s.com*/ * * @param text * the text to escape. * @param escapeSpaces * should we also escape spaces using &'nbsp'; entity ? * @return the escaped HTML text. */ public static String escapeForHTML(String text, boolean escapeSpaces) { if (text == null) { return null; } // use apache lib to escape... // this library doesn't escape spaces (see workaround bellow) String str = StringEscapeUtils.escapeHtml4(text); if (escapeSpaces) { // Workaround : we have also to escape spaces... StringWriter writer = new StringWriter((int) (str.length() * 1.5)); boolean spaces = false; int len = str.length(); for (int i = 0; i < len; i++) { char c = str.charAt(i); if (c != ' ') { writer.write(c); spaces = false; } else { // space or spaces... if (i == 0) { // start with space spaces = true; } else if (i == len - 1) { // ends with space spaces = true; } else if (i < len - 1 && str.charAt(i + 1) == ' ') { // two or more spaces spaces = true; } if (spaces) { writer.write(" "); } else { writer.write(' '); } } } str = writer.toString(); } return str; }
From source file:edu.cornell.mannlib.semservices.util.SKOSUtils.java
public static String getConceptXML(String conceptUriString) { URL conceptURL = null;//from w ww . j a v a2 s. c om try { conceptURL = new URL(conceptUriString); } catch (Exception e) { log.error("Exception occurred in instantiating URL for " + conceptUriString, e); // If the url is having trouble, just return null for the concept return null; } log.debug("loading concept uri " + conceptUriString); String results = null; try { StringWriter sw = new StringWriter(); BufferedReader in = new BufferedReader(new InputStreamReader(conceptURL.openStream())); String inputLine; while ((inputLine = in.readLine()) != null) { sw.write(inputLine); } in.close(); results = sw.toString(); log.debug(results); } catch (Exception ex) { log.error("Error occurred in getting concept from the URL " + conceptUriString, ex); return null; } return results; }
From source file:org.gogoego.util.db.DBSessionFactory.java
public static void registerDataSource(final String name, final Properties properties) { boolean fail = false; StringWriter errmsg = new StringWriter(); for (String p : new String[] { "uri", "driver", "user", "password" }) { String found = properties.getProperty("dbsession." + name + "." + p); if (found == null) { if (fail) errmsg.write(", "); errmsg.write(name + "." + p); fail = true;/* w w w .j a va 2 s. c o m*/ } } if (fail) throw new RuntimeException("Required database connection property or properties missing: " + errmsg); registerDataSource(name, properties.getProperty("dbsession." + name + ".uri"), properties.getProperty("dbsession." + name + ".driver"), properties.getProperty("dbsession." + name + ".user"), properties.getProperty("dbsession." + name + ".password")); }
From source file:Main.java
public static String toString(Object entity, boolean formatOutput) { StringWriter stringWriter = new StringWriter(); try {//from w w w .jav a 2 s. c o m Map<String, Object> properties = new HashMap<String, Object>(); properties.put(Marshaller.JAXB_FORMATTED_OUTPUT, formatOutput); JAXBContext jaxbContext = JAXBContext.newInstance(entity.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(entity, stringWriter); } catch (JAXBException e) { stringWriter.write(e.getMessage()); } return stringWriter.toString(); }
From source file:org.chtijbug.drools.utils.FileUtils.java
protected static StringBuffer replaceTokenFromFile(File file, String tokenKey, String tokenValue) throws IOException { FileReader fileReader = new FileReader(file); StringWriter stringWriter = null; try {/*from www. j a v a2s . c om*/ stringWriter = new StringWriter(); //______ Read each line of the file. List<String> allLines = IOUtils.readLines(fileReader); for (String line : allLines) { //______ Replace all Token key with the token Value String replacedLine = line.replace(tokenKey, tokenValue); stringWriter.write(replacedLine); stringWriter.write("\n"); } //______ return the replaced content return stringWriter.getBuffer(); } finally { IOUtils.closeQuietly(fileReader); IOUtils.closeQuietly(stringWriter); } }
From source file:de.dentrassi.pm.deb.aspect.internal.RepoBuilder.java
/** * Write a field/*from w w w . j a v a 2 s . co m*/ * * @param writer * the writer to use * @param fieldName * the field name * @param value * the value, should not be <code>null</code> since this would * cause the string * <q>null</q> in the file. */ protected static void write(final StringWriter writer, final String fieldName, final String value) { writer.write(fieldName + ": " + value + "\n"); }
From source file:org.commonjava.aprox.bind.jaxrs.util.ResponseUtils.java
public static CharSequence formatEntity(final Throwable error, final String message) { final StringWriter sw = new StringWriter(); if (message != null) { sw.append(message);//from www .jav a2 s . c o m sw.append("\nError was:\n\n"); } sw.append(error.getMessage()); final Throwable cause = error.getCause(); if (cause != null) { sw.append("\n\n"); cause.printStackTrace(new PrintWriter(sw)); } sw.write('\n'); return sw.toString(); }