Reinstate JSON license notices in datarouter
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / json / JSONStringer.java
index 87c8a5b..91b5877 100644 (file)
  ******************************************************************************/\r
 package org.json;\r
 \r
+/*\r
+Copyright (c) 2006 JSON.org\r
 \r
+Permission is hereby granted, free of charge, to any person obtaining a copy\r
+of this software and associated documentation files (the "Software"), to deal\r
+in the Software without restriction, including without limitation the rights\r
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+copies of the Software, and to permit persons to whom the Software is\r
+furnished to do so, subject to the following conditions:\r
 \r
-import java.io.StringWriter;\r
+The above copyright notice and this permission notice shall be included in all\r
+copies or substantial portions of the Software.\r
+\r
+The Software shall be used for Good, not Evil.\r
+\r
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
+SOFTWARE.\r
+*/\r
 \r
+import java.io.StringWriter;\r
 \r
+/**\r
+ * JSONStringer provides a quick and convenient way of producing JSON text.\r
+ * The texts produced strictly conform to JSON syntax rules. No whitespace is\r
+ * added, so the results are ready for transmission or storage. Each instance of\r
+ * JSONStringer can produce one JSON text.\r
+ * <p>\r
+ * A JSONStringer instance provides a <code>value</code> method for appending\r
+ * values to the\r
+ * text, and a <code>key</code>\r
+ * method for adding keys before values in objects. There are <code>array</code>\r
+ * and <code>endArray</code> methods that make and bound array values, and\r
+ * <code>object</code> and <code>endObject</code> methods which make and bound\r
+ * object values. All of these methods return the JSONWriter instance,\r
+ * permitting cascade style. For example, <pre>\r
+ * myString = new JSONStringer()\r
+ *     .object()\r
+ *         .key("JSON")\r
+ *         .value("Hello, World!")\r
+ *     .endObject()\r
+ *     .toString();</pre> which produces the string <pre>\r
+ * {"JSON":"Hello, World!"}</pre>\r
+ * <p>\r
+ * The first method called must be <code>array</code> or <code>object</code>.\r
+ * There are no methods for adding commas or colons. JSONStringer adds them for\r
+ * you. Objects and arrays can be nested up to 20 levels deep.\r
+ * <p>\r
+ * This can sometimes be easier than using a JSONObject to build a string.\r
+ * @author JSON.org\r
+ * @version 2008-09-18\r
+ */\r
 public class JSONStringer extends JSONWriter {\r
     /**\r
      * Make a fresh JSONStringer. It can be used to build one JSON text.\r
@@ -35,7 +86,14 @@ public class JSONStringer extends JSONWriter {
         super(new StringWriter());\r
     }\r
 \r
-   \r
+    /**\r
+     * Return the JSON text. This method is used to obtain the product of the\r
+     * JSONStringer instance. It will return <code>null</code> if there was a\r
+     * problem in the construction of the JSON text (such as the calls to\r
+     * <code>array</code> were not properly balanced with calls to\r
+     * <code>endArray</code>).\r
+     * @return The JSON text.\r
+     */\r
     public String toString() {\r
         return this.mode == 'd' ? this.writer.toString() : null;\r
     }\r