List of usage examples for java.io StringWriter close
public void close() throws IOException
From source file:org.kalypso.ui.editorLauncher.GmlEditorTemplateLauncher.java
public static IStorageEditorInput createInputForGml(final IFile file) throws CoreException { try {/*from w ww . jav a2 s.c om*/ final ObjectFactory typesFac = new ObjectFactory(); final URL context = ResourceUtilities.createURL(file.getParent()); final LayerType type = typesFac.createLayerType(); LayerTypeUtilities.initLayerType(type, file, context); final Gistreeview gistreeview = TemplateUtilities.OF_GISTREEVIEW.createGistreeview(); gistreeview.setInput(type); final Marshaller marshaller = TemplateUtilities.createGistreeviewMarshaller(CharEncoding.UTF_8); final StringWriter w = new StringWriter(); marshaller.marshal(gistreeview, w); w.close(); final String string = w.toString(); // als StorageInput zurckgeben final String basename = FilenameUtils.removeExtension(file.getName()); final String gmvName = basename + ".gmv"; //$NON-NLS-1$ final IFile gmvFile = file.getParent().getFile(new Path(gmvName)); final IPath fullPath = gmvFile.getFullPath(); return new StorageEditorInput(new StringStorage(string, fullPath)); } catch (final JAXBException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } catch (final IOException e) { throw new CoreException(StatusUtilities.statusFromThrowable(e)); } }
From source file:Main.java
protected static Result internalTransform(Document doc, Templates templates, Result r, boolean trace) { StringWriter sw = new StringWriter(); try {/*from ww w. j a v a2 s. co m*/ Transformer transformer = templates.newTransformer(); transformer.transform(new DOMSource(doc), r); sw.close(); return r; } catch (Throwable th) { th.printStackTrace(); return r; } }
From source file:Main.java
protected static Result internalTransform(InputStream doc, Templates templates, Result r, boolean trace) { StringWriter sw = new StringWriter(); try {// w ww.j ava2 s. c o m Transformer transformer = templates.newTransformer(); transformer.transform(new StreamSource(doc), r); sw.close(); return r; } catch (Throwable th) { th.printStackTrace(); return r; } }
From source file:Main.java
protected static Result internalTransform(Reader doc, Templates templates, Result r, boolean trace) { StringWriter sw = new StringWriter(); try {/*from w ww. j a v a 2 s . co m*/ Transformer transformer = templates.newTransformer(); transformer.transform(new StreamSource(doc), r); sw.close(); return r; } catch (Throwable th) { th.printStackTrace(); return r; } }
From source file:function.Functions.java
protected static String toString(InputStream in) throws IOException { StringWriter out = new StringWriter(); copy(new InputStreamReader(in), out); out.close(); in.close();/*from ww w. java 2 s. c om*/ return out.toString(); }
From source file:Main.java
public static String constructXMLString(Document dom) throws IOException { String retXMLStr = null;// w ww. j a v a 2 s. c o m TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = factory.newTransformer(); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); DOMSource source = new DOMSource(dom); transformer.transform(source, result); writer.close(); retXMLStr = writer.toString(); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } /* // Make a string out of the DOM object System.out.println(dom.toString()); OutputFormat format = new OutputFormat(dom); format.setIndenting(true); ByteArrayOutputStream byteoutStream = new ByteArrayOutputStream(); XMLSerializer serializer = new XMLSerializer(byteoutStream, format); serializer.serialize(dom); String retXMLStr = new String(byteoutStream.toByteArray()); byteoutStream.close(); */ return retXMLStr; }
From source file:org.ethereum.jsontestsuite.JSONReader.java
public static String loadJSONFromResource(String resname, ClassLoader loader) { System.out.println("Loading local resource: " + resname); try {/*w ww . jav a2 s . c om*/ InputStreamReader reader = new InputStreamReader(loader.getResourceAsStream(resname)); StringWriter writer = new StringWriter(); IOUtils.copyAndCloseInput(reader, writer, 100000000); writer.close(); return writer.toString(); } catch (IOException e) { e.printStackTrace(); } return ""; }
From source file:Main.java
public static String transformXmlToString(Document importPackageDocument) throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException, IOException {//from w w w . j ava2 s . c o m TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); StringWriter writer = new StringWriter(); javax.xml.transform.Result result = new StreamResult(writer); Source source = new DOMSource(importPackageDocument); transformer.transform(source, result); writer.close(); String xml = writer.toString(); return xml; }
From source file:org.jkcsoft.java.xml.XMLUtil.java
public static String domToString(Node node, int estSize) throws Exception { String retVal = null;/*from w w w . j av a 2 s . c o m*/ if (node != null) { StringWriter sw = new StringWriter(estSize); xtrans.transform(new DOMSource(node), new StreamResult(sw)); retVal = sw.toString(); sw.close(); } return retVal; }
From source file:org.ojbc.util.helper.HttpUtils.java
/** * Send the specified payload to the specified http endpoint via POST. * @param payload/*from w ww. j a v a 2s.c o m*/ * @param url * @return the http response * @throws Exception */ public static String post(String payload, String url) throws Exception { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); post.setEntity(new StringEntity(payload, Consts.UTF_8)); HttpResponse response = client.execute(post); HttpEntity reply = response.getEntity(); StringWriter sw = new StringWriter(); BufferedReader isr = new BufferedReader(new InputStreamReader(reply.getContent())); String line; while ((line = isr.readLine()) != null) { sw.append(line); } sw.close(); return sw.toString(); }