Posts

Showing posts with the label J2EE

XML To JSON Converter

Have the following jars in the classpath,  commons-beanutils-1.6.1.jar  commons-collections-3.2.jar  commons-lang-2.1.jar  commons-logging-1.1.jar  ezmorph-1.0.4.jar  json-lib-2.3-jdk15.jar  xom-1.0.jar import net.sf.json.JSON; import net.sf.json.xml.XMLSerializer; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; public class XML2JSONConverter {     public String convertXMLTOJSON(String inputXML) {         String jsonString = "";         try {             JSON objJson = new XMLSerializer().read(inputXML);             jsonString = objJson.toString();         } catch (Exception e) {             e.printStackTrace();         }         return jsonString;     }     static String co...

Java InputStream to String Covertion

Found this small method to convert InputStream to String, This will help to avoid using Apache IOUtils etc.,  static String convertStreamToString(java.io.InputStream is) {         java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");         return s.hasNext() ? s.next() : "";     }