From 9b89bbcdc909d24039d37bd3b2ff2805b27bbf78 Mon Sep 17 00:00:00 2001 From: Marcus Longmuir Date: Fri, 2 Aug 2013 01:38:53 +0100 Subject: [PATCH 1/4] Initial commit. --- .gitignore | 6 + .settings/org.eclipse.jdt.core.prefs | 13 + JSONArray.java | 14 +- JSONObject.java | 3213 +++++++++++----------- None.java | 9 + RawJSON.java | 31 + bin/.gitignore | 6 + bin/.settings/org.eclipse.jdt.core.prefs | 13 + bin/CDL.class | Bin 0 -> 1505 bytes bin/Cookie.class | Bin 0 -> 876 bytes bin/CookieList.class | Bin 0 -> 715 bytes bin/HTTP.class | Bin 0 -> 765 bytes bin/HTTPTokener.class | Bin 0 -> 590 bytes bin/JSONArray.class | Bin 0 -> 5139 bytes bin/JSONException.class | Bin 0 -> 768 bytes bin/JSONML.class | Bin 0 -> 1227 bytes bin/JSONObject$Null.class | Bin 0 -> 815 bytes bin/JSONObject.class | Bin 0 -> 8059 bytes bin/JSONString.class | Bin 0 -> 441 bytes bin/JSONStringer.class | Bin 0 -> 555 bytes bin/JSONTokener.class | Bin 0 -> 2243 bytes bin/JSONWriter.class | Bin 0 -> 1931 bytes bin/Kim.class | Bin 0 -> 1434 bytes bin/None.class | Bin 0 -> 431 bytes bin/Property.class | Bin 0 -> 721 bytes bin/README | 68 + bin/RawJSON.class | Bin 0 -> 857 bytes bin/XML.class | Bin 0 -> 1396 bytes bin/XMLTokener.class | Bin 0 -> 1138 bytes bin/build.gradle | 20 + bin/build.sh | 25 + bin/zip/BitInputStream.class | Bin 0 -> 1114 bytes bin/zip/BitOutputStream.class | Bin 0 -> 1091 bytes bin/zip/BitReader.class | Bin 0 -> 558 bytes bin/zip/BitWriter.class | Bin 0 -> 579 bytes bin/zip/Compressor.class | Bin 0 -> 15882 bytes bin/zip/Decompressor.class | Bin 0 -> 11292 bytes bin/zip/Huff$Symbol.class | Bin 0 -> 1211 bytes bin/zip/Huff.class | Bin 0 -> 2481 bytes bin/zip/JSONzip.class | Bin 0 -> 1786 bytes bin/zip/Keep.class | Bin 0 -> 831 bytes bin/zip/MapKeep.class | Bin 0 -> 1223 bytes bin/zip/None.class | Bin 0 -> 442 bytes bin/zip/PostMortem.class | Bin 0 -> 449 bytes bin/zip/README | 2 + bin/zip/TrieKeep$Node.class | Bin 0 -> 2325 bytes bin/zip/TrieKeep.class | Bin 0 -> 3550 bytes build.gradle | 20 + build.sh | 25 + 49 files changed, 1871 insertions(+), 1594 deletions(-) create mode 100644 .gitignore create mode 100644 .settings/org.eclipse.jdt.core.prefs create mode 100644 None.java create mode 100644 RawJSON.java create mode 100644 bin/.gitignore create mode 100644 bin/.settings/org.eclipse.jdt.core.prefs create mode 100644 bin/CDL.class create mode 100644 bin/Cookie.class create mode 100644 bin/CookieList.class create mode 100644 bin/HTTP.class create mode 100644 bin/HTTPTokener.class create mode 100644 bin/JSONArray.class create mode 100644 bin/JSONException.class create mode 100644 bin/JSONML.class create mode 100644 bin/JSONObject$Null.class create mode 100644 bin/JSONObject.class create mode 100644 bin/JSONString.class create mode 100644 bin/JSONStringer.class create mode 100644 bin/JSONTokener.class create mode 100644 bin/JSONWriter.class create mode 100644 bin/Kim.class create mode 100644 bin/None.class create mode 100644 bin/Property.class create mode 100755 bin/README create mode 100644 bin/RawJSON.class create mode 100644 bin/XML.class create mode 100644 bin/XMLTokener.class create mode 100644 bin/build.gradle create mode 100644 bin/build.sh create mode 100644 bin/zip/BitInputStream.class create mode 100644 bin/zip/BitOutputStream.class create mode 100644 bin/zip/BitReader.class create mode 100644 bin/zip/BitWriter.class create mode 100644 bin/zip/Compressor.class create mode 100644 bin/zip/Decompressor.class create mode 100644 bin/zip/Huff$Symbol.class create mode 100644 bin/zip/Huff.class create mode 100644 bin/zip/JSONzip.class create mode 100644 bin/zip/Keep.class create mode 100644 bin/zip/MapKeep.class create mode 100644 bin/zip/None.class create mode 100644 bin/zip/PostMortem.class create mode 100644 bin/zip/README create mode 100644 bin/zip/TrieKeep$Node.class create mode 100644 bin/zip/TrieKeep.class create mode 100644 build.gradle create mode 100644 build.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..3a00a4770 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/build +/jar +/.gradle +/.classpath +/.DS_Store +/.project diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..4b6f4c10e --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,13 @@ +# +#Thu Aug 01 20:22:57 BST 2013 +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error diff --git a/JSONArray.java b/JSONArray.java index 673a91927..69f1eb653 100644 --- a/JSONArray.java +++ b/JSONArray.java @@ -31,6 +31,7 @@ of this software and associated documentation files (the "Software"), to deal import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.ListIterator; import java.util.Map; /** @@ -69,20 +70,22 @@ of this software and associated documentation files (the "Software"), to deal *
  • Strings do not need to be quoted at all if they do not begin with a quote * or single quote, and if they do not contain leading or trailing spaces, and * if they do not contain any of these characters: - * { } [ ] / \ : , # and if they do not look like numbers and + * { } [ ] / \ : , = ; # and if they do not look like numbers and * if they are not the reserved words true, false, or * null.
  • + *
  • Values can be separated by ; (semicolon) as + * well as by , (comma).
  • * * * @author JSON.org - * @version 2013-04-18 + * @version 2012-11-13 */ public class JSONArray { /** * The arrayList where the JSONArray's properties are kept. */ - private final ArrayList myArrayList; + public final ArrayList myArrayList; /** * Construct an empty JSONArray. @@ -90,6 +93,10 @@ public class JSONArray { public JSONArray() { this.myArrayList = new ArrayList(); } + + public ListIterator listIterator(){ + return this.myArrayList.listIterator(); + } /** * Construct a JSONArray from a JSONTokener. @@ -115,6 +122,7 @@ public JSONArray(JSONTokener x) throws JSONException { this.myArrayList.add(x.nextValue()); } switch (x.nextClean()) { + case ';': case ',': if (x.nextClean() == ']') { return; diff --git a/JSONObject.java b/JSONObject.java index 5ca5a45bc..e12f539c9 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -1,27 +1,27 @@ package org.json; /* - Copyright (c) 2002 JSON.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - The Software shall be used for Good, not Evil. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. */ import java.io.IOException; @@ -35,40 +35,40 @@ of this software and associated documentation files (the "Software"), to deal import java.util.HashMap; import java.util.Iterator; import java.util.Locale; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.Map.Entry; import java.util.ResourceBundle; import java.util.Set; +import java.util.TreeMap; /** * A JSONObject is an unordered collection of name/value pairs. Its external * form is a string wrapped in curly braces with colons between the names and * values, and commas between the values and names. The internal form is an - * object having get and opt methods for accessing - * the values by name, and put methods for adding or replacing - * values by name. The values can be any of these types: Boolean, + * object having get and opt methods for accessing the + * values by name, and put methods for adding or replacing values + * by name. The values can be any of these types: Boolean, * JSONArray, JSONObject, Number, - * String, or the JSONObject.NULL object. A - * JSONObject constructor can be used to convert an external form JSON text - * into an internal form whose values can be retrieved with the - * get and opt methods, or to convert values into a - * JSON text using the put and toString methods. A - * get method returns a value if one can be found, and throws an - * exception if one cannot be found. An opt method returns a - * default value instead of throwing an exception, and so is useful for - * obtaining optional values. + * String, or the JSONObject.NULL object. A JSONObject + * constructor can be used to convert an external form JSON text into an + * internal form whose values can be retrieved with the get and + * opt methods, or to convert values into a JSON text using the + * put and toString methods. A get method + * returns a value if one can be found, and throws an exception if one cannot be + * found. An opt method returns a default value instead of throwing + * an exception, and so is useful for obtaining optional values. *

    * The generic get() and opt() methods return an * object, which you can cast or query for type. There are also typed * get and opt methods that do type checking and type - * coercion for you. The opt methods differ from the get methods in that they - * do not throw. Instead, they return a specified value, such as null. + * coercion for you. The opt methods differ from the get methods in that they do + * not throw. Instead, they return a specified value, such as null. *

    - * The put methods add or replace values in an object. For - * example, + * The put methods add or replace values in an object. For example, * *

    - * myString = new JSONObject()
    - *         .put("JSON", "Hello, World!").toString();
    + * myString = new JSONObject().put("JSON", "Hello, World!").toString();
      * 
    * * produces the string {"JSON": "Hello, World"}. @@ -81,1561 +81,1592 @@ of this software and associated documentation files (the "Software"), to deal * before the closing brace. *
  • Strings may be quoted with ' (single * quote).
  • - *
  • Strings do not need to be quoted at all if they do not begin with a - * quote or single quote, and if they do not contain leading or trailing - * spaces, and if they do not contain any of these characters: - * { } [ ] / \ : , # and if they do not look like numbers and - * if they are not the reserved words true, false, - * or null.
  • + *
  • Strings do not need to be quoted at all if they do not begin with a quote + * or single quote, and if they do not contain leading or trailing spaces, and + * if they do not contain any of these characters: + * { } [ ] / \ : , = ; # and if they do not look like numbers and + * if they are not the reserved words true, false, or + * null.
  • + *
  • Keys can be followed by = or => as well as by + * :.
  • + *
  • Values can be followed by ; (semicolon) as + * well as by , (comma).
  • * * * @author JSON.org - * @version 2013-06-17 + * @version 2012-12-01 */ public class JSONObject { - /** - * JSONObject.NULL is equivalent to the value that JavaScript calls null, - * whilst Java's null is equivalent to the value that JavaScript calls - * undefined. - */ - private static final class Null { - - /** - * There is only intended to be a single instance of the NULL object, - * so the clone method returns itself. - * - * @return NULL. - */ - protected final Object clone() { - return this; - } - - /** - * A Null object is equal to the null value and to itself. - * - * @param object - * An object to test for nullness. - * @return true if the object parameter is the JSONObject.NULL object or - * null. - */ - public boolean equals(Object object) { - return object == null || object == this; - } - - /** - * Get the "null" string value. - * - * @return The string "null". - */ - public String toString() { - return "null"; - } - } - - /** - * The map where the JSONObject's properties are kept. - */ - private final Map map; - - /** - * It is sometimes more convenient and less ambiguous to have a - * NULL object than to use Java's null value. - * JSONObject.NULL.equals(null) returns true. - * JSONObject.NULL.toString() returns "null". - */ - public static final Object NULL = new Null(); - - /** - * Construct an empty JSONObject. - */ - public JSONObject() { - this.map = new HashMap(); - } - - /** - * Construct a JSONObject from a subset of another JSONObject. An array of - * strings is used to identify the keys that should be copied. Missing keys - * are ignored. - * - * @param jo - * A JSONObject. - * @param names - * An array of strings. - * @throws JSONException - * @exception JSONException - * If a value is a non-finite number or if a name is - * duplicated. - */ - public JSONObject(JSONObject jo, String[] names) { - this(); - for (int i = 0; i < names.length; i += 1) { - try { - this.putOnce(names[i], jo.opt(names[i])); - } catch (Exception ignore) { - } - } - } - - /** - * Construct a JSONObject from a JSONTokener. - * - * @param x - * A JSONTokener object containing the source string. - * @throws JSONException - * If there is a syntax error in the source string or a - * duplicated key. - */ - public JSONObject(JSONTokener x) throws JSONException { - this(); - char c; - String key; - - if (x.nextClean() != '{') { - throw x.syntaxError("A JSONObject text must begin with '{'"); - } - for (;;) { - c = x.nextClean(); - switch (c) { - case 0: - throw x.syntaxError("A JSONObject text must end with '}'"); - case '}': - return; - default: - x.back(); - key = x.nextValue().toString(); - } - -// The key is followed by ':'. - - c = x.nextClean(); - if (c != ':') { - throw x.syntaxError("Expected a ':' after a key"); - } - this.putOnce(key, x.nextValue()); - -// Pairs are separated by ','. - - switch (x.nextClean()) { - case ';': - case ',': - if (x.nextClean() == '}') { - return; - } - x.back(); - break; - case '}': - return; - default: - throw x.syntaxError("Expected a ',' or '}'"); - } - } - } - - /** - * Construct a JSONObject from a Map. - * - * @param map - * A map object that can be used to initialize the contents of - * the JSONObject. - * @throws JSONException - */ - public JSONObject(Map map) { - this.map = new HashMap(); - if (map != null) { - Iterator i = map.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry e = (Map.Entry) i.next(); - Object value = e.getValue(); - if (value != null) { - this.map.put(e.getKey(), wrap(value)); - } - } - } - } - - /** - * Construct a JSONObject from an Object using bean getters. It reflects on - * all of the public methods of the object. For each of the methods with no - * parameters and a name starting with "get" or - * "is" followed by an uppercase letter, the method is invoked, - * and a key and the value returned from the getter method are put into the - * new JSONObject. - * - * The key is formed by removing the "get" or "is" - * prefix. If the second remaining character is not upper case, then the - * first character is converted to lower case. - * - * For example, if an object has a method named "getName", and - * if the result of calling object.getName() is - * "Larry Fine", then the JSONObject will contain - * "name": "Larry Fine". - * - * @param bean - * An object that has getter methods that should be used to make - * a JSONObject. - */ - public JSONObject(Object bean) { - this(); - this.populateMap(bean); - } - - /** - * Construct a JSONObject from an Object, using reflection to find the - * public members. The resulting JSONObject's keys will be the strings from - * the names array, and the values will be the field values associated with - * those keys in the object. If a key is not found or not visible, then it - * will not be copied into the new JSONObject. - * - * @param object - * An object that has fields that should be used to make a - * JSONObject. - * @param names - * An array of strings, the names of the fields to be obtained - * from the object. - */ - public JSONObject(Object object, String names[]) { - this(); - Class c = object.getClass(); - for (int i = 0; i < names.length; i += 1) { - String name = names[i]; - try { - this.putOpt(name, c.getField(name).get(object)); - } catch (Exception ignore) { - } - } - } - - /** - * Construct a JSONObject from a source JSON text string. This is the most - * commonly used JSONObject constructor. - * - * @param source - * A string beginning with { (left - * brace) and ending with } - *  (right brace). - * @exception JSONException - * If there is a syntax error in the source string or a - * duplicated key. - */ - public JSONObject(String source) throws JSONException { - this(new JSONTokener(source)); - } - - /** - * Construct a JSONObject from a ResourceBundle. - * - * @param baseName - * The ResourceBundle base name. - * @param locale - * The Locale to load the ResourceBundle for. - * @throws JSONException - * If any JSONExceptions are detected. - */ - public JSONObject(String baseName, Locale locale) throws JSONException { - this(); - ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, - Thread.currentThread().getContextClassLoader()); - -// Iterate through the keys in the bundle. - - Enumeration keys = bundle.getKeys(); - while (keys.hasMoreElements()) { - Object key = keys.nextElement(); - if (key instanceof String) { - -// Go through the path, ensuring that there is a nested JSONObject for each -// segment except the last. Add the value using the last segment's name into -// the deepest nested JSONObject. - - String[] path = ((String) key).split("\\."); - int last = path.length - 1; - JSONObject target = this; - for (int i = 0; i < last; i += 1) { - String segment = path[i]; - JSONObject nextTarget = target.optJSONObject(segment); - if (nextTarget == null) { - nextTarget = new JSONObject(); - target.put(segment, nextTarget); - } - target = nextTarget; - } - target.put(path[last], bundle.getString((String) key)); - } - } - } - - /** - * Accumulate values under a key. It is similar to the put method except - * that if there is already an object stored under the key then a JSONArray - * is stored under the key to hold all of the accumulated values. If there - * is already a JSONArray, then the new value is appended to it. In - * contrast, the put method replaces the previous value. - * - * If only one value is accumulated that is not a JSONArray, then the result - * will be the same as using put. But if multiple values are accumulated, - * then the result will be like append. - * - * @param key - * A key string. - * @param value - * An object to be accumulated under the key. - * @return this. - * @throws JSONException - * If the value is an invalid number or if the key is null. - */ - public JSONObject accumulate(String key, Object value) throws JSONException { - testValidity(value); - Object object = this.opt(key); - if (object == null) { - this.put(key, - value instanceof JSONArray ? new JSONArray().put(value) - : value); - } else if (object instanceof JSONArray) { - ((JSONArray) object).put(value); - } else { - this.put(key, new JSONArray().put(object).put(value)); - } - return this; - } - - /** - * Append values to the array under a key. If the key does not exist in the - * JSONObject, then the key is put in the JSONObject with its value being a - * JSONArray containing the value parameter. If the key was already - * associated with a JSONArray, then the value parameter is appended to it. - * - * @param key - * A key string. - * @param value - * An object to be accumulated under the key. - * @return this. - * @throws JSONException - * If the key is null or if the current value associated with - * the key is not a JSONArray. - */ - public JSONObject append(String key, Object value) throws JSONException { - testValidity(value); - Object object = this.opt(key); - if (object == null) { - this.put(key, new JSONArray().put(value)); - } else if (object instanceof JSONArray) { - this.put(key, ((JSONArray) object).put(value)); - } else { - throw new JSONException("JSONObject[" + key - + "] is not a JSONArray."); - } - return this; - } - - /** - * Produce a string from a double. The string "null" will be returned if the - * number is not finite. - * - * @param d - * A double. - * @return A String. - */ - public static String doubleToString(double d) { - if (Double.isInfinite(d) || Double.isNaN(d)) { - return "null"; - } - -// Shave off trailing zeros and decimal point, if possible. - - String string = Double.toString(d); - if (string.indexOf('.') > 0 && string.indexOf('e') < 0 - && string.indexOf('E') < 0) { - while (string.endsWith("0")) { - string = string.substring(0, string.length() - 1); - } - if (string.endsWith(".")) { - string = string.substring(0, string.length() - 1); - } - } - return string; - } - - /** - * Get the value object associated with a key. - * - * @param key - * A key string. - * @return The object associated with the key. - * @throws JSONException - * if the key is not found. - */ - public Object get(String key) throws JSONException { - if (key == null) { - throw new JSONException("Null key."); - } - Object object = this.opt(key); - if (object == null) { - throw new JSONException("JSONObject[" + quote(key) + "] not found."); - } - return object; - } - - /** - * Get the boolean value associated with a key. - * - * @param key - * A key string. - * @return The truth. - * @throws JSONException - * if the value is not a Boolean or the String "true" or - * "false". - */ - public boolean getBoolean(String key) throws JSONException { - Object object = this.get(key); - if (object.equals(Boolean.FALSE) - || (object instanceof String && ((String) object) - .equalsIgnoreCase("false"))) { - return false; - } else if (object.equals(Boolean.TRUE) - || (object instanceof String && ((String) object) - .equalsIgnoreCase("true"))) { - return true; - } - throw new JSONException("JSONObject[" + quote(key) - + "] is not a Boolean."); - } - - /** - * Get the double value associated with a key. - * - * @param key - * A key string. - * @return The numeric value. - * @throws JSONException - * if the key is not found or if the value is not a Number - * object and cannot be converted to a number. - */ - public double getDouble(String key) throws JSONException { - Object object = this.get(key); - try { - return object instanceof Number ? ((Number) object).doubleValue() - : Double.parseDouble((String) object); - } catch (Exception e) { - throw new JSONException("JSONObject[" + quote(key) - + "] is not a number."); - } - } - - /** - * Get the int value associated with a key. - * - * @param key - * A key string. - * @return The integer value. - * @throws JSONException - * if the key is not found or if the value cannot be converted - * to an integer. - */ - public int getInt(String key) throws JSONException { - Object object = this.get(key); - try { - return object instanceof Number ? ((Number) object).intValue() - : Integer.parseInt((String) object); - } catch (Exception e) { - throw new JSONException("JSONObject[" + quote(key) - + "] is not an int."); - } - } - - /** - * Get the JSONArray value associated with a key. - * - * @param key - * A key string. - * @return A JSONArray which is the value. - * @throws JSONException - * if the key is not found or if the value is not a JSONArray. - */ - public JSONArray getJSONArray(String key) throws JSONException { - Object object = this.get(key); - if (object instanceof JSONArray) { - return (JSONArray) object; - } - throw new JSONException("JSONObject[" + quote(key) - + "] is not a JSONArray."); - } - - /** - * Get the JSONObject value associated with a key. - * - * @param key - * A key string. - * @return A JSONObject which is the value. - * @throws JSONException - * if the key is not found or if the value is not a JSONObject. - */ - public JSONObject getJSONObject(String key) throws JSONException { - Object object = this.get(key); - if (object instanceof JSONObject) { - return (JSONObject) object; - } - throw new JSONException("JSONObject[" + quote(key) - + "] is not a JSONObject."); - } - - /** - * Get the long value associated with a key. - * - * @param key - * A key string. - * @return The long value. - * @throws JSONException - * if the key is not found or if the value cannot be converted - * to a long. - */ - public long getLong(String key) throws JSONException { - Object object = this.get(key); - try { - return object instanceof Number ? ((Number) object).longValue() - : Long.parseLong((String) object); - } catch (Exception e) { - throw new JSONException("JSONObject[" + quote(key) - + "] is not a long."); - } - } - - /** - * Get an array of field names from a JSONObject. - * - * @return An array of field names, or null if there are no names. - */ - public static String[] getNames(JSONObject jo) { - int length = jo.length(); - if (length == 0) { - return null; - } - Iterator iterator = jo.keys(); - String[] names = new String[length]; - int i = 0; - while (iterator.hasNext()) { - names[i] = (String) iterator.next(); - i += 1; - } - return names; - } - - /** - * Get an array of field names from an Object. - * - * @return An array of field names, or null if there are no names. - */ - public static String[] getNames(Object object) { - if (object == null) { - return null; - } - Class klass = object.getClass(); - Field[] fields = klass.getFields(); - int length = fields.length; - if (length == 0) { - return null; - } - String[] names = new String[length]; - for (int i = 0; i < length; i += 1) { - names[i] = fields[i].getName(); - } - return names; - } - - /** - * Get the string associated with a key. - * - * @param key - * A key string. - * @return A string which is the value. - * @throws JSONException - * if there is no string value for the key. - */ - public String getString(String key) throws JSONException { - Object object = this.get(key); - if (object instanceof String) { - return (String) object; - } - throw new JSONException("JSONObject[" + quote(key) + "] not a string."); - } - - /** - * Determine if the JSONObject contains a specific key. - * - * @param key - * A key string. - * @return true if the key exists in the JSONObject. - */ - public boolean has(String key) { - return this.map.containsKey(key); - } - - /** - * Increment a property of a JSONObject. If there is no such property, - * create one with a value of 1. If there is such a property, and if it is - * an Integer, Long, Double, or Float, then add one to it. - * - * @param key - * A key string. - * @return this. - * @throws JSONException - * If there is already a property with this name that is not an - * Integer, Long, Double, or Float. - */ - public JSONObject increment(String key) throws JSONException { - Object value = this.opt(key); - if (value == null) { - this.put(key, 1); - } else if (value instanceof Integer) { - this.put(key, ((Integer) value).intValue() + 1); - } else if (value instanceof Long) { - this.put(key, ((Long) value).longValue() + 1); - } else if (value instanceof Double) { - this.put(key, ((Double) value).doubleValue() + 1); - } else if (value instanceof Float) { - this.put(key, ((Float) value).floatValue() + 1); - } else { - throw new JSONException("Unable to increment [" + quote(key) + "]."); - } - return this; - } - - /** - * Determine if the value associated with the key is null or if there is no - * value. - * - * @param key - * A key string. - * @return true if there is no value associated with the key or if the value - * is the JSONObject.NULL object. - */ - public boolean isNull(String key) { - return JSONObject.NULL.equals(this.opt(key)); - } - - /** - * Get an enumeration of the keys of the JSONObject. - * - * @return An iterator of the keys. - */ - public Iterator keys() { - return this.keySet().iterator(); - } - - /** - * Get a set of keys of the JSONObject. - * - * @return A keySet. - */ - public Set keySet() { - return this.map.keySet(); - } - - /** - * Get the number of keys stored in the JSONObject. - * - * @return The number of keys in the JSONObject. - */ - public int length() { - return this.map.size(); - } - - /** - * Produce a JSONArray containing the names of the elements of this - * JSONObject. - * - * @return A JSONArray containing the key strings, or null if the JSONObject - * is empty. - */ - public JSONArray names() { - JSONArray ja = new JSONArray(); - Iterator keys = this.keys(); - while (keys.hasNext()) { - ja.put(keys.next()); - } - return ja.length() == 0 ? null : ja; - } - - /** - * Produce a string from a Number. - * - * @param number - * A Number - * @return A String. - * @throws JSONException - * If n is a non-finite number. - */ - public static String numberToString(Number number) throws JSONException { - if (number == null) { - throw new JSONException("Null pointer"); - } - testValidity(number); - -// Shave off trailing zeros and decimal point, if possible. - - String string = number.toString(); - if (string.indexOf('.') > 0 && string.indexOf('e') < 0 - && string.indexOf('E') < 0) { - while (string.endsWith("0")) { - string = string.substring(0, string.length() - 1); - } - if (string.endsWith(".")) { - string = string.substring(0, string.length() - 1); - } - } - return string; - } - - /** - * Get an optional value associated with a key. - * - * @param key - * A key string. - * @return An object which is the value, or null if there is no value. - */ - public Object opt(String key) { - return key == null ? null : this.map.get(key); - } - - /** - * Get an optional boolean associated with a key. It returns false if there - * is no such key, or if the value is not Boolean.TRUE or the String "true". - * - * @param key - * A key string. - * @return The truth. - */ - public boolean optBoolean(String key) { - return this.optBoolean(key, false); - } - - /** - * Get an optional boolean associated with a key. It returns the - * defaultValue if there is no such key, or if it is not a Boolean or the - * String "true" or "false" (case insensitive). - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return The truth. - */ - public boolean optBoolean(String key, boolean defaultValue) { - try { - return this.getBoolean(key); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get an optional double associated with a key, or NaN if there is no such - * key or if its value is not a number. If the value is a string, an attempt - * will be made to evaluate it as a number. - * - * @param key - * A string which is the key. - * @return An object which is the value. - */ - public double optDouble(String key) { - return this.optDouble(key, Double.NaN); - } - - /** - * Get an optional double associated with a key, or the defaultValue if - * there is no such key or if its value is not a number. If the value is a - * string, an attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return An object which is the value. - */ - public double optDouble(String key, double defaultValue) { - try { - return this.getDouble(key); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get an optional int value associated with a key, or zero if there is no - * such key or if the value is not a number. If the value is a string, an - * attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @return An object which is the value. - */ - public int optInt(String key) { - return this.optInt(key, 0); - } - - /** - * Get an optional int value associated with a key, or the default if there - * is no such key or if the value is not a number. If the value is a string, - * an attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return An object which is the value. - */ - public int optInt(String key, int defaultValue) { - try { - return this.getInt(key); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get an optional JSONArray associated with a key. It returns null if there - * is no such key, or if its value is not a JSONArray. - * - * @param key - * A key string. - * @return A JSONArray which is the value. - */ - public JSONArray optJSONArray(String key) { - Object o = this.opt(key); - return o instanceof JSONArray ? (JSONArray) o : null; - } - - /** - * Get an optional JSONObject associated with a key. It returns null if - * there is no such key, or if its value is not a JSONObject. - * - * @param key - * A key string. - * @return A JSONObject which is the value. - */ - public JSONObject optJSONObject(String key) { - Object object = this.opt(key); - return object instanceof JSONObject ? (JSONObject) object : null; - } - - /** - * Get an optional long value associated with a key, or zero if there is no - * such key or if the value is not a number. If the value is a string, an - * attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @return An object which is the value. - */ - public long optLong(String key) { - return this.optLong(key, 0); - } - - /** - * Get an optional long value associated with a key, or the default if there - * is no such key or if the value is not a number. If the value is a string, - * an attempt will be made to evaluate it as a number. - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return An object which is the value. - */ - public long optLong(String key, long defaultValue) { - try { - return this.getLong(key); - } catch (Exception e) { - return defaultValue; - } - } - - /** - * Get an optional string associated with a key. It returns an empty string - * if there is no such key. If the value is not a string and is not null, - * then it is converted to a string. - * - * @param key - * A key string. - * @return A string which is the value. - */ - public String optString(String key) { - return this.optString(key, ""); - } - - /** - * Get an optional string associated with a key. It returns the defaultValue - * if there is no such key. - * - * @param key - * A key string. - * @param defaultValue - * The default. - * @return A string which is the value. - */ - public String optString(String key, String defaultValue) { - Object object = this.opt(key); - return NULL.equals(object) ? defaultValue : object.toString(); - } - - private void populateMap(Object bean) { - Class klass = bean.getClass(); - -// If klass is a System class then set includeSuperClass to false. - - boolean includeSuperClass = klass.getClassLoader() != null; - - Method[] methods = includeSuperClass ? klass.getMethods() : klass - .getDeclaredMethods(); - for (int i = 0; i < methods.length; i += 1) { - try { - Method method = methods[i]; - if (Modifier.isPublic(method.getModifiers())) { - String name = method.getName(); - String key = ""; - if (name.startsWith("get")) { - if ("getClass".equals(name) - || "getDeclaringClass".equals(name)) { - key = ""; - } else { - key = name.substring(3); - } - } else if (name.startsWith("is")) { - key = name.substring(2); - } - if (key.length() > 0 - && Character.isUpperCase(key.charAt(0)) - && method.getParameterTypes().length == 0) { - if (key.length() == 1) { - key = key.toLowerCase(); - } else if (!Character.isUpperCase(key.charAt(1))) { - key = key.substring(0, 1).toLowerCase() - + key.substring(1); - } - - Object result = method.invoke(bean, (Object[]) null); - if (result != null) { - this.map.put(key, wrap(result)); - } - } - } - } catch (Exception ignore) { - } - } - } - - /** - * Put a key/boolean pair in the JSONObject. - * - * @param key - * A key string. - * @param value - * A boolean which is the value. - * @return this. - * @throws JSONException - * If the key is null. - */ - public JSONObject put(String key, boolean value) throws JSONException { - this.put(key, value ? Boolean.TRUE : Boolean.FALSE); - return this; - } - - /** - * Put a key/value pair in the JSONObject, where the value will be a - * JSONArray which is produced from a Collection. - * - * @param key - * A key string. - * @param value - * A Collection value. - * @return this. - * @throws JSONException - */ - public JSONObject put(String key, Collection value) throws JSONException { - this.put(key, new JSONArray(value)); - return this; - } - - /** - * Put a key/double pair in the JSONObject. - * - * @param key - * A key string. - * @param value - * A double which is the value. - * @return this. - * @throws JSONException - * If the key is null or if the number is invalid. - */ - public JSONObject put(String key, double value) throws JSONException { - this.put(key, new Double(value)); - return this; - } - - /** - * Put a key/int pair in the JSONObject. - * - * @param key - * A key string. - * @param value - * An int which is the value. - * @return this. - * @throws JSONException - * If the key is null. - */ - public JSONObject put(String key, int value) throws JSONException { - this.put(key, new Integer(value)); - return this; - } - - /** - * Put a key/long pair in the JSONObject. - * - * @param key - * A key string. - * @param value - * A long which is the value. - * @return this. - * @throws JSONException - * If the key is null. - */ - public JSONObject put(String key, long value) throws JSONException { - this.put(key, new Long(value)); - return this; - } - - /** - * Put a key/value pair in the JSONObject, where the value will be a - * JSONObject which is produced from a Map. - * - * @param key - * A key string. - * @param value - * A Map value. - * @return this. - * @throws JSONException - */ - public JSONObject put(String key, Map value) throws JSONException { - this.put(key, new JSONObject(value)); - return this; - } - - /** - * Put a key/value pair in the JSONObject. If the value is null, then the - * key will be removed from the JSONObject if it is present. - * - * @param key - * A key string. - * @param value - * An object which is the value. It should be of one of these - * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, - * String, or the JSONObject.NULL object. - * @return this. - * @throws JSONException - * If the value is non-finite number or if the key is null. - */ - public JSONObject put(String key, Object value) throws JSONException { - if (key == null) { - throw new NullPointerException("Null key."); - } - if (value != null) { - testValidity(value); - this.map.put(key, value); - } else { - this.remove(key); - } - return this; - } - - /** - * Put a key/value pair in the JSONObject, but only if the key and the value - * are both non-null, and only if there is not already a member with that - * name. - * - * @param key - * @param value - * @return his. - * @throws JSONException - * if the key is a duplicate - */ - public JSONObject putOnce(String key, Object value) throws JSONException { - if (key != null && value != null) { - if (this.opt(key) != null) { - throw new JSONException("Duplicate key \"" + key + "\""); - } - this.put(key, value); - } - return this; - } - - /** - * Put a key/value pair in the JSONObject, but only if the key and the value - * are both non-null. - * - * @param key - * A key string. - * @param value - * An object which is the value. It should be of one of these - * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, - * String, or the JSONObject.NULL object. - * @return this. - * @throws JSONException - * If the value is a non-finite number. - */ - public JSONObject putOpt(String key, Object value) throws JSONException { - if (key != null && value != null) { - this.put(key, value); - } - return this; - } - - /** - * Produce a string in double quotes with backslash sequences in all the - * right places. A backslash will be inserted within = '\u0080' && c < '\u00a0') - || (c >= '\u2000' && c < '\u2100')) { - w.write("\\u"); - hhhh = Integer.toHexString(c); - w.write("0000", 0, 4 - hhhh.length()); - w.write(hhhh); - } else { - w.write(c); - } - } - } - w.write('"'); - return w; - } - - /** - * Remove a name and its value, if present. - * - * @param key - * The name to be removed. - * @return The value that was associated with the name, or null if there was - * no value. - */ - public Object remove(String key) { - return this.map.remove(key); - } - - /** - * Try to convert a string into a number, boolean, or null. If the string - * can't be converted, return the string. - * - * @param string - * A String. - * @return A simple JSON value. - */ - public static Object stringToValue(String string) { - Double d; - if (string.equals("")) { - return string; - } - if (string.equalsIgnoreCase("true")) { - return Boolean.TRUE; - } - if (string.equalsIgnoreCase("false")) { - return Boolean.FALSE; - } - if (string.equalsIgnoreCase("null")) { - return JSONObject.NULL; - } - - /* - * If it might be a number, try converting it. If a number cannot be - * produced, then the value will just be a string. - */ - - char b = string.charAt(0); - if ((b >= '0' && b <= '9') || b == '-') { - try { - if (string.indexOf('.') > -1 || string.indexOf('e') > -1 - || string.indexOf('E') > -1) { - d = Double.valueOf(string); - if (!d.isInfinite() && !d.isNaN()) { - return d; - } - } else { - Long myLong = new Long(string); - if (string.equals(myLong.toString())) { - if (myLong.longValue() == myLong.intValue()) { - return new Integer(myLong.intValue()); - } else { - return myLong; - } - } - } - } catch (Exception ignore) { - } - } - return string; - } - - /** - * Throw an exception if the object is a NaN or infinite number. - * - * @param o - * The object to test. - * @throws JSONException - * If o is a non-finite number. - */ - public static void testValidity(Object o) throws JSONException { - if (o != null) { - if (o instanceof Double) { - if (((Double) o).isInfinite() || ((Double) o).isNaN()) { - throw new JSONException( - "JSON does not allow non-finite numbers."); - } - } else if (o instanceof Float) { - if (((Float) o).isInfinite() || ((Float) o).isNaN()) { - throw new JSONException( - "JSON does not allow non-finite numbers."); - } - } - } - } - - /** - * Produce a JSONArray containing the values of the members of this - * JSONObject. - * - * @param names - * A JSONArray containing a list of key strings. This determines - * the sequence of the values in the result. - * @return A JSONArray of values. - * @throws JSONException - * If any of the values are non-finite numbers. - */ - public JSONArray toJSONArray(JSONArray names) throws JSONException { - if (names == null || names.length() == 0) { - return null; - } - JSONArray ja = new JSONArray(); - for (int i = 0; i < names.length(); i += 1) { - ja.put(this.opt(names.getString(i))); - } - return ja; - } - - /** - * Make a JSON text of this JSONObject. For compactness, no whitespace is - * added. If this would not result in a syntactically correct JSON text, - * then null will be returned instead. - *

    - * Warning: This method assumes that the data structure is acyclical. - * - * @return a printable, displayable, portable, transmittable representation - * of the object, beginning with { (left - * brace) and ending with } (right - * brace). - */ - public String toString() { - try { - return this.toString(0); - } catch (Exception e) { - return null; - } - } - - /** - * Make a prettyprinted JSON text of this JSONObject. - *

    - * Warning: This method assumes that the data structure is acyclical. - * - * @param indentFactor - * The number of spaces to add to each level of indentation. - * @return a printable, displayable, portable, transmittable representation - * of the object, beginning with { (left - * brace) and ending with } (right - * brace). - * @throws JSONException - * If the object contains an invalid number. - */ - public String toString(int indentFactor) throws JSONException { - StringWriter w = new StringWriter(); - synchronized (w.getBuffer()) { - return this.write(w, indentFactor, 0).toString(); - } - } - - /** - * Make a JSON text of an Object value. If the object has an - * value.toJSONString() method, then that method will be used to produce the - * JSON text. The method is required to produce a strictly conforming text. - * If the object does not contain a toJSONString method (which is the most - * common case), then a text will be produced by other means. If the value - * is an array or Collection, then a JSONArray will be made from it and its - * toJSONString method will be called. If the value is a MAP, then a - * JSONObject will be made from it and its toJSONString method will be - * called. Otherwise, the value's toString method will be called, and the - * result will be quoted. - * - *

    - * Warning: This method assumes that the data structure is acyclical. - * - * @param value - * The value to be serialized. - * @return a printable, displayable, transmittable representation of the - * object, beginning with { (left - * brace) and ending with } (right - * brace). - * @throws JSONException - * If the value is or contains an invalid number. - */ - public static String valueToString(Object value) throws JSONException { - if (value == null || value.equals(null)) { - return "null"; - } - if (value instanceof JSONString) { - Object object; - try { - object = ((JSONString) value).toJSONString(); - } catch (Exception e) { - throw new JSONException(e); - } - if (object instanceof String) { - return (String) object; - } - throw new JSONException("Bad value from toJSONString: " + object); - } - if (value instanceof Number) { - return numberToString((Number) value); - } - if (value instanceof Boolean || value instanceof JSONObject - || value instanceof JSONArray) { - return value.toString(); - } - if (value instanceof Map) { - return new JSONObject((Map) value).toString(); - } - if (value instanceof Collection) { - return new JSONArray((Collection) value).toString(); - } - if (value.getClass().isArray()) { - return new JSONArray(value).toString(); - } - return quote(value.toString()); - } - - /** - * Wrap an object, if necessary. If the object is null, return the NULL - * object. If it is an array or collection, wrap it in a JSONArray. If it is - * a map, wrap it in a JSONObject. If it is a standard property (Double, - * String, et al) then it is already wrapped. Otherwise, if it comes from - * one of the java packages, turn it into a string. And if it doesn't, try - * to wrap it in a JSONObject. If the wrapping fails, then null is returned. - * - * @param object - * The object to wrap - * @return The wrapped value - */ - public static Object wrap(Object object) { - try { - if (object == null) { - return NULL; - } - if (object instanceof JSONObject || object instanceof JSONArray - || NULL.equals(object) || object instanceof JSONString - || object instanceof Byte || object instanceof Character - || object instanceof Short || object instanceof Integer - || object instanceof Long || object instanceof Boolean - || object instanceof Float || object instanceof Double - || object instanceof String) { - return object; - } - - if (object instanceof Collection) { - return new JSONArray((Collection) object); - } - if (object.getClass().isArray()) { - return new JSONArray(object); - } - if (object instanceof Map) { - return new JSONObject((Map) object); - } - Package objectPackage = object.getClass().getPackage(); - String objectPackageName = objectPackage != null ? objectPackage - .getName() : ""; - if (objectPackageName.startsWith("java.") - || objectPackageName.startsWith("javax.") - || object.getClass().getClassLoader() == null) { - return object.toString(); - } - return new JSONObject(object); - } catch (Exception exception) { - return null; - } - } - - /** - * Write the contents of the JSONObject as JSON text to a writer. For - * compactness, no whitespace is added. - *

    - * Warning: This method assumes that the data structure is acyclical. - * - * @return The writer. - * @throws JSONException - */ - public Writer write(Writer writer) throws JSONException { - return this.write(writer, 0, 0); - } - - static final Writer writeValue(Writer writer, Object value, - int indentFactor, int indent) throws JSONException, IOException { - if (value == null || value.equals(null)) { - writer.write("null"); - } else if (value instanceof JSONObject) { - ((JSONObject) value).write(writer, indentFactor, indent); - } else if (value instanceof JSONArray) { - ((JSONArray) value).write(writer, indentFactor, indent); - } else if (value instanceof Map) { - new JSONObject((Map) value).write(writer, indentFactor, indent); - } else if (value instanceof Collection) { - new JSONArray((Collection) value).write(writer, indentFactor, - indent); - } else if (value.getClass().isArray()) { - new JSONArray(value).write(writer, indentFactor, indent); - } else if (value instanceof Number) { - writer.write(numberToString((Number) value)); - } else if (value instanceof Boolean) { - writer.write(value.toString()); - } else if (value instanceof JSONString) { - Object o; - try { - o = ((JSONString) value).toJSONString(); - } catch (Exception e) { - throw new JSONException(e); - } - writer.write(o != null ? o.toString() : quote(value.toString())); - } else { - quote(value.toString(), writer); - } - return writer; - } - - static final void indent(Writer writer, int indent) throws IOException { - for (int i = 0; i < indent; i += 1) { - writer.write(' '); - } - } - - /** - * Write the contents of the JSONObject as JSON text to a writer. For - * compactness, no whitespace is added. - *

    - * Warning: This method assumes that the data structure is acyclical. - * - * @return The writer. - * @throws JSONException - */ - Writer write(Writer writer, int indentFactor, int indent) - throws JSONException { - try { - boolean commanate = false; - final int length = this.length(); - Iterator keys = this.keys(); - writer.write('{'); - - if (length == 1) { - Object key = keys.next(); - writer.write(quote(key.toString())); - writer.write(':'); - if (indentFactor > 0) { - writer.write(' '); - } - writeValue(writer, this.map.get(key), indentFactor, indent); - } else if (length != 0) { - final int newindent = indent + indentFactor; - while (keys.hasNext()) { - Object key = keys.next(); - if (commanate) { - writer.write(','); - } - if (indentFactor > 0) { - writer.write('\n'); - } - indent(writer, newindent); - writer.write(quote(key.toString())); - writer.write(':'); - if (indentFactor > 0) { - writer.write(' '); - } - writeValue(writer, this.map.get(key), indentFactor, - newindent); - commanate = true; - } - if (indentFactor > 0) { - writer.write('\n'); - } - indent(writer, indent); - } - writer.write('}'); - return writer; - } catch (IOException exception) { - throw new JSONException(exception); - } - } + + /** + * JSONObject.NULL is equivalent to the value that JavaScript calls null, + * whilst Java's null is equivalent to the value that JavaScript calls + * undefined. + */ + private static final class Null { + + /** + * There is only intended to be a single instance of the NULL object, + * so the clone method returns itself. + * @return NULL. + */ + protected final Object clone() { + return this; + } + + /** + * A Null object is equal to the null value and to itself. + * @param object An object to test for nullness. + * @return true if the object parameter is the JSONObject.NULL object + * or null. + */ + public boolean equals(Object object) { + return object == null || object == this; + } + + /** + * Get the "null" string value. + * @return The string "null". + */ + public String toString() { + return "null"; + } + } + + + /** + * The map where the JSONObject's properties are kept. + */ + private Map map; + + + /** + * It is sometimes more convenient and less ambiguous to have a + * NULL object than to use Java's null value. + * JSONObject.NULL.equals(null) returns true. + * JSONObject.NULL.toString() returns "null". + */ + public static final Object NULL = new Null(); + + + /** + * Construct an empty JSONObject with optionally sorted keys. + * @param sortedEntries Whether the toString method should output using sorted keys. + */ + public JSONObject(boolean sortedEntries) { + if(sortedEntries){ + this.map = new TreeMap(); + } else { + this.map = new LinkedHashMap(); + } + } + + /** + * Construct an empty JSONObject. + */ + public JSONObject(){ + this(false); + } + + + /** + * Construct a JSONObject from a subset of another JSONObject. + * An array of strings is used to identify the keys that should be copied. + * Missing keys are ignored. + * @param jo A JSONObject. + * @param names An array of strings. + * @throws JSONException + * @exception JSONException If a value is a non-finite number or if a name is duplicated. + */ + public JSONObject(JSONObject jo, String[] names) { + this(); + for (int i = 0; i < names.length; i += 1) { + try { + this.putOnce(names[i], jo.opt(names[i])); + } catch (Exception ignore) { + } + } + } + + + /** + * Construct a JSONObject from a JSONTokener. + * @param x A JSONTokener object containing the source string. + * @throws JSONException If there is a syntax error in the source string + * or a duplicated key. + */ + public JSONObject(JSONTokener x) throws JSONException { + this(); + char c; + String key; + + if (x.nextClean() != '{') { + throw x.syntaxError("A JSONObject text must begin with '{'"); + } + for (;;) { + c = x.nextClean(); + switch (c) { + case 0: + throw x.syntaxError("A JSONObject text must end with '}'"); + case '}': + return; + default: + x.back(); + key = x.nextValue().toString(); + } + + // The key is followed by ':'. We will also tolerate '=' or '=>'. + + c = x.nextClean(); + if (c == '=') { + if (x.next() != '>') { + x.back(); + } + } else if (c != ':') { + throw x.syntaxError("Expected a ':' after a key"); + } + this.putOnce(key, x.nextValue()); + + // Pairs are separated by ','. We will also tolerate ';'. + + switch (x.nextClean()) { + case ';': + case ',': + if (x.nextClean() == '}') { + return; + } + x.back(); + break; + case '}': + return; + default: + throw x.syntaxError("Expected a ',' or '}'"); + } + } + } + + + /** + * Construct a JSONObject from a Map. + * + * @param map A map object that can be used to initialize the contents of + * the JSONObject. + * @param sortedEntries Whether the toString method should output using sorted keys. + * @throws JSONException + */ + public JSONObject(Map map, boolean sortedEntries) { + if(sortedEntries){ + this.map = new TreeMap(); + } else { + this.map = new LinkedHashMap(); + } + if (map != null) { + Iterator> i = map.entrySet().iterator(); + while (i.hasNext()) { + Entry e = i.next(); + Object value = e.getValue(); + if (value != null) { + this.map.put(e.getKey(), wrap(value)); + } + } + } + } + + /** + * Construct a JSONObject from a Map. + * + * @param map A map object that can be used to initialize the contents of + * the JSONObject. + * @throws JSONException + */ + public JSONObject(Map map){ + this(map,false); + } + + /** + * Construct a JSONObject from an Object using bean getters. + * It reflects on all of the public methods of the object. + * For each of the methods with no parameters and a name starting + * with "get" or "is" followed by an uppercase letter, + * the method is invoked, and a key and the value returned from the getter method + * are put into the new JSONObject. + * + * The key is formed by removing the "get" or "is" prefix. + * If the second remaining character is not upper case, then the first + * character is converted to lower case. + * + * For example, if an object has a method named "getName", and + * if the result of calling object.getName() is "Larry Fine", + * then the JSONObject will contain "name": "Larry Fine". + * + * @param bean An object that has getter methods that should be used + * to make a JSONObject. + */ + public JSONObject(Object bean) { + this(); + this.populateMap(bean); + } + + + /** + * Construct a JSONObject from an Object, using reflection to find the + * public members. The resulting JSONObject's keys will be the strings + * from the names array, and the values will be the field values associated + * with those keys in the object. If a key is not found or not visible, + * then it will not be copied into the new JSONObject. + * @param object An object that has fields that should be used to make a + * JSONObject. + * @param names An array of strings, the names of the fields to be obtained + * from the object. + */ + public JSONObject(Object object, String names[]) { + this(); + Class c = object.getClass(); + for (int i = 0; i < names.length; i += 1) { + String name = names[i]; + try { + this.putOpt(name, c.getField(name).get(object)); + } catch (Exception ignore) { + } + } + } + + + /** + * Construct a JSONObject from a source JSON text string. + * This is the most commonly used JSONObject constructor. + * @param source A string beginning + * with { (left brace) and ending + * with } (right brace). + * @exception JSONException If there is a syntax error in the source + * string or a duplicated key. + */ + public JSONObject(String source) throws JSONException { + this(new JSONTokener(source)); + } + + + /** + * Construct a JSONObject from a ResourceBundle. + * @param baseName The ResourceBundle base name. + * @param locale The Locale to load the ResourceBundle for. + * @throws JSONException If any JSONExceptions are detected. + */ + public JSONObject(String baseName, Locale locale) throws JSONException { + this(); + ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, + Thread.currentThread().getContextClassLoader()); + + // Iterate through the keys in the bundle. + + Enumeration keys = bundle.getKeys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + if (key instanceof String) { + + // Go through the path, ensuring that there is a nested JSONObject for each + // segment except the last. Add the value using the last segment's name into + // the deepest nested JSONObject. + + String[] path = ((String)key).split("\\."); + int last = path.length - 1; + JSONObject target = this; + for (int i = 0; i < last; i += 1) { + String segment = path[i]; + JSONObject nextTarget = target.optJSONObject(segment); + if (nextTarget == null) { + nextTarget = new JSONObject(); + target.put(segment, nextTarget); + } + target = nextTarget; + } + target.put(path[last], bundle.getString((String)key)); + } + } + } + + + /** + * Accumulate values under a key. It is similar to the put method except + * that if there is already an object stored under the key then a + * JSONArray is stored under the key to hold all of the accumulated values. + * If there is already a JSONArray, then the new value is appended to it. + * In contrast, the put method replaces the previous value. + * + * If only one value is accumulated that is not a JSONArray, then the + * result will be the same as using put. But if multiple values are + * accumulated, then the result will be like append. + * @param key A key string. + * @param value An object to be accumulated under the key. + * @return this. + * @throws JSONException If the value is an invalid number + * or if the key is null. + */ + public JSONObject accumulate( + String key, + Object value + ) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, value instanceof JSONArray + ? new JSONArray().put(value) + : value); + } else if (object instanceof JSONArray) { + ((JSONArray)object).put(value); + } else { + this.put(key, new JSONArray().put(object).put(value)); + } + return this; + } + + + /** + * Append values to the array under a key. If the key does not exist in the + * JSONObject, then the key is put in the JSONObject with its value being a + * JSONArray containing the value parameter. If the key was already + * associated with a JSONArray, then the value parameter is appended to it. + * @param key A key string. + * @param value An object to be accumulated under the key. + * @return this. + * @throws JSONException If the key is null or if the current value + * associated with the key is not a JSONArray. + */ + public JSONObject append(String key, Object value) throws JSONException { + testValidity(value); + Object object = this.opt(key); + if (object == null) { + this.put(key, new JSONArray().put(value)); + } else if (object instanceof JSONArray) { + this.put(key, ((JSONArray)object).put(value)); + } else { + throw new JSONException("JSONObject[" + key + + "] is not a JSONArray."); + } + return this; + } + + + /** + * Produce a string from a double. The string "null" will be returned if + * the number is not finite. + * @param d A double. + * @return A String. + */ + public static String doubleToString(double d) { + if (Double.isInfinite(d) || Double.isNaN(d)) { + return "null"; + } + + // Shave off trailing zeros and decimal point, if possible. + + String string = Double.toString(d); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && + string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + + /** + * Get the value object associated with a key. + * + * @param key A key string. + * @return The object associated with the key. + * @throws JSONException if the key is not found. + */ + public Object get(String key) throws JSONException { + if (key == null) { + throw new JSONException("Null key."); + } + Object object = this.opt(key); + return object; + } + + + /** + * Get the boolean value associated with a key. + * + * @param key A key string. + * @return The truth. + * @throws JSONException + * if the value is not a Boolean or the String "true" or "false". + */ + public Boolean getBoolean(String key) throws JSONException { + Object object = this.get(key); + if(object!=null){ + if (object.equals(Boolean.FALSE) || + (object instanceof String && + ((String)object).equalsIgnoreCase("false"))) { + return false; + } else if (object.equals(Boolean.TRUE) || + (object instanceof String && + ((String)object).equalsIgnoreCase("true"))) { + return true; + } + } + return null; + } + + + /** + * Get the double value associated with a key. + * @param key A key string. + * @return The numeric value. + * @throws JSONException if the key is not found or + * if the value is not a Number object and cannot be converted to a number. + */ + public Double getDouble(String key) throws JSONException { + Object object = this.get(key); + if(object!=null){ + try { + return object instanceof Number + ? ((Number)object).doubleValue() + : Double.parseDouble((String)object); + } catch (Exception e) { + return null; + } + } + return null; + } + + + /** + * Get the int value associated with a key. + * + * @param key A key string. + * @return The integer value. + * @throws JSONException if the key is not found or if the value cannot + * be converted to an integer. + */ + public Integer getInt(String key) throws JSONException { + Object object = this.get(key); + if(object!=null){ + try { + return object instanceof Number + ? ((Number)object).intValue() + : Integer.parseInt((String)object); + } catch (Exception e) { + return null; + } + } + return null; + } + + + /** + * Get the JSONArray value associated with a key. + * + * @param key A key string. + * @return A JSONArray which is the value. + * @throws JSONException if the key is not found or + * if the value is not a JSONArray. + */ + public JSONArray getJSONArray(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONArray) { + return (JSONArray)object; + } + return null; + } + + + /** + * Get the JSONObject value associated with a key. + * + * @param key A key string. + * @return A JSONObject which is the value. + * @throws JSONException if the key is not found or + * if the value is not a JSONObject. + */ + public JSONObject getJSONObject(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof JSONObject) { + return (JSONObject)object; + } + return null; + } + + + /** + * Get the long value associated with a key. + * + * @param key A key string. + * @return The long value. + * @throws JSONException if the key is not found or if the value cannot + * be converted to a long. + */ + public Long getLong(String key) throws JSONException { + Object object = this.get(key); + if(object!=null){ + try { + return object instanceof Number + ? ((Number)object).longValue() + : Long.parseLong((String)object); + } catch (Exception e) { + return null; + } + } + return null; + } + + + /** + * Get an array of field names from a JSONObject. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(JSONObject jo) { + int length = jo.length(); + if (length == 0) { + return null; + } + Iterator iterator = jo.keys(); + String[] names = new String[length]; + int i = 0; + while (iterator.hasNext()) { + names[i] = (String)iterator.next(); + i += 1; + } + return names; + } + + + /** + * Get an array of field names from an Object. + * + * @return An array of field names, or null if there are no names. + */ + public static String[] getNames(Object object) { + if (object == null) { + return null; + } + Class klass = object.getClass(); + Field[] fields = klass.getFields(); + int length = fields.length; + if (length == 0) { + return null; + } + String[] names = new String[length]; + for (int i = 0; i < length; i += 1) { + names[i] = fields[i].getName(); + } + return names; + } + + + /** + * Get the string associated with a key. + * + * @param key A key string. + * @return A string which is the value. + * @throws JSONException if there is no string value for the key. + */ + public String getString(String key) throws JSONException { + Object object = this.get(key); + if (object instanceof String) { + return (String)object; + } + return null; + } + + + /** + * Determine if the JSONObject contains a specific key. + * @param key A key string. + * @return true if the key exists in the JSONObject. + */ + public boolean has(String key) { + return this.map.containsKey(key); + } + + + /** + * Increment a property of a JSONObject. If there is no such property, + * create one with a value of 1. If there is such a property, and if + * it is an Integer, Long, Double, or Float, then add one to it. + * @param key A key string. + * @return this. + * @throws JSONException If there is already a property with this name + * that is not an Integer, Long, Double, or Float. + */ + public JSONObject increment(String key) throws JSONException { + Object value = this.opt(key); + if (value == null) { + this.put(key, 1); + } else if (value instanceof Integer) { + this.put(key, ((Integer)value).intValue() + 1); + } else if (value instanceof Long) { + this.put(key, ((Long)value).longValue() + 1); + } else if (value instanceof Double) { + this.put(key, ((Double)value).doubleValue() + 1); + } else if (value instanceof Float) { + this.put(key, ((Float)value).floatValue() + 1); + } else { + throw new JSONException("Unable to increment [" + quote(key) + "]."); + } + return this; + } + + + /** + * Determine if the value associated with the key is null or if there is + * no value. + * @param key A key string. + * @return true if there is no value associated with the key or if + * the value is the JSONObject.NULL object. + */ + public boolean isNull(String key) { + return JSONObject.NULL.equals(this.opt(key)); + } + + + /** + * Get an enumeration of the keys of the JSONObject. + * + * @return An iterator of the keys. + */ + public Iterator keys() { + return this.keySet().iterator(); + } + + /** + * Get an enumeration of the keys of the JSONObject. + * + * @return An iterator of the keys. + */ + public Set> entries() { + return this.map.entrySet(); + } + + + /** + * Get a set of keys of the JSONObject. + * + * @return A keySet. + */ + public Set keySet() { + return this.map.keySet(); + } + + + /** + * Get the number of keys stored in the JSONObject. + * + * @return The number of keys in the JSONObject. + */ + public int length() { + return this.map.size(); + } + + + /** + * Produce a JSONArray containing the names of the elements of this + * JSONObject. + * @return A JSONArray containing the key strings, or null if the JSONObject + * is empty. + */ + public JSONArray names() { + JSONArray ja = new JSONArray(); + Iterator keys = this.keys(); + while (keys.hasNext()) { + ja.put(keys.next()); + } + return ja.length() == 0 ? null : ja; + } + + /** + * Produce a string from a Number. + * @param number A Number + * @return A String. + * @throws JSONException If n is a non-finite number. + */ + public static String numberToString(Number number) + throws JSONException { + if (number == null) { + throw new JSONException("Null pointer"); + } + testValidity(number); + + // Shave off trailing zeros and decimal point, if possible. + + String string = number.toString(); + if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && + string.indexOf('E') < 0) { + while (string.endsWith("0")) { + string = string.substring(0, string.length() - 1); + } + if (string.endsWith(".")) { + string = string.substring(0, string.length() - 1); + } + } + return string; + } + + + /** + * Get an optional value associated with a key. + * @param key A key string. + * @return An object which is the value, or null if there is no value. + */ + public Object opt(String key) { + return key == null ? null : this.map.get(key); + } + + + /** + * Get an optional boolean associated with a key. + * It returns false if there is no such key, or if the value is not + * Boolean.TRUE or the String "true". + * + * @param key A key string. + * @return The truth. + */ + public boolean optBoolean(String key) { + return this.optBoolean(key, false); + } + + + /** + * Get an optional boolean associated with a key. + * It returns the defaultValue if there is no such key, or if it is not + * a Boolean or the String "true" or "false" (case insensitive). + * + * @param key A key string. + * @param defaultValue The default. + * @return The truth. + */ + public boolean optBoolean(String key, boolean defaultValue) { + try { + return this.getBoolean(key); + } catch (Exception e) { + return defaultValue; + } + } + + + /** + * Get an optional double associated with a key, + * or NaN if there is no such key or if its value is not a number. + * If the value is a string, an attempt will be made to evaluate it as + * a number. + * + * @param key A string which is the key. + * @return An object which is the value. + */ + public double optDouble(String key) { + return this.optDouble(key, Double.NaN); + } + + + /** + * Get an optional double associated with a key, or the + * defaultValue if there is no such key or if its value is not a number. + * If the value is a string, an attempt will be made to evaluate it as + * a number. + * + * @param key A key string. + * @param defaultValue The default. + * @return An object which is the value. + */ + public double optDouble(String key, double defaultValue) { + try { + return this.getDouble(key); + } catch (Exception e) { + return defaultValue; + } + } + + + /** + * Get an optional int value associated with a key, + * or zero if there is no such key or if the value is not a number. + * If the value is a string, an attempt will be made to evaluate it as + * a number. + * + * @param key A key string. + * @return An object which is the value. + */ + public int optInt(String key) { + return this.optInt(key, 0); + } + + + /** + * Get an optional int value associated with a key, + * or the default if there is no such key or if the value is not a number. + * If the value is a string, an attempt will be made to evaluate it as + * a number. + * + * @param key A key string. + * @param defaultValue The default. + * @return An object which is the value. + */ + public int optInt(String key, int defaultValue) { + try { + return this.getInt(key); + } catch (Exception e) { + return defaultValue; + } + } + + + /** + * Get an optional JSONArray associated with a key. + * It returns null if there is no such key, or if its value is not a + * JSONArray. + * + * @param key A key string. + * @return A JSONArray which is the value. + */ + public JSONArray optJSONArray(String key) { + Object o = this.opt(key); + return o instanceof JSONArray ? (JSONArray)o : null; + } + + + /** + * Get an optional JSONObject associated with a key. + * It returns null if there is no such key, or if its value is not a + * JSONObject. + * + * @param key A key string. + * @return A JSONObject which is the value. + */ + public JSONObject optJSONObject(String key) { + Object object = this.opt(key); + return object instanceof JSONObject ? (JSONObject)object : null; + } + + + /** + * Get an optional long value associated with a key, + * or zero if there is no such key or if the value is not a number. + * If the value is a string, an attempt will be made to evaluate it as + * a number. + * + * @param key A key string. + * @return An object which is the value. + */ + public long optLong(String key) { + return this.optLong(key, 0); + } + + + /** + * Get an optional long value associated with a key, + * or the default if there is no such key or if the value is not a number. + * If the value is a string, an attempt will be made to evaluate it as + * a number. + * + * @param key A key string. + * @param defaultValue The default. + * @return An object which is the value. + */ + public long optLong(String key, long defaultValue) { + try { + return this.getLong(key); + } catch (Exception e) { + return defaultValue; + } + } + + + /** + * Get an optional string associated with a key. + * It returns an empty string if there is no such key. If the value is not + * a string and is not null, then it is converted to a string. + * + * @param key A key string. + * @return A string which is the value. + */ + public String optString(String key) { + return this.optString(key, ""); + } + + + /** + * Get an optional string associated with a key. + * It returns the defaultValue if there is no such key. + * + * @param key A key string. + * @param defaultValue The default. + * @return A string which is the value. + */ + public String optString(String key, String defaultValue) { + Object object = this.opt(key); + return NULL.equals(object) ? defaultValue : object.toString(); + } + + + private void populateMap(Object bean) { + Class klass = bean.getClass(); + + // If klass is a System class then set includeSuperClass to false. + + boolean includeSuperClass = klass.getClassLoader() != null; + + Method[] methods = includeSuperClass + ? klass.getMethods() + : klass.getDeclaredMethods(); + for (int i = 0; i < methods.length; i += 1) { + try { + Method method = methods[i]; + if (Modifier.isPublic(method.getModifiers())) { + String name = method.getName(); + String key = ""; + if (name.startsWith("get")) { + if ("getClass".equals(name) || + "getDeclaringClass".equals(name)) { + key = ""; + } else { + key = name.substring(3); + } + } else if (name.startsWith("is")) { + key = name.substring(2); + } + if (key.length() > 0 && + Character.isUpperCase(key.charAt(0)) && + method.getParameterTypes().length == 0) { + if (key.length() == 1) { + key = key.toLowerCase(); + } else if (!Character.isUpperCase(key.charAt(1))) { + key = key.substring(0, 1).toLowerCase() + + key.substring(1); + } + + Object result = method.invoke(bean, (Object[])null); + if (result != null) { + this.map.put(key, wrap(result)); + } + } + } + } catch (Exception ignore) { + } + } + } + + + /** + * Put a key/boolean pair in the JSONObject. + * + * @param key A key string. + * @param value A boolean which is the value. + * @return this. + * @throws JSONException If the key is null. + */ + public JSONObject put(String key, boolean value) throws JSONException { + this.put(key, value ? Boolean.TRUE : Boolean.FALSE); + return this; + } + + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONArray which is produced from a Collection. + * @param key A key string. + * @param value A Collection value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Collection value) throws JSONException { + this.put(key, new JSONArray(value)); + return this; + } + + + /** + * Put a key/double pair in the JSONObject. + * + * @param key A key string. + * @param value A double which is the value. + * @return this. + * @throws JSONException If the key is null or if the number is invalid. + */ + public JSONObject put(String key, double value) throws JSONException { + this.put(key, new Double(value)); + return this; + } + + + /** + * Put a key/int pair in the JSONObject. + * + * @param key A key string. + * @param value An int which is the value. + * @return this. + * @throws JSONException If the key is null. + */ + public JSONObject put(String key, int value) throws JSONException { + this.put(key, new Integer(value)); + return this; + } + + + /** + * Put a key/long pair in the JSONObject. + * + * @param key A key string. + * @param value A long which is the value. + * @return this. + * @throws JSONException If the key is null. + */ + public JSONObject put(String key, long value) throws JSONException { + this.put(key, new Long(value)); + return this; + } + + + /** + * Put a key/value pair in the JSONObject, where the value will be a + * JSONObject which is produced from a Map. + * @param key A key string. + * @param value A Map value. + * @return this. + * @throws JSONException + */ + public JSONObject put(String key, Map value) throws JSONException { + this.put(key, new JSONObject(value)); + return this; + } + + /** + * Put all keys and values from another JSONObject into this JSONObject. + * @param other A JSONObject. + * @return this. + */ + public JSONObject put(JSONObject other){ + this.map.putAll(other.map); + return this; + } + + /** + * Use the map of the other JSONObject. Effectively becoming it. + * @param other A JSONObject. + * @return this. + */ + public JSONObject useMapOf(JSONObject other){ + this.map = other.map; + return this; + } + + + /** + * Put a key/value pair in the JSONObject. If the value is null, + * then the key will be removed from the JSONObject if it is present. + * @param key A key string. + * @param value An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, + * or the JSONObject.NULL object. + * @return this. + * @throws JSONException If the value is non-finite number + * or if the key is null. + */ + public JSONObject put(String key, Object value) throws JSONException { + if (key == null) { + throw new JSONException("Null key."); + } + if (value != null) { + testValidity(value); + this.map.put(key, value); + } else { + this.remove(key); + } + return this; + } + + + /** + * Put a key/value pair in the JSONObject, but only if the key and the + * value are both non-null, and only if there is not already a member + * with that name. + * @param key + * @param value + * @return his. + * @throws JSONException if the key is a duplicate + */ + public JSONObject putOnce(String key, Object value) throws JSONException { + if (key != null && value != null) { + if (this.opt(key) != null) { + throw new JSONException("Duplicate key \"" + key + "\""); + } + this.put(key, value); + } + return this; + } + + + /** + * Put a key/value pair in the JSONObject, but only if the + * key and the value are both non-null. + * @param key A key string. + * @param value An object which is the value. It should be of one of these + * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, + * or the JSONObject.NULL object. + * @return this. + * @throws JSONException If the value is a non-finite number. + */ + public JSONObject putOpt(String key, Object value) throws JSONException { + if (key != null && value != null) { + this.put(key, value); + } + return this; + } + + + /** + * Produce a string in double quotes with backslash sequences in all the + * right places. A backslash will be inserted within = '\u0080' && c < '\u00a0') + || (c >= '\u2000' && c < '\u2100')) { + w.write("\\u"); + hhhh = Integer.toHexString(c); + w.write("0000", 0, 4 - hhhh.length()); + w.write(hhhh); + } else { + w.write(c); + } + } + } + w.write('"'); + return w; + } + + /** + * Remove a name and its value, if present. + * @param key The name to be removed. + * @return The value that was associated with the name, + * or null if there was no value. + */ + public Object remove(String key) { + return this.map.remove(key); + } + + /** + * Try to convert a string into a number, boolean, or null. If the string + * can't be converted, return the string. + * @param string A String. + * @return A simple JSON value. + */ + public static Object stringToValue(String string) { + Double d; + if (string.equals("")) { + return string; + } + if (string.equalsIgnoreCase("true")) { + return Boolean.TRUE; + } + if (string.equalsIgnoreCase("false")) { + return Boolean.FALSE; + } + if (string.equalsIgnoreCase("null")) { + return JSONObject.NULL; + } + + /* + * If it might be a number, try converting it. + * If a number cannot be produced, then the value will just + * be a string. Note that the plus and implied string + * conventions are non-standard. A JSON parser may accept + * non-JSON forms as long as it accepts all correct JSON forms. + */ + + char b = string.charAt(0); + if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { + try { + if (string.indexOf('.') > -1 || + string.indexOf('e') > -1 || string.indexOf('E') > -1) { + d = Double.valueOf(string); + if (!d.isInfinite() && !d.isNaN()) { + return d; + } + } else { + Long myLong = new Long(string); + if (myLong.longValue() == myLong.intValue()) { + return new Integer(myLong.intValue()); + } else { + return myLong; + } + } + } catch (Exception ignore) { + } + } + return string; + } + + + /** + * Throw an exception if the object is a NaN or infinite number. + * @param o The object to test. + * @throws JSONException If o is a non-finite number. + */ + public static void testValidity(Object o) throws JSONException { + if (o != null) { + if (o instanceof Double) { + if (((Double)o).isInfinite() || ((Double)o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } else if (o instanceof Float) { + if (((Float)o).isInfinite() || ((Float)o).isNaN()) { + throw new JSONException( + "JSON does not allow non-finite numbers."); + } + } + } + } + + + /** + * Produce a JSONArray containing the values of the members of this + * JSONObject. + * @param names A JSONArray containing a list of key strings. This + * determines the sequence of the values in the result. + * @return A JSONArray of values. + * @throws JSONException If any of the values are non-finite numbers. + */ + public JSONArray toJSONArray(JSONArray names) throws JSONException { + if (names == null || names.length() == 0) { + return null; + } + JSONArray ja = new JSONArray(); + for (int i = 0; i < names.length(); i += 1) { + ja.put(this.opt(names.getString(i))); + } + return ja; + } + + /** + * Make a JSON text of this JSONObject. For compactness, no whitespace + * is added. If this would not result in a syntactically correct JSON text, + * then null will be returned instead. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @return a printable, displayable, portable, transmittable + * representation of the object, beginning + * with { (left brace) and ending + * with } (right brace). + */ + public String toString() { + try { + return this.toString(0); + } catch (Exception e) { + return null; + } + } + + + /** + * Make a prettyprinted JSON text of this JSONObject. + *

    + * Warning: This method assumes that the data structure is acyclical. + * @param indentFactor The number of spaces to add to each level of + * indentation. + * @return a printable, displayable, portable, transmittable + * representation of the object, beginning + * with { (left brace) and ending + * with } (right brace). + * @throws JSONException If the object contains an invalid number. + */ + public String toString(int indentFactor) throws JSONException { + StringWriter w = new StringWriter(); + synchronized (w.getBuffer()) { + return this.write(w, indentFactor, 0).toString(); + } + } + + /** + * Make a JSON text of an Object value. If the object has an + * value.toJSONString() method, then that method will be used to produce + * the JSON text. The method is required to produce a strictly + * conforming text. If the object does not contain a toJSONString + * method (which is the most common case), then a text will be + * produced by other means. If the value is an array or Collection, + * then a JSONArray will be made from it and its toJSONString method + * will be called. If the value is a MAP, then a JSONObject will be made + * from it and its toJSONString method will be called. Otherwise, the + * value's toString method will be called, and the result will be quoted. + * + *

    + * Warning: This method assumes that the data structure is acyclical. + * @param value The value to be serialized. + * @return a printable, displayable, transmittable + * representation of the object, beginning + * with { (left brace) and ending + * with } (right brace). + * @throws JSONException If the value is or contains an invalid number. + */ + public static String valueToString(Object value) throws JSONException { + if (value == null || value.equals(null)) { + return "null"; + } + if (value instanceof JSONString) { + Object object; + try { + object = ((JSONString)value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + if (object instanceof String) { + return (String)object; + } + throw new JSONException("Bad value from toJSONString: " + object); + } + if (value instanceof Number) { + return numberToString((Number) value); + } + if (value instanceof Boolean || value instanceof JSONObject || + value instanceof JSONArray) { + return value.toString(); + } + if (value instanceof Map) { + return new JSONObject((Map)value).toString(); + } + if (value instanceof Collection) { + return new JSONArray((Collection)value).toString(); + } + if (value.getClass().isArray()) { + return new JSONArray(value).toString(); + } + if (value instanceof RawJSON) { + return value.toString(); + } + return quote(value.toString()); + } + + /** + * Wrap an object, if necessary. If the object is null, return the NULL + * object. If it is an array or collection, wrap it in a JSONArray. If + * it is a map, wrap it in a JSONObject. If it is a standard property + * (Double, String, et al) then it is already wrapped. Otherwise, if it + * comes from one of the java packages, turn it into a string. And if + * it doesn't, try to wrap it in a JSONObject. If the wrapping fails, + * then null is returned. + * + * @param object The object to wrap + * @return The wrapped value + */ + public static Object wrap(Object object) { + try { + if (object == null) { + return NULL; + } + if (object instanceof JSONObject || object instanceof JSONArray || + NULL.equals(object) || object instanceof JSONString || + object instanceof Byte || object instanceof Character || + object instanceof Short || object instanceof Integer || + object instanceof Long || object instanceof Boolean || + object instanceof Float || object instanceof Double || + object instanceof String) { + return object; + } + + if (object instanceof Collection) { + return new JSONArray((Collection)object); + } + if (object.getClass().isArray()) { + return new JSONArray(object); + } + if (object instanceof Map) { + return new JSONObject((Map)object); + } + Package objectPackage = object.getClass().getPackage(); + String objectPackageName = objectPackage != null + ? objectPackage.getName() + : ""; + if ( + objectPackageName.startsWith("java.") || + objectPackageName.startsWith("javax.") || + object.getClass().getClassLoader() == null + ) { + return object.toString(); + } + return new JSONObject(object); + } catch(Exception exception) { + return null; + } + } + + + /** + * Write the contents of the JSONObject as JSON text to a writer. + * For compactness, no whitespace is added. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + public Writer write(Writer writer) throws JSONException { + return this.write(writer, 0, 0); + } + + + static final Writer writeValue(Writer writer, Object value, + int indentFactor, int indent) throws JSONException, IOException { + if (value == null || value.equals(null)) { + writer.write("null"); + } else if (value instanceof JSONObject) { + ((JSONObject) value).write(writer, indentFactor, indent); + } else if (value instanceof JSONArray) { + ((JSONArray) value).write(writer, indentFactor, indent); + } else if (value instanceof Map) { + new JSONObject((Map) value).write(writer, indentFactor, indent); + } else if (value instanceof Collection) { + new JSONArray((Collection) value).write(writer, indentFactor, + indent); + } else if (value.getClass().isArray()) { + new JSONArray(value).write(writer, indentFactor, indent); + } else if (value instanceof Number) { + writer.write(numberToString((Number) value)); + } else if (value instanceof Boolean) { + writer.write(value.toString()); + } else if (value instanceof RawJSON) { + writer.write(value.toString()); + } else if (value instanceof JSONString) { + Object o; + try { + o = ((JSONString) value).toJSONString(); + } catch (Exception e) { + throw new JSONException(e); + } + writer.write(o != null ? o.toString() : quote(value.toString())); + } else { + quote(value.toString(), writer); + } + return writer; + } + + static final void indent(Writer writer, int indent) throws IOException { + for (int i = 0; i < indent; i += 1) { + writer.write(' '); + } + } + + /** + * Write the contents of the JSONObject as JSON text to a writer. For + * compactness, no whitespace is added. + *

    + * Warning: This method assumes that the data structure is acyclical. + * + * @return The writer. + * @throws JSONException + */ + Writer write(Writer writer, int indentFactor, int indent) + throws JSONException { + try { + boolean commanate = false; + final int length = this.length(); + Iterator> entries = this.map.entrySet().iterator(); + writer.write('{'); + + + + if (length == 1) { + Entry entry = entries.next(); + writer.write(quote(entry.getKey().toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, entry.getValue(), indentFactor, indent); + } else if (length != 0) { + final int newindent = indent + indentFactor; + while (entries.hasNext()) { + Entry entry = entries.next(); + if (commanate) { + writer.write(','); + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, newindent); + writer.write(quote(entry.getKey().toString())); + writer.write(':'); + if (indentFactor > 0) { + writer.write(' '); + } + writeValue(writer, entry.getValue(), indentFactor, + newindent); + commanate = true; + } + if (indentFactor > 0) { + writer.write('\n'); + } + indent(writer, indent); + } + writer.write('}'); + return writer; + } catch (IOException exception) { + throw new JSONException(exception); + } + } } diff --git a/None.java b/None.java new file mode 100644 index 000000000..1dda8bc69 --- /dev/null +++ b/None.java @@ -0,0 +1,9 @@ +package org.json; + +public interface None { + /** + * Negative One + */ + public static final int none = -1; + +} diff --git a/RawJSON.java b/RawJSON.java new file mode 100644 index 000000000..f9848ed23 --- /dev/null +++ b/RawJSON.java @@ -0,0 +1,31 @@ +package org.json; + +/** + * Used to hold a known valid JSON string in a JSON structure + * without the overhead of parsing it first. + * @author Marcus Longmuir + * @version 2013-03-01 + */ +public class RawJSON { + + String rawJSON = null; + + public RawJSON(String string){ + this.rawJSON = string; + } + + public void setString(String toSet){ + this.rawJSON = toSet; + } + + public void useContentFrom(RawJSON other){ + this.rawJSON = other.rawJSON; + } + public void cloneJSONObject(JSONObject obj){ + this.rawJSON = obj.toString(); + } + + public String toString(){ + return this.rawJSON; + } +} \ No newline at end of file diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 000000000..3a00a4770 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,6 @@ +/build +/jar +/.gradle +/.classpath +/.DS_Store +/.project diff --git a/bin/.settings/org.eclipse.jdt.core.prefs b/bin/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..4b6f4c10e --- /dev/null +++ b/bin/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,13 @@ +# +#Thu Aug 01 20:22:57 BST 2013 +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error diff --git a/bin/CDL.class b/bin/CDL.class new file mode 100644 index 0000000000000000000000000000000000000000..276fc6cbdf6714fbb5c06673caa8cc3b5c2a78f6 GIT binary patch literal 1505 zcmbW0-)<5?6vn?nD9b`ii`GB&Pq)}s+KV8O7B`PnQCJf9Mkii1Oa>bsQsRhdQ+f{A0XuG~R81|Y%)j9QNDB05CUV|%F@BbgB zgN{33$k-G^mBDC>puxQ%$=53OtJ>i~T^ literal 0 HcmV?d00001 diff --git a/bin/Cookie.class b/bin/Cookie.class new file mode 100644 index 0000000000000000000000000000000000000000..0b03f51da1b021d33074ab366f44c4a6c1033a94 GIT binary patch literal 876 zcmbV~%}yIJ6orpNN+v@fG%bJS&&i?!7DTGLDis?9iz))401`{bu@Z-gJ@PmaPr|Dp zwG!-kDAYTokRT!zSlBc7`rOaw-kH1m-!}lhp`1g8VRFyf3$1dU$w)ZT#6n((mf{ubTHBq(nhI}Pm2hJ{?+P#5+>=~g#^hyGUI{}4m@eQ0 zW*Fu+YC|)1@3d*{q-KjXZPa0}+feRA(ESXhnw26t6Hce`zhu_8b;1zT29wyKrd1+E zO!}|m$S*GoFwao_Z|@8RZ-3Q~4j+fh$Kr>A-fllW#HE4Z19V5!1uT6glXu6EnB<(qhzEhUbGyH?#ycAxe za7$4JMcPvhXwA}I7^v_OC5rO+gwK>o30uzyb7KhA2SVndZUKu#U!wOc)qi;<;dq3w Xg4K5r`Xhw3H+a8#s$*Cu*BS7?*G{-N literal 0 HcmV?d00001 diff --git a/bin/CookieList.class b/bin/CookieList.class new file mode 100644 index 0000000000000000000000000000000000000000..fe7cf18de67b81b8ab22a2a8b11a9b6874e46826 GIT binary patch literal 715 zcmbVJO-sW-6r8Qqq_JA9-=C~KsRu>zq~b+Xkf4XE;BlKS?bb9KHrwJq6BP9Bj}l+v zM-&CYLmoSCCo}KOKEK>Q0@%i~g93whsP&DKzDlfvBEwim^u=Z$Fto2C zWe*qzR@bf=iif%>9h4X1NP7F(b1}!T@@GB_uGMclFp%jNhqa$ul4)J{OdyX{x?UyU zU?WWgE1-v?2M1L~VGU7r2<>DT@E+h^SG_xwpQu|vg=)$HePdM1+1bN5s)S0Iz$CGz k=v<_m=}c?=o7U_vT3eY`Ayb&g!ao#FJ{1@iNvD9NS5lavi~s-t literal 0 HcmV?d00001 diff --git a/bin/HTTP.class b/bin/HTTP.class new file mode 100644 index 0000000000000000000000000000000000000000..72ffdc8980eb1cf675c339deb4bf35484019cf66 GIT binary patch literal 765 zcmbV~%TC)s6o&tCQ|y?ep`lQEAJPqU0TSv8DmI9VDhsM6jnw7D86}fCGuC*5*zs6M ztps}>3iXVkgbJie-5k%kedp%OtDolpHt;?~z)(5pbiRbBFwBj_u~^T99;_erMlyBe z-1(a9F*K8@tL?1PgDr;oj?sk^+I2-XkrAp4K|N-e`J}XR+YFCZR=XZy`ZB~5hQ<`K zYpt;n<`~pBZDnDyW7+4a8Rse!P8rQ}YkHX+Z}Pa>8A{%lX(lYiS)#wW1eAQ<^Dvz*+!zYJe-Vs(sl&Z_oJIs zWL;sE*Kdp!H&g{pn)uz(Dr(MrZXX@~*&2U{o=hVsBi=npW$q^}LcFGBdhe|*!dr&r ze{O~$a_0IT3{><^h1L7>QPH-U*i`N*KUmfGzUEJYWzezcmtc5-$C#mSNLql1tdxaW zk~Ok?EOj9Mh5Gkq;|xzP%D87FeU>LIkgS#O7>jsLS`|yg4e*lQ74p0)Ss(sly?KDO WU$TOd@DBVx2&cCM+9q)Vw0;8&qo@f0 literal 0 HcmV?d00001 diff --git a/bin/HTTPTokener.class b/bin/HTTPTokener.class new file mode 100644 index 0000000000000000000000000000000000000000..f3d549778784a8f327c7ddc3468d5ba6d049f9c2 GIT binary patch literal 590 zcmah`O-lnY5PhlDZP)r$zx5J((o2itNyUpOB1MI+g2%WW+SF~bWTW(-2?~1mM~Sml zw4mT2lbJVfUS=k5?@uoPcCa3xATW6vMVFDiBSS7gk%6<;#rYQ?Fma%b_J;zCo6Vkj zP>n>HPNU_WHl6*gYk}gCZBu}tbkgQqPsrNE#YO-x9lg4`4S3d4a&vY836#G$nEeuh@R0ZRh z;8vR2(D{A;mRzLx9f4}o#wxj1PUrC#SoB?;2~0IdcCar{HZ<_V4G1i3ZvCEHAUqz# zl;)FU0hU-IU)ncT!ivDgzmu~}%ig<~PITVl>_`{&e3#gOz!?7(P+*TIV;gX^%V>e` z@EN6>YWRrC>yR_eHs^rP4BN`k4>60mAy&ma*DbJL E2c)ftC;$Ke literal 0 HcmV?d00001 diff --git a/bin/JSONArray.class b/bin/JSONArray.class new file mode 100644 index 0000000000000000000000000000000000000000..20eb8807f74c9708f93ed0c7e2e5c3b47bad7049 GIT binary patch literal 5139 zcmb`J!E@VG5XSe}PMoNYQ%VY?v_x@2t5Arc1PXN;XyOzc+@z2+rGXhnao#veWj&89 zhxEn_+&D4Ag%ek)A#kFsay5p+V&o=ISfuT?s@xFqlK%}RWGCM z7-lgDmlzDr8zH+H$Y!)vB)V@^}A-PP+{EeN|lyVnv{LERC&rCP#K8@f~5RUJ&{ z2TfEgrxz3j6d27x7EYpets~yEx9-@6RWG?>N2`X#SKEzkZg1%Leg>ziqNbahx^1}Y zZZPBQ8ZE3xH7FVS&Y4)2io?%7)(C0YS=){leZ!6a*NxZJ!Scz#+z<^TUmIH!HBCrh%p%Nmc{Gok}ypyA|`v! z_LQuv#w}U8&fQ_qDqXwM#Gp|HcNc{)xo+VoVA2+v$5>gkz4E%DGR_Q!Di(6wbp>mQ z>!7v_@-97CBX*>_?@#8apU@S?Ad4AQVbwdxmCjo`oj#(rI{+xdXsxzQ6Q9`=1`0k; zjfvEh!v{@n)ty~$=23oHG|`KKe*^CWT4l>Kk3ru&#>$?1jCt-c(6Nt!z%IJ&E`7II zTz9h6gL?XSWQ&qz*a4Z{3)G70CAzgMm+N!$D}FTQNfvZ@UpZ)SXTr1{h2qNphWg zSFfC=tc$i?;aOyyMN$UeaV}t` zFmhZ~_(gb(tO?ZP*C?49^|7g$gu)|ORKjG%UXR!g2 zH3KgsV2zWki|}Fs)p z{7Mo^cq-#+_#=ccFA<{a@Ha`gil;fQhJQ)I0-oWRgw!BOcneQ%T*6og;cbZ!*^AT^ zNw|h5KCXtj5W=EFi0nmbkt8fZSt1;M7m2A(t%VSlV-r3OAzUZ#nrJ_JA*|T5l{yF^ zyd(LE*6>9L;a!OkUDK~Z2$k4`Z$k(x32OR%2Yx15PeRQCM+o_fzlE_>gIsjODiEx6mbbfqKb+{(nuU#XS8wIwO3wm=|4jP z3GVzT#OxN4tyGBvmUh-Nex7;n`RA{%-vK;_Y@;Etc0751a&)OF3&z0qIK_-I^{)&PgZAGbU5|lZr_Wosaj=b7zNg?kJbm1(~X#7cwxME;G`h z4j)Dldbr<37i&yqY%HA==^6QHDMX+@cA9NbY!2stip{Vvd5OMeGOOOIi(T4L>g~i7 zMpvF~?(Wq*S;9JaBCzvM;R4ab6<*U@Q!%_oV!t#KI}ljmmug^u7FIcHS6PQE5pMH- zg=;LC;~makaNgj5^bNg_{kvaq??;8-;8@-Ue-Aizt9^t`Y*n=`9{y*C0Up&ll#{MF RJidX$vl}@)qi}(0D-U_Rum7-rUq`)1`6bWYhQ$ z{2wHc;GLhu1LCGBX(9y>eTWm=$KO3U*WZ7B{tDnJ_Dd)*tiI`;9Cxh}iVW)$aVgra z@J8*E!9?02Z9jKBCw#$ht=T$dD85odSwfkiw$L7Ft+as(gY(wYGEnZN9CBMtea97{ zqde|wHE`whkelWHSn{E?U7<& zij(LttoT9)B!Aqr&bn4#ol8&Z&ik3*rPks@rwlXeTnZ0Vv`rXa#9BE>o|FKdcF+vsRJM)#e%)~Ko z00Z$N#r$wOu|#6_)P=U?YbR<>B~o{-gQ%C-16?_~rl3AkL$FF?iDu7emC@V$0^?oX z{DkT^niWu^G17pZbsDR&3LB`?%)|}cB-JK;7is6#jP;0EQH_{&Cx`W9#ww7ejBVV_ zB`nu$q;szAhc5iPQA%X@~=6t!wjLZ1mR;sV0b_sDd6ER DYhvs7 literal 0 HcmV?d00001 diff --git a/bin/JSONObject$Null.class b/bin/JSONObject$Null.class new file mode 100644 index 0000000000000000000000000000000000000000..6b5f4aa3258960f01124aeb5e2c30cd8d19b688b GIT binary patch literal 815 zcmaiyPfr^$5XGODz%EPLKng9T|4hUoxd1{vHB~RDl|WHAgd(*!XJaK!9Xog(gw!J+ zs!}VJJ0A)$tBsT`TB!$nHTL*7@6GJp{qMg3j<6ddV5pt;&bnv)u}u74ccyiS3d8zX zT!{lM%BGh z*6^vbeJv*+c)WT(l6)W&Ega=cMe;)oC2v?a+#jdbH2A>ElpE{$MEGRHJ*CU*DakCR zH{uu(o>Z}nrwm)o&O%JjJ7tFLOl+;AjO@-Ped*2x)n}-8Y$Ei9a4L)EhZR3kDZ@tR zQA^qk%Zavz-fcEpg%Wvh+7X^J?Ecp=^-x~Ugr*Yz2%S?}-x(rrbJ>q8&CM{xJv(!W z{Gu`!h1uWs<#vcsL`I~fYv(g)jSIus8h6wXSB))TP1|c5(2{uY!?UtQF9GtgrB8^m)I!~ b7B0#NHzkAsuc&H(*LagvClB-8>8D%A=I6hUZxP?qN!#F zPAd5!2GJ=sqbX+5;0*Sb?;f%rEzFc@s9I)7TCu@HhmjGQI6XejptEw9LHLlWsper6 z>Yq)_;McI8<`L*XTRbC24MR7YVLb!&v}W*vo?YVUcuLRZ)vRKwx)#qH`dpUh4#s2A z>3JSc^Hf$bP$sXW7L^Q-_v%Jw_d-F}dgE!G7vh?3#&e39nva_(&X@BT8d1>Y}x)Kf}!Mln?J>@0@Nd9}cxb=*q>My0V| zAbR`d)pPWF*4aYS`Xbl3F(mY2qsu9t7rqxFa6f}K!FJaeY;a6=Q)xx_z^c_6Q)uaS zuF|#4D2t4fa$#P-95H9z$GM%dXjvUuwp#(^w$Dl`Rm>GJotQ87~^ z$Tn0FjP+$|Q{2SeiPdWkr8EutMp1i(Kufjl#O$y&!oz4gq8V)WAP3#qemjFGF=EU&RZKQ6ZkY=rPpj4@E$drwU zv{b%jB!L@YRJQtu)I{GX&13>MT2a$=7MsL*EHz04pY0AH$zwEmEP)$QR4tY4e!}od zSI8K))F=F6!b`+T;6D zRUbHGsMzhLa`qM?fYIMzMI9HDlhQFB#wnsNA-Jtz-LR(h86{i9=T?&!O#H2;RTD>a zi>XVM)?+(jjc>Z6hl`GQC`*L z-2!O3BI0CSjY=``iyRIBOV|lYsV=?HO7=MXWXU^ENX%$0Z4K)#Cx6~%Qe0T1Yz^qZMY9@-;A0eByG7%f3_ma zj#bc*sKVM=S;OpOvW63NvA!T!QP>3! zIuYMh)=`u--&zFGbqpSYhe?0Do}>uB5;ic{4Fh$s{w7(Ez@uwtHMEheL3peVRv*dQ z1AFUW4Uw#U@OT}pagwzk4%ERqPq3nJ5Qd~$@@6Yh2@RJmf~Xducc^B)>#iPyC*W`$ zw%;ObXK)0bbZjU;St#2-BMC?A%F1n$b!-jR{74dpVFY7ip9`bzR1eO{FC^(Wp1dW} zi5f}2k))(V8mp1?7fE^=#-(fpd-V@VI0+NA5*i}}Aqtc5OhxsH85(F!W4FZ;bS!YoesTC@2HNjQfSq*lV`B;k2DUo+urAHoX~AvhP`lY|R6 zm236lXCJ~vi4dHN-w8qkC_vvtsha$gATXGNR7H1-lOfQWP`?i=T?cEQ4~vtmz)Xck zd{~!ARQfu^o7$0G#JqVNfq0PqUDArZX)FABEd4B=4&yop`c0B^x{{O-hGZ)1$#g-vh+-iHsv G(fL*M|Ccr0Brid(ysLi}bXn&{mRW$Y%& zOgyy7dwKo$*VnJ_w+{f9IQLK?2p(qB$;=w5Vh>e<=9=x;FkvblPM2%JErCDciB!_w z5FGUS3xevcj)aFgL0G2mjM2u&5rKSEMr?Gl6A|S)&1Ax?)QVw5v@#SZ}oI(nyO9Roc>&S-zsy#l=hJX#U2#K>#1e4V)k(sEziFo!+>l z`hD4TP92V=5|eGZ6lTsG2tjMCIZGDI$XxHuhSg;y1npk`|2S9MOm7Vr_cEUomIns; y)inZFl`9#jIKo5Joc5f$*t@|y{HIp%ipFP=X}Uenz^&85$-kn7v%+Z?PUi=-fo*F5 literal 0 HcmV?d00001 diff --git a/bin/JSONStringer.class b/bin/JSONStringer.class new file mode 100644 index 0000000000000000000000000000000000000000..50213a242641b31154c00d42b662144ab09e3297 GIT binary patch literal 555 zcmah`O-}+b6r3Wk%ZeZfe%uNtxIkh&iSc6epac&f#$(xSmg4Sq(=Eh*W}=DS{ZYm) zm`DPNhraerCNuM1zrNo-0G#5)LWZDtJG>tZwGxrfm4z&UlOm5wXs!tI7a|h+l3=IR z9us7*q{l532+A|IVBLU4e)n1_sch^Lh=)k=LbfQRSQDU7C^ zdfW||GMt#X&&=nvDV5)uB{FJKPx6FDQqz!WcS^OP^Ou;rdY#^M9N5?^B8L(|z19B< zvl^wBhAsC+#0T?m!qtcwe}ZaXx-1woCDQ&E%<8E~2ul6+P4ozCEmvX$wN`u6!p0#% zsw{v?lpPl*6?6+V0UjSeU9w%Ukz{tk-)@DWQ zGR|ZIVg%AVbdMHX%Ik%#+77b<0x7FOCA9)336Ko}r>WISgaAy_IZTalkp?7@E;ZE>`z(nqE*L)T6MPai9OcEGB z%5GgsA(L>Hfb)V&<_mX^*`_6$p5xNM5#02osJX1UVj8JRgPAt7Tq@DWqt-61Gczk> zeR0PZJZsv5`6d^E*`$HhFavaFZ4axDx@QdoCSZCL(lA3{s+(#k)pj5qUSCzoj+ar3 z%~rFYXt~qv>Aep^|r-4RhgfF zSqxQ?hkK|}4eP@0MzFUiusc2F1JGp_BYlP5(|iN*2XzN zGImwD;WCvgbgX|bn{YHvEy!9_KnFbgOa zUNXF4Fbr|DhR{xiYpVNgbk`9W4fn_3bhwU(ei>e_vsplG`V)9aQ2G(bK|WGN|G0OWlL;&!L8obd)_X1M2HYHg^|1%*mX>uiH#&6> zdaxD;V13uJ3Io;nL(94icLvDorrN9v6vzM5mbR>gVi7NRTPo_}rS&d?F);-bNdq51jQDBTPTGatoy~NM_z=E= zPhn!B34S#^iVs0NyR8=L6hlAk?94f5e&_U@|EBu~-}V4Jz+46i24iV;W%;dgLZLE9 zF^p~T9bR_1UoWq0ZV5YN$a;LYCW5fRz+N+qRHWYwxgV}`w zWKGbvLS_oIx9QINYLur<15jW?vALLR9WD-JanXQ21;(a!kaUV;kAY^Yr=N9qL_fH zdrK*>s&d}xnoR)4X4SFi(A!g1P=n?*BDG4{b;PQxNFm( z=$AG#n5MQzP5*1l;s(Rie>+1{<4W<545QY}QGPNmWX!5mdK_7Dylh_@rtKf)B)0`& z(y}9@WDrd~WmVz{2CXJ3DsLTDM&uaUiF6ftHhQw;t%ZLqOFfn&UFztqC&XBlEoF;W zPBe*pSO29*Ntgo3lSG}yB!*~Z$j~W)EIq?8XrIC<MV@OK)^!cb z*RU9F!qT#$?CrXAtWO$N0yDU!Wko&f&-$!kG29-gt}j~Foqh!(w7 z1QP7|J**LT9B6_%N<}vw&-L7I&N6K){o1DVd9=e-sP})0b{d2fRIW{FYS-GVZg;$_GB)mP9Qb0W z%_Mo;U|4w7+1fm+F%osNmJ9uaL^|EE$%)`tgj&Vn>dYFJ6W^oC5i8=&7O# zLePI^!$J;o^kyNC0<8@5*=oT-k@iKZl(0b0v$T6mT{f-GSCro_o%@XQ-)U#z0zK#G zjPAck&rU{wv-{4``U zk6Q-TD&?%x9H(Spu}a3$+8J(RWh$FVx~9Grg9e5>xI0CdBw`{wG7>z43;nmuX0?p0 cI##FD%+8@>B;3P&<9ueb-WypDC}Rta-$xML#Q*>R literal 0 HcmV?d00001 diff --git a/bin/None.class b/bin/None.class new file mode 100644 index 0000000000000000000000000000000000000000..6ede91611244bab14abb7948d2fb5583640704b3 GIT binary patch literal 431 zcmYjNO-}+b6r2LWvVtIrAGd}RdVs{E5-&s(6M_ej#ADfQmg3TGx`p`9Of=EEKT3VO zA;BK{=Djy>GMVq6_fG&~=VTqH7;6+4|cZ`jC%hc!&4~5fth8B((%7d-Pc6YRMHE~wy=q7XB7%45s>(yM^sURZ^t&s^tJQG%B{dVY2%-RO> zUS*7GmRm2AD^oxyQlt#$*h86Wg}MSfLLRE{sqWL{GG_t)2Wro)gEut4a^5lh*;S^{ L&LFH{AGfI zefLL6?`{)gMJV_%m$~4G6;nsOe}(H(UrWWO?SVa=%~g!S|&WwmJfstdfXCRj$@kTCA{W&a8WAa z0~Q%pcl_BfEo)TNZKlJPeHF>m;h-(eg&=)~imw9^UJ9eqd{WHYo=O-zf9ge(p=kBb z*4gRQg|8EZp;cjH0#h<+*8LfZUU?_uK*s6DiGwwUQrdm4x!7Q+{@0;Qe5S!b;xAO{ ze|LR735mD#&;;^_N*66nciB&!K^63Y^zER?$h3Ki4rSl69PsYpURAtX6n|4Shcd+! z13F6-i`m`7M^q>)U>PffTBUoQI-fGG-G8{&-{9KIxN;f8CO*G|;pmxxVT*Wj`0@w5 CETt*{ literal 0 HcmV?d00001 diff --git a/bin/README b/bin/README new file mode 100755 index 000000000..b77c71a21 --- /dev/null +++ b/bin/README @@ -0,0 +1,68 @@ +JSON in Java [package org.json] + +Douglas Crockford +douglas@crockford.com + +2011-02-02 + + +JSON is a light-weight, language independent, data interchange format. +See http://www.JSON.org/ + +The files in this package implement JSON encoders/decoders in Java. +It also includes the capability to convert between JSON and XML, HTTP +headers, Cookies, and CDL. + +This is a reference implementation. There is a large number of JSON packages +in Java. Perhaps someday the Java community will standardize on one. Until +then, choose carefully. + +The license includes this restriction: "The software shall be used for good, +not evil." If your conscience cannot live with that, then choose a different +package. + +The package compiles on Java 1.2 thru Java 1.4. + + +JSONObject.java: The JSONObject can parse text from a String or a JSONTokener +to produce a map-like object. The object provides methods for manipulating its +contents, and for producing a JSON compliant object serialization. + +JSONArray.java: The JSONObject can parse text from a String or a JSONTokener +to produce a vector-like object. The object provides methods for manipulating +its contents, and for producing a JSON compliant array serialization. + +JSONTokener.java: The JSONTokener breaks a text into a sequence of individual +tokens. It can be constructed from a String, Reader, or InputStream. + +JSONException.java: The JSONException is the standard exception type thrown +by this package. + + +JSONString.java: The JSONString interface requires a toJSONString method, +allowing an object to provide its own serialization. + +JSONStringer.java: The JSONStringer provides a convenient facility for +building JSON strings. + +JSONWriter.java: The JSONWriter provides a convenient facility for building +JSON text through a writer. + + +CDL.java: CDL provides support for converting between JSON and comma +delimited lists. + +Cookie.java: Cookie provides support for converting between JSON and cookies. + +CookieList.java: CookieList provides support for converting between JSON and +cookie lists. + +HTTP.java: HTTP provides support for converting between JSON and HTTP headers. + +HTTPTokener.java: HTTPTokener extends JSONTokener for parsing HTTP headers. + +XML.java: XML provides support for converting between JSON and XML. + +JSONML.java: JSONML provides support for converting between JSONML and XML. + +XMLTokener.java: XMLTokener extends JSONTokener for parsing XML text. diff --git a/bin/RawJSON.class b/bin/RawJSON.class new file mode 100644 index 0000000000000000000000000000000000000000..dfc70b3a4002864d01c6efe17f73eedc7553d431 GIT binary patch literal 857 zcma)3T~8B16g{`r?si=%R4S;bL!ZhEB*rHpybyUH4I~yxe4K74?bO|wW_F7FGZIbo z-5+JR+ZIZ~8hx0LJLldr=brof&-b4I-r;S43L*F;zn%2XP6Jd4t7Ca7_flzwduRQz zN<8CkjuV>QCED{&o8dm8cA$;+hlEz=A-r=zs2SZ6P-%0tq~Jv`>D!4h^T%(QevQzR65R?$mFXWD$%xXxI50RX^VkXxiHp?O!{Ob zJg2Lx35&m<-i{(fXv7E*vXrhi>U5g*l{=UGPtlxBWO^Z;F5<;w)sJ*esCO40aliFk z`FZmpo)fnJDW9-1&DD`LUKxMvY(|JXcZ7vQjU=^36*IW?ywT|{!~G&B^mhI$VZF2S z&}l-{vs0I-V_kF;F9h!vmSY=)M?7-k^%%9;&VxnBFLjRIGg{#@`hn<6Grq>kFODi$ z<-InmBCPQ}p4}rf@r)x@@)w3y3By_`!v;1>HIy;5N*P|@<$p75mNLA;);)&8qqz@d O8n#LqUUN+aZ*Bm}+PYO>eyM z&R=AriQfC8jAvm3DBFnMoOfsD%roabGyCJ`mu~ zsA(wRY7TjhKa1zPc7kvo$=GS%dq&yY&OPoREo!yPkEcA zu%?zg5-we!5oV2Ux;k4%`8{#`q4}2VaOZdq2N8@R7sv^mL63Dl$)GM}0y*mRAAO3D z<=Fxmo=#)WHWIg0Gv%?e#49_z#SArND|~)f13gUoH?mm80#fv~igcuzNVAb@k)Dq< z7wKZ87lxW4VjfErFB0tu(HW`s6@_<&%b#)OJB<=_3Me~VVYo&yH_F0w+@MhwH*t$* zLc)XJ2)APh#*mO0?pwnO(Tnt*r2Tj1Bn-v`4fn7fO9;C(auHX<$1x#``zXy@JF86X oE0foMuANP4&td})|AX*hs)h}0#uCErp6Q-_8WR|{C^Lb|FU7eL#{d8T literal 0 HcmV?d00001 diff --git a/bin/XMLTokener.class b/bin/XMLTokener.class new file mode 100644 index 0000000000000000000000000000000000000000..71bfba0b8be87b4abd571ea86287e8ad7e63fe50 GIT binary patch literal 1138 zcmbVKU2hUW6g`8;!j_8CqSns^HK7ld#Q0>5ra_D`(3*ga8efKG0t3s;W_D=s$^YRW zG0{Zd{R{pVP5PADtw2ZpWon4j>*%*vqgf=8nc5BI73SSo3sFjVTN^?<8kqic;+!~NZ3hHO(0 zgo6!+QqrH)TgGUU$0mb(t&E6ta3Thtucx65xRqLYq0#+7Odok}p*IrVK==VSgbBGn z;X~oov>EP=Bdu!QK#Ryz+ImxN{gG!0F6N=|?OAxub>X5^go8Yd(w0gb&Zd1~dYs;2 zD7UrGgJW)Fd|xE9b|fQ)VtchAl3Y+?Zkx{zdIt>K_1(W^(@I-&Uxcxc$iY>H&3L8D zTprgLs{a&DP9!gBWyym--#Y4#Ng|Eo#-P^1q)NSccAzCFAA>r=^2PXxy$tziBEwfa zBKB1O-VuFQ&x|jg%Xmwr)gty{H&F${Ir^6vc5og!iX4h*$8;9x_K>O>`nq4?zAYC& zLirW8cWcO3K?vP&@-2DxDYtO#` literal 0 HcmV?d00001 diff --git a/bin/build.gradle b/bin/build.gradle new file mode 100644 index 000000000..8cd5d19e4 --- /dev/null +++ b/bin/build.gradle @@ -0,0 +1,20 @@ +apply plugin: 'java' +apply plugin: 'eclipse' + +version = '1.0' + +sourceSets { + main { + java { + srcDir projectDir + } + } +} + +uploadArchives { + repositories { + flatDir { + dirs 'jar' + } + } +} \ No newline at end of file diff --git a/bin/build.sh b/bin/build.sh new file mode 100644 index 000000000..0d3117adc --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,25 @@ +oldHash="$(cat ../../sums/JSONjavaBuild)" +newHash="$(tar c .git/refs/ | md5sum)" +echo oldHash: $oldHash +echo newHash: $newHash + +build=0 + +if [ -z "$oldHash" ] ; then + build=1 + echo "No previous hash." +else + if [ "X$oldHash" = "X$newHash" ] + then + echo "No change to hash." + else + build=1 + fi +fi + +if [ "$build" -gt 0 ] +then + gradle jar uploadArchives --parallel --daemon + touch ../../sums/JSONjavaBuild + echo "$newHash" > ../../sums/JSONjavaBuild +fi \ No newline at end of file diff --git a/bin/zip/BitInputStream.class b/bin/zip/BitInputStream.class new file mode 100644 index 0000000000000000000000000000000000000000..71e91ca07fb9e7eabc100f4c25c98842c3fdd16e GIT binary patch literal 1114 zcmbVKU60a06g>l#LS+|(U1j|&_yvAIVtjIq51KW>5I5OfH&GwV&`w~0cA9C~to{do zkBKJw?vFCw=@J%WqtP^-+uJ$!+%xCS_aC3X0(gM?HgXKL4>IaKl}SI0=E;7d1rKak z4Alug;=LIUN4?$QM0kmf0>jz@y(hRYG=mlJc*>A_+h-_Ift>N-OfWFY3-gfJeA<;E z!{#6*l&ZJVX`4`?rtUG7yrAT<3}y0!q0!EScMhrLGvx~#8w{0Gi91>=UBr2Y=oNL1 z)$B<4uBU>C6eUuHZlo0{3m&;n>0m5eUwAXF2@`Q|%16R&DLv{=Vik7jh%MJwB6dTS zxB*YRv71ndIF87M)e?hr9MsV$qlzs$pva_$|+7r*E8GHTLi_|rp(F76Ddxo9{Y!vDCKt+x&zJ-%{+w1rmh2MBinKgu-Q9p=cPc zt}x`y-aj&2gG-&8RA~`YYpEvflXBh2Q1dQR%{p$asQEL)G?U>r+L>xjy~$GZK9j41 QJO9D;F_Y^q`IE!FpAsL^)c^nh literal 0 HcmV?d00001 diff --git a/bin/zip/BitOutputStream.class b/bin/zip/BitOutputStream.class new file mode 100644 index 0000000000000000000000000000000000000000..7c86eb1b4ee5ab3e2c6cb324ebe498e5f38e9d01 GIT binary patch literal 1091 zcmbV~TW=CU7>3{Bw6N0B(o(I*1y7&}B*rUiywKDHLga#4!_caUS) zneip>1YAuzgV9X*)YNV>@$RKl@SXaEXCOK^*odT zw^A!FG`7_TgolJ!{7Jk4DX+rLQ;1l6Bw3)PL3$5CeS;HG^vGA0(-ke*1>RGag zRY=)yT4JT^ViyNxY~w0JZ5?+~EvlhZlcPB1N?$7RCYq0gIpGurL$$Ac9-ML`lVI_~NyUbJ+juxwK;}>L3)2JaWjuL6II=1|_)3dIjZV z-AdL1>9$d!d52D)k}pH6`xU$It9zeO`<`g8(Htv5S@&>1m35I>T3kGp^#Bi3S=mc-T&1#_|CQsXR91`b H&*0H7rSZ*& literal 0 HcmV?d00001 diff --git a/bin/zip/BitReader.class b/bin/zip/BitReader.class new file mode 100644 index 0000000000000000000000000000000000000000..6a7919353cd3ad892b246470a0e519874e1ac5d8 GIT binary patch literal 558 zcmZ8e%Sr<=6g|<}spF&C`hEsi)kO;~wYX3!REmNx&|R7dHFcT{nX!mJCMf9Mj}mWc zQE`!*oRfP`&b|5ge0c+~i_HKd3{y`!sU7Or}g`HC3{;#UrayZfwSTB9nJKqZ0L)kfXmPJ~Iqaz|H&nOt*R3=_%IeJKIqNEzWXS#*r*fMPRKlh0XF3<f;MFJE`h# z^LXO?TJc25R5;>fLf(k3;_KFR8@=3`2FY6IiB&l_*7Lsb@|t@}QNxTBeNG9?I7S82 zQNcz+f7 e^MscuzCg$lmg)ByS;6mb$m-WDivB4o|9t~J>3-1w literal 0 HcmV?d00001 diff --git a/bin/zip/Compressor.class b/bin/zip/Compressor.class new file mode 100644 index 0000000000000000000000000000000000000000..802c2fae9672db18cec55f77c0cfcd6478ffac08 GIT binary patch literal 15882 zcmeHOO;a327=C+z?6M&tV&X?MIuJjG7$Iu>3M5L97{UTZ2r}$$G5%4__SYZ1T+l&AP2n!jMg3aps1*<&Ia~`r7zR5cokJj*-)U+^XZx`qeF3 zvCGK8tGbcr*X>5&m#VZDUa|}Q%j?vx&~nuca8Sc7-*wlhJ>myzV;iAgA45JPcEzWm zUH2oq=0@dpJHjdSUW1k+aS9t5!+EuaA4K*phFx~+Y;uX(yKElaI41kdy)tcZA@(w} zBj0xI=zfF79BVXM_n9yi$E!!9_G;kQxBzU3ofsCEwn~GLO=t4dyfF0YYaGaK`OQLq z%Ug*!9Vl=gVI#q-W!Wp=jYDRR(nj~nH>GLGCi=3SAcs(|u*z2p z=OkP@)=qJ_WpM*JX9G2sF$Y<2Yt&HHX3jN?RvpHqHd)CC5o5sn^jWgY;L=Axh*%?_ zf+4h}E+d@P`;&TvK+IUwnAyS9YdiGR-BaNV2TzZ$LkP_O-+3X6-?OnDFB@9QL?JC2 z*q=DMnM5J@h1oTj_BsQyo5=b4WXS5s&FdR|*9QeCz~BJn-~@qFPBCeM#RcpHYmyBX zy*gdktd(f6%noj`msa%4ZgpknAb01(-e}zm37p_dS&Mfl5F0nJq-HsKs=(Blv?V$A4 z)DYwSX)O6BT9+|Kppimnt+gV7lTMLQnQhUOz<{`kC7QD{8=fZ$@%OA>#l9^vi}DjN zZjrZ1?=LBq(ww9S&kXLuTl9NdnYy+c#-wA35g*SUw!G4H_Jy3weM$RyM7Ormx91B> zG*O&z*^C}OnK6tYixI80f#Uy-xB|?R+DfK43Gih1KIwUoGTAjNn-mGJW12bWD;d2F zF2VR*TfOKhVm>)mPusCcJFcU}#J*ko`r}E5?X$EZrwpOp&}9vUJWLV`G>53V3{#H~ ze8JfMVEi0HTej^`y6HN%#=nyCgcAoGUg^d~Yy6fc@()SR!<1f5; zJqSlTY~A6%gGzO2@#%MHkgV;TW9 z?Cp=2Q<;fVA;t`=t<6KQg}|xuZ88rxi1k;BaLN)a`(9?Y)Bu8J28ub3ZX`pA&SZ8C z+RT1%luhIXZ8BirhGFGlp1}P6e$Q@c%i#9d7veYJ6_)(XpiHlMtUWlGbpOU!M==MV z;<6?xT zB?vb;0{ayL&%$X$e-2;w;=AXY91?^VBnWE~4i?x-tYHaOLxM%%EW9M;m1y&_1nUb4 zmIbeZBgJBNh*gqdJ?MZns=zuY;q|oy3y{}&1=i~ltnWHtjZ3lmnroC{{VKt--~zlM z#Y*&&+3|M?7Q5&5Eh$!F$BU9R{wcw-;2n5Zf%V>AEOJJQbqV87=JyG&2?^F^2^PR* zxT3)NK!SBgf@Q&!lGjxU)|V12fRA8C!Rwj?>!Ae8g6m4{XC+vFOR?sZd7`)%%Q`E; oBCw#;UWRp{1D48HWmppuEDIJf?kxBOZnOBq+k{1h7p=D&ng9R* literal 0 HcmV?d00001 diff --git a/bin/zip/Decompressor.class b/bin/zip/Decompressor.class new file mode 100644 index 0000000000000000000000000000000000000000..05eb35d18c31872124fd2e3d05d3e30744dc96fc GIT binary patch literal 11292 zcmeHNTXWk)6h7;?vE!yquiP(7xXI8uP|B??fuxtAG^8^mWQM%S^2SkWOCCwiw0+`* z2Yvz%yfVWKFFY{=Gw{X(zky%Ck6<`Qa_o(>RI6A^#zP-0Th{KUbG|*dJ<=b4|NJWe zT!QN*C@?tn!0j$v7mnZQ1|kgopaew*$LZfs*6yt0H-njm8wJ8{ih#k~3SC-uqtD_$ z>I|l@x}F;?GB{(6T&r#{C|>iMq6Eir=8nBX5l#{Jy26R%DKs*Hb30u>i1;1`cWjR)Hw534=IF)|?Kkc@q8k%&P%<9*+~(2! zuBgmB8f%`1r692HD=cK3b2YG0#U?e7sqj1 zA_z$Va+Ho6hBzfQDZbC55+{(rH|%y#7{JB=Gcl+{vMC;nFW}@@$38<$ala84uv{-P zWB+#=JD5|(GSvj)fM>;?ZZ&+rEo^Tb;bS1<@U%LKCMiop19hU92H>t8xHeV=+0ve5 z8)l*m`K&c4h(?$0Eh|7^zi3u~PIrIC_RDI~0%6J%%XeL5Pi?QnO zK^n=X@)$mnqsSGgz}zg9;1q-N*2=J>mh9{5)Nz|zaXqox>oi2LPUSK-=2m>iZg2F< z=l-9?Xxk0x8ujz!>JM9bQ)tk5w5pp7Dg(m85E@>=rg?=`7x5 zF*s>$R#%9@_#Ab7l}&xCsiW>jZD0}_3#p5#Gj1dnOinXH65LF#FoQ~FWomao*hUx7 zD0rT%Fenol z71nB348pfYd`$ryG|l=}My-!gE9(~zWmsVB2Xj_tE=K)d+izI?3>}P8f0FqVlfcyf z7At(Mxt=Lz^r(rq_k27Pt=A)Xiw=oepV5 z@>5KvYq%LP)NnVWK_=#m>zGLzGwT>vM9X_`xfp+_b407!-#Ny`Y#H8XQ#W(=NJ%fV zHKv*B)r@VKLCu-pht{guT4$0G7!MuNy@(LfVyunFAoXNYnZdE1hkdm&TxIaRS)a;L zMa!gmcB zevZL39%u1)3Ceh!!L!SFwSeE1U!d~Enc1J<@Re*VT z@eo*FDY0IHms7A_QRw)M63c?B5^Ko)YYMC%l~@kW7_1?!Rm>rW-t y-nG`7-hK=T zBzWhe5VKCA6o`1^fd|j=uFsr3eJt#7$ z9f(7*77G=v?F0uHS`SJL<{focXZE!=783@=K!hI|)H}avwCR(=V@q&~Ml(346*BOo zvKXOZz&06_j!;Ge;;=1RJe5k?XOz&|T-hgB*FE&$68W22*)T?%GF)bb=Wmq3Ovi`V zyoDierxCWRg6>0h&EQeZ`>B(V>XusB9{QW<3^JhM5QV7?dZI zMW3Lj=D6ksVorwMlnebQpE4EMqR2?+g3 A7XSbN literal 0 HcmV?d00001 diff --git a/bin/zip/Huff.class b/bin/zip/Huff.class new file mode 100644 index 0000000000000000000000000000000000000000..62938f9dc4b2e588a7bd8acb027d9eae5a8804d8 GIT binary patch literal 2481 zcmdT_>uwY`7(L!>vKIn@rD?eq6E59tX;SWxP$UQ-7KMP=kgDx3@2s=yurnTc93XiJ z-hj72LIMf?^Ax-Yh|gX&7cc=;MS>q=&)A>OeCP8y_N%wgUH~|Oiv{EuiYqFexW2To zP(Yqx`=YonCb}YNPuyxQ%E%Tl^gd=*C$fMd!#20#w$AKLZLEwLhFUrnDq&!ChC;R+ zH+45-sQf$A$3EQfgHsHHRy4bkVMk!DxRlQ6E5gz=`-egwsFv*z`~{ULdyyeut=HzM zo7OGLgCbeyWLuu3O9HJbh$XOp~Kn(Ij3l2KO} z3Q9$EPqZZ;)22PXnCWDk(jMb2Ei;~I%VS}q4!5*KK1``3>zBC59-N9(DhKal@JJ+X zaZ~bsHs#Wd#;w__4;F0VZ_Y1n z)9V55XBeJ*kK9R;4ZUO{c}=;Cq2$ja=Q)PqdO}W_?usmvq*n6I$OktH-44B@i-K?V z&Z9Xxt}+}1!vJy^M1h_PN+{E%SHTtxQ=h|DZ1epHw)=jEpD)p>3U*Ta1C5^Y2tfHc zM*pt-^c1^a`q+Kc4p9u~*-!1Te=p-_9Pne@|Gkgk;(7>U0fff^gd7gzNHB*G!kYjB zBZQ-0ionK#2*038b*fSJc|!U%P?2LF^I?-gtnp9OG{A>7K7lZ?j?chmHDw}zki#E1 u9^|uzbt1sW1h5!ko%#&c=>XQF0M-D`5|XY(7-eq>eziA_N>YdT7ejLePPkV}CFrRLdZIZ& z04Nx6d$&CbdnysM5Xu*wQ7<)#9}QY68kiyC$YGBkjqyxihd9wa1+AwX3dz~@K*0}v z!)!foay^XA%X|!I0bOUry(Ez@IZ6nsg6t+E#Sr7-wg*&>i}Anr_j$pp*61VNLl=SGnf7mLIA7zH}wZz}0AJ zPX;?O@fjCn*$jO&oX@fNATY;DPYwL2MlC_--r60;6zBoQRB!Umm3lK!Ued&&GcE9jz`sMMy`F5>IXTT`yGr z{!cCZ8SJ`+mtbG8Fza8m@Fm!nExZi7Vc{#VuUhyTouKQqf<8{r=k!Ik-YC{D3;rv* znenR`U!yWE(AVhbHrN$RSYUO2r8`d+?)^+_zXO$M1OJnmN6>xP(|Hs=-CMBWLn+-0V0q=U;qFB literal 0 HcmV?d00001 diff --git a/bin/zip/Keep.class b/bin/zip/Keep.class new file mode 100644 index 0000000000000000000000000000000000000000..083778e4777649c8d1bfcac4816a93d5cea856ff GIT binary patch literal 831 zcmah|ZHv=D5Pmk7Hf^levs&L@_Uc>fhZaN-JP|<@uGUky^FaKxO_y|g>2BC;tKJ_I z6!g14N}S{(cVb0CX0x;NJoC)V=Eu)3-vHc4H-N`bJ5=f5rIcv^pJ8JrmST_y9S>fQ zXEJgDs%6ZM(K0}dVLeB@F`0X1tdny(jzlUVAR_-vcu8u4sS86 zk+{6}VQ*LiXW0C2eGI`^xlA1rZmrv+{`yWu2h`oANEYO5QzK94JQ^FN3U|%IM)HNq z1=jNk_w#Ce4kChw3TWc=)DhBk@NueK8|8W$>*TLcbQ2q7&(Q8cfds;@XuWHl`;7D7 z$?M?~*($|=-pgbg#dnA+xJtV^uHkygaPJR>8!H$d77Sj&wTVuN%QNTvN10dQp03Eu ZaPuG9S1}C#W}si<7H$_>?vV9x_ZK8tqn!W% literal 0 HcmV?d00001 diff --git a/bin/zip/MapKeep.class b/bin/zip/MapKeep.class new file mode 100644 index 0000000000000000000000000000000000000000..60a9c9965b60afcc375b88a4766dcf168dd78897 GIT binary patch literal 1223 zcmb`G%Wl&^6o&sv(_Gw?Kti}*rs0-s5(%*)hz$Z!H3g)WNL)4(XPQi~J=S;<0ec>U z=Rg7p_PhhHf;e{5HbO(y1+wJ1oPWMK{?GBx-(SB2xQjbQrTBJvES zbR%6cM@VX`-VJCEesBEfXGT%R^!P3Ac1azK<#0 zQ0r@71Os7Ix?XJN?L;LE>;0vok=@1AG~rXJR$A>r36~f)j<=K?rK;?yX!KW3i}JQN z8N660cAFfMA=SB+-TC5htJi*A0%zDe{-UgQ|G`A+OC!hBj?(-iV{&nIE`k|(*PyOj z^7*i3y&XL>zI>umgDZ=s@1z|G4l<8^iyS?xC}guDN;DQIQiezGHCo*xRgOmQ8!E4A zr@r9yk4#%%C_%cjG_TM|Dl~8|i=W4ZB|;X<2p1iMo`b+}8CRAFM>)6%Z=HmzxaK5W ecjTa)gbg&E1Xm89oP-;=d1At6C*fA+=j}h~w+{yZ literal 0 HcmV?d00001 diff --git a/bin/zip/None.class b/bin/zip/None.class new file mode 100644 index 0000000000000000000000000000000000000000..1674c79f1256b95ee3bdf266cef0a81e0fd1e1be GIT binary patch literal 442 zcmYjNO-}+b6r2jevVtIrAGd}RdVs{E5-&s(6M_ej#A8{SrMR@4ZXw1$W}=DS{ZZ;G zA;BKroA)|1nY{0x_fG(qI4xp_A$V13XJE7}BF|8pi+ho#X>@~MmxVTqH9=vl;)H;s+k^UUZrC2sPmkr~&<@r7{Fj60IZ zmy{C!mw09vqKtzw>NsR5bT?5Ot^PLL&{?J9YahPaS6U91i;1)&L3tSJeG`dfEUfbL zW*H96(nj)5c}B^fukGy$bSLEKx(sL7MS*&erX2)?0+bL^-=odNngxU(C_mNr-%$Hn S^Ny%`m3L^YHy$0Y(a9f4y=`>> literal 0 HcmV?d00001 diff --git a/bin/zip/PostMortem.class b/bin/zip/PostMortem.class new file mode 100644 index 0000000000000000000000000000000000000000..8b5f285b6107a7bfe69e3ce80ceed696bbaf34e0 GIT binary patch literal 449 zcmY+B&riZI9K~M|*_h}M#B;+5JV4@6h!>-$`6B^I^j5lN6t{Kh3Nij;CYtEoKg!rG zMD)-m@8x~_{p9uQ`|Sh3DUKaf2o7FkHoQ~0xmMbU#6gvyxnyfLj9D5DZ|6(F4S_r6 zu}q~oC)nxrX9U#?6$%G+0)Lyn)LLm5dj#2iszt8iwFoI!NhV`vq)KU~)jSr-8TIPZ zg`lC}G1E4aG5*9NLAy#vgJrJLf#vGbP>GzT%Fu)vzM#gAi08}_{T(Tio(C8E4IIEH zsEs$MonEkon;0$AXjH)aflS5CDwzvCWtNAa6)4W)8Pl@R8`H~vdm(7|g8x;G`i}(O zM6EOzSF(7--}X2t_SOh&UAAnXV)1rSv)ZxhWaE18a35OUD;l3=rfKgY1A7ijr}&N* K+NE<;I-MUxCvqMD literal 0 HcmV?d00001 diff --git a/bin/zip/README b/bin/zip/README new file mode 100644 index 000000000..93e6470b7 --- /dev/null +++ b/bin/zip/README @@ -0,0 +1,2 @@ +FOR EVALUATION PURPOSES ONLY. THIS PACKAGE HAS NOT BEEN TESTED ADEQUATELY FOR +PRODUCTION USE. diff --git a/bin/zip/TrieKeep$Node.class b/bin/zip/TrieKeep$Node.class new file mode 100644 index 0000000000000000000000000000000000000000..0d5ff9cb3376cb7a778e3bc801553c607dafe76b GIT binary patch literal 2325 zcmeHI-A)rh6#k}ETGj&P-+u>0-Kqg&yrRYnh$IaaO+XU$YP%iUf!&?W?9iZ3V0-{y z!ACIBMDKklV61S!##49d#vNPwLZ_oM8*>8US`uZKfBRnV|$1w3;#>?AUiVY#+ z#ZA=|1>_mZdtS#|4!o$f{GzcZd{e+M!8saPh=#`Q%c4?X{ziH=vtc71jG1oPS3Pfx`-*3|L`i(B2hs{ zG`X+BSO%VvD&nzLjX;FS3U@}f+k!WRA9$LaV$a|AT7oYq-CEj9RJ26NF7T!j36GTF zp=bOyHxwccV=BBi#CjgV$uK4gco&2FUSxwCf_JlVMmA)aan6n69yjk|aqf|J?Nof& zR))f~Rg>?_(53OK@LjFKv|*N1-koJ?#IDeZrQ0?$lu06^R!Tgl&J05SfBo3`w9ub+ zs#!P-#?G$A4$7D*VHC3rGj9D@tG0}$!K+#=8?VbqY#xLSp|?GfCx*$o^1Wck)6(w$ z9OkW3GEAKi!&I9|EQeZxGrN9v6h6}yx|9L};{7rpYU`zVK~xHOA(}K4Fab%FU)y$Q2X=QhvjY*I!1yS> zfQcsh&mYDo@Bw@ZV?48^wuXV0q~RAo_A=9RzB%)qv)`P4|MTe!0NjD6aflE|zUBVd zvgB-zF+UD50+yc9BLW?3Qn&$u$Z8G;svuFoA? zap6&4ih{%3V3H=fmMe^wSkbX18u@l{!!9#AB4jzU9tbakQH{`&U;*`nqOPrq6{^sM zz42L5HM(faDjauxAr-A*(4y^W=K`a(XcAqxAHzIVg4$GV`|QXf%-VtY(5ZBps)!QB zx=C?QrKv8tFkzZhTB}S<#2S-D!s21A6So>0( zfIc{$gd_|R7)s^qTD7Dk7G73sSzn%eY+=(aFu81_JP{bki=yqU*pln<&SXqgI7(vg ze|m}17{!uDwMAVFwbFv~1b(!jf9)XZP%u#a9p;r)rKVc z2V;BG6x#yH$~;g^&fDI$uF^0Q=@koZ5@_X=Zq7{`EC_Vh;#~BY1-A&SwIy#&V@2A#`wX5b5 zOJY+N*>kR?w5N9RXLM{>kU7s|a@MhffCX`wCeXjD|3sb9ZD<@GV^WX;^qQ|W3d`6_ z1V91jvGVG(Dnr0 zJJAO4I*IpW_@01Ma5|hj180p0=L`tnj0hLtq7i`_5PljFM&MEdLJZ@o?qbw{@XLsB z1+F$A)OkqlMj%lm!Zo;VM7Uu<=rJN>_COdjAWZCmVCKOT!?Y3MHvVU-*MrV_mC3t? r7)nNjdoa;}P-pVK0pYy?Aqo$1)d);NR ../../sums/JSONjavaBuild +fi \ No newline at end of file From 701a29bfe926e95444d4811368b0e0bc39390939 Mon Sep 17 00:00:00 2001 From: Marcus Longmuir Date: Tue, 24 Sep 2013 22:07:58 -0700 Subject: [PATCH 2/4] Removed build optimizations (that weren't worthwhile due to the current setup) --- bin/build.sh | 25 ------------------------- build.sh | 25 ------------------------- 2 files changed, 50 deletions(-) diff --git a/bin/build.sh b/bin/build.sh index 0d3117adc..e69de29bb 100644 --- a/bin/build.sh +++ b/bin/build.sh @@ -1,25 +0,0 @@ -oldHash="$(cat ../../sums/JSONjavaBuild)" -newHash="$(tar c .git/refs/ | md5sum)" -echo oldHash: $oldHash -echo newHash: $newHash - -build=0 - -if [ -z "$oldHash" ] ; then - build=1 - echo "No previous hash." -else - if [ "X$oldHash" = "X$newHash" ] - then - echo "No change to hash." - else - build=1 - fi -fi - -if [ "$build" -gt 0 ] -then - gradle jar uploadArchives --parallel --daemon - touch ../../sums/JSONjavaBuild - echo "$newHash" > ../../sums/JSONjavaBuild -fi \ No newline at end of file diff --git a/build.sh b/build.sh index 0d3117adc..e69de29bb 100644 --- a/build.sh +++ b/build.sh @@ -1,25 +0,0 @@ -oldHash="$(cat ../../sums/JSONjavaBuild)" -newHash="$(tar c .git/refs/ | md5sum)" -echo oldHash: $oldHash -echo newHash: $newHash - -build=0 - -if [ -z "$oldHash" ] ; then - build=1 - echo "No previous hash." -else - if [ "X$oldHash" = "X$newHash" ] - then - echo "No change to hash." - else - build=1 - fi -fi - -if [ "$build" -gt 0 ] -then - gradle jar uploadArchives --parallel --daemon - touch ../../sums/JSONjavaBuild - echo "$newHash" > ../../sums/JSONjavaBuild -fi \ No newline at end of file From 2e8a20a1877f6fdff1eba392d525ca1b9225280f Mon Sep 17 00:00:00 2001 From: Marcus Longmuir Date: Wed, 25 Sep 2013 10:18:28 -0700 Subject: [PATCH 3/4] Re-added accidentally removed build script. --- bin/build.sh | 1 + build.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/bin/build.sh b/bin/build.sh index e69de29bb..ba1ccbe7a 100644 --- a/bin/build.sh +++ b/bin/build.sh @@ -0,0 +1 @@ +gradle jar uploadArchives --parallel --daemon \ No newline at end of file diff --git a/build.sh b/build.sh index e69de29bb..ba1ccbe7a 100644 --- a/build.sh +++ b/build.sh @@ -0,0 +1 @@ +gradle jar uploadArchives --parallel --daemon \ No newline at end of file From c061f683557664a5bdd75aa9845c14ef2e08a360 Mon Sep 17 00:00:00 2001 From: Marcus Longmuir Date: Thu, 26 Sep 2013 22:42:43 -0700 Subject: [PATCH 4/4] Vastly improved build times. --- bin/build.gradle | 8 ++------ bin/build.sh | 2 +- build.gradle | 8 ++------ build.sh | 2 +- 4 files changed, 6 insertions(+), 14 deletions(-) diff --git a/bin/build.gradle b/bin/build.gradle index 8cd5d19e4..dd4b4bc7c 100644 --- a/bin/build.gradle +++ b/bin/build.gradle @@ -11,10 +11,6 @@ sourceSets { } } -uploadArchives { - repositories { - flatDir { - dirs 'jar' - } - } +jar { + destinationDir = file('jar/') } \ No newline at end of file diff --git a/bin/build.sh b/bin/build.sh index ba1ccbe7a..8f931344c 100644 --- a/bin/build.sh +++ b/bin/build.sh @@ -1 +1 @@ -gradle jar uploadArchives --parallel --daemon \ No newline at end of file +gradle jar --parallel --daemon \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8cd5d19e4..dd4b4bc7c 100644 --- a/build.gradle +++ b/build.gradle @@ -11,10 +11,6 @@ sourceSets { } } -uploadArchives { - repositories { - flatDir { - dirs 'jar' - } - } +jar { + destinationDir = file('jar/') } \ No newline at end of file diff --git a/build.sh b/build.sh index ba1ccbe7a..8f931344c 100644 --- a/build.sh +++ b/build.sh @@ -1 +1 @@ -gradle jar uploadArchives --parallel --daemon \ No newline at end of file +gradle jar --parallel --daemon \ No newline at end of file