List of usage examples for java.io Writer toString
public String toString()
From source file:Main.java
public static String getPrettyXml(byte[] xml) { try {//from w w w . j av a 2s.c o m String unformattedXml = new String(xml); final Document document = parseXmlFile(unformattedXml); OutputFormat format = new OutputFormat(document); format.setLineWidth(65); format.setIndenting(true); format.setIndent(2); Writer out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(document); return out.toString(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static <T> String obj2Xml(T c) throws RuntimeException { String returnXml = ""; Writer writer = null; try {//from w w w . j a v a 2s. c om writer = new StringWriter(); JAXBContext.newInstance(c.getClass()).createMarshaller().marshal(c, writer); returnXml = writer.toString(); } catch (JAXBException e) { throw new RuntimeException(e); } finally { try { writer.close(); } catch (IOException e) { throw new RuntimeException(e); } } return returnXml; }
From source file:org.apache.hadoop.io.crypto.bee.BeeUtil.java
public static String getStackTrace(Throwable throwable) { // for LOG, you can directly use LOG.error("", e). Writer writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); throwable.printStackTrace(printWriter); return writer.toString(); }
From source file:Main.java
public static String format(Document document) { try {//from w ww.j a va2 s. co m OutputFormat format = new OutputFormat(document); format.setLineWidth(65); format.setIndenting(true); format.setIndent(2); Writer out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(document); return out.toString(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.nabla.wapp.server.general.Util.java
public static String formatInternalErrorDescription(final Throwable x) { if (x == null) return null; final Writer buffer = new StringWriter(); final PrintWriter pw = new PrintWriter(buffer); x.printStackTrace(pw);// www .j av a 2 s . com return buffer.toString(); }
From source file:Main.java
/** * Return the absolute path to the hub database. * * @return path The path to the db as a string */// w w w . jav a 2 s . c o m private static String getDbPath() { if (Debug) Log.i(TAG, "getDBPath() called."); String path = Environment.getExternalStorageDirectory().getPath() + "/" + BASE_DIR; File dbDir = new File(path); if (!dbDir.isDirectory()) { try { if (Debug) Log.i(TAG, "Trying to create " + path); dbDir.mkdirs(); } catch (Exception e) { final Writer result = new StringWriter(); final PrintWriter printWriter = new PrintWriter(result); e.printStackTrace(printWriter); Log.e(TAG, result.toString()); } } return path; }
From source file:com.seer.datacruncher.spring.MacrosValidateController.java
private static String getStackTrace(Throwable throwable) { Writer writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); throwable.printStackTrace(printWriter); return writer.toString(); }
From source file:info.magnolia.freemarker.FreemarkerUtil.java
/** * Uses the class of the object to create the templates name, passes the object under the name 'this' * and returns the result in a String./*from w ww .ja v a 2s. co m*/ * Used only in DialogMultiSelect - VersionCommentPopup - Inbox - SubPagesControl */ public static String process(Object thisObj) { final Writer writer = new StringWriter(); process(thisObj, writer); return writer.toString(); }
From source file:helper.SerializationHelper.java
public static String serializeGridTopology(ActorTopology topology) { ObjectMapper mapper = new ObjectMapper(); Writer strWriter = new StringWriter(); try {// w ww . j av a 2 s .c om mapper.writeValue(strWriter, topology); } catch (Exception e) { System.out.println(e); } return strWriter.toString(); }
From source file:info.magnolia.freemarker.FreemarkerUtil.java
/** * Process this template with the passed data and returns the result in a String. *///ww w.j a va 2s. c om public static String process(String name, Map<String, Object> data) { final Writer writer = new StringWriter(); process(name, data, writer); return writer.toString(); }