List of usage examples for org.apache.commons.io IOUtils copy
public static void copy(Reader input, OutputStream output, String encoding) throws IOException
Reader
to bytes on an OutputStream
using the specified character encoding, and calling flush. From source file:com.rpeactual.json2xml.JSON2XML.java
/** * Takes an JSON input stream and returns an XML output stream * /*from ww w . ja v a 2 s . c o m*/ * @param inputStream * @param outputStream * @throws IOException * @throws XmlException */ public void json2xml(InputStream jsonStream, String outputFolder) throws IOException, XmlException { StringWriter writer = new StringWriter(); IOUtils.copy(jsonStream, writer, UTF_8); String jsonStr = writer.toString(); JSONObject o = new JSONObject(jsonStr); String xml = org.json.XML.toString(o); File xmlFile = new File(outputFolder, "output.xml"); OutputStream xmlStream = new FileOutputStream(xmlFile); IOUtils.write(xml, xmlStream, UTF_8); File xsdFile = new File(outputFolder, "output.xsd"); xml2xsd(xmlFile.getAbsolutePath(), xsdFile.getAbsolutePath()); }