- * Each row of text represents a row in a table or a data record. Each row - * ends with a NEWLINE character. Each row contains one or more values. - * Values are separated by commas. A value can contain any character except - * for comma, unless it is wrapped in single quotes or double quotes. - *
- * The first row usually contains the names of the columns. - *
- * A comma delimited list can be converted into a JSONArray of JSONObjects.
- * The names for the elements in the JSONObjects can be taken from the names
- * in the first row.
- * @author JSON.org
- * @version 2016-05-01
- */
-public class CDL {
-
- /**
- * Constructs a new CDL object.
- * @deprecated (Utility class cannot be instantiated)
- */
- @Deprecated
- public CDL() {
- }
-
- /**
- * Get the next value. The value can be wrapped in quotes. The value can
- * be empty.
- * @param x A JSONTokener of the source text.
- * @param delimiter used in the file
- * @return The value string, or null if empty.
- * @throws JSONException if the quoted string is badly formed.
- */
- private static String getValue(JSONTokener x, char delimiter) throws JSONException {
- char c;
- char q;
- StringBuilder sb;
- do {
- c = x.next();
- } while (c == ' ' || c == '\t');
- if (c == 0) {
- return null;
- } else if (c == '"' || c == '\'') {
- q = c;
- sb = new StringBuilder();
- for (;;) {
- c = x.next();
- if (c == q) {
- //Handle escaped double-quote
- char nextC = x.next();
- if (nextC != '\"') {
- // if our quote was the end of the file, don't step
- if (nextC > 0) {
- x.back();
- }
- break;
- }
- }
- if (c == 0 || c == '\n' || c == '\r') {
- throw x.syntaxError("Missing close quote '" + q + "'.");
- }
- sb.append(c);
- }
- return sb.toString();
- } else if (c == delimiter) {
- x.back();
- return "";
- }
- x.back();
- return x.nextTo(delimiter);
- }
-
- /**
- * Produce a JSONArray of strings from a row of comma delimited values.
- * @param x A JSONTokener of the source text.
- * @return A JSONArray of strings.
- * @throws JSONException if a called function fails
- */
- public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
- return rowToJSONArray(x, ',');
- }
-
- /**
- * Produce a JSONArray of strings from a row of comma delimited values.
- * @param x A JSONTokener of the source text.
- * @param delimiter custom delimiter char
- * @return A JSONArray of strings.
- * @throws JSONException if a called function fails
- */
- public static JSONArray rowToJSONArray(JSONTokener x, char delimiter) throws JSONException {
- JSONArray ja = new JSONArray();
- for (;;) {
- String value = getValue(x,delimiter);
- char c = x.next();
- if (value != null) {
- ja.put(value);
- } else if (ja.length() == 0 && c != delimiter) {
- return null;
- } else {
- // This line accounts for CSV ending with no newline
- ja.put("");
- }
-
- for (;;) {
- if (c == delimiter) {
- break;
- }
- if (c != ' ') {
- if (c == '\n' || c == '\r' || c == 0) {
- return ja;
- }
- throw x.syntaxError("Bad character '" + c + "' (" +
- (int)c + ").");
- }
- c = x.next();
- }
- }
- }
-
- /**
- * Produce a JSONObject from a row of comma delimited text, using a
- * parallel JSONArray of strings to provides the names of the elements.
- * @param names A JSONArray of names. This is commonly obtained from the
- * first row of a comma delimited text file using the rowToJSONArray
- * method.
- * @param x A JSONTokener of the source text.
- * @return A JSONObject combining the names and values.
- * @throws JSONException if a called function fails
- */
- public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x) throws JSONException {
- return rowToJSONObject(names, x, ',');
- }
-
- /**
- * Produce a JSONObject from a row of comma delimited text, using a
- * parallel JSONArray of strings to provides the names of the elements.
- * @param names A JSONArray of names. This is commonly obtained from the
- * first row of a comma delimited text file using the rowToJSONArray
- * method.
- * @param x A JSONTokener of the source text.
- * @param delimiter custom delimiter char
- * @return A JSONObject combining the names and values.
- * @throws JSONException if a called function fails
- */
- public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x, char delimiter) throws JSONException {
- JSONArray ja = rowToJSONArray(x, delimiter);
- return ja != null ? ja.toJSONObject(names) : null;
- }
-
- /**
- * Produce a comma delimited text row from a JSONArray. Values containing
- * the comma character will be quoted. Troublesome characters may be
- * removed.
- * @param ja A JSONArray of strings.
- * @return A string ending in NEWLINE.
- */
- public static String rowToString(JSONArray ja) {
- return rowToString(ja, ',');
- }
-
- /**
- * Produce a comma delimited text row from a JSONArray. Values containing
- * the comma character will be quoted. Troublesome characters may be
- * removed.
- * @param ja A JSONArray of strings.
- * @param delimiter custom delimiter char
- * @return A string ending in NEWLINE.
- */
- public static String rowToString(JSONArray ja, char delimiter) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < ja.length(); i += 1) {
- if (i > 0) {
- sb.append(delimiter);
- }
- Object object = ja.opt(i);
- if (object != null) {
- String string = object.toString();
- if (!string.isEmpty() && (string.indexOf(delimiter) >= 0 ||
- string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 ||
- string.indexOf(0) >= 0 || string.charAt(0) == '"')) {
- sb.append('"');
- int length = string.length();
- for (int j = 0; j < length; j += 1) {
- char c = string.charAt(j);
- if (c >= ' ' && c != '"') {
- sb.append(c);
- }
- }
- sb.append('"');
- } else {
- sb.append(string);
- }
- }
- }
- sb.append('\n');
- return sb.toString();
- }
-
- /**
- * Produce a JSONArray of JSONObjects from a comma delimited text string,
- * using the first row as a source of names.
- * @param string The comma delimited text.
- * @return A JSONArray of JSONObjects.
- * @throws JSONException if a called function fails
- */
- public static JSONArray toJSONArray(String string) throws JSONException {
- return toJSONArray(string, ',');
- }
-
- /**
- * Produce a JSONArray of JSONObjects from a comma delimited text string,
- * using the first row as a source of names.
- * @param string The comma delimited text.
- * @param delimiter custom delimiter char
- * @return A JSONArray of JSONObjects.
- * @throws JSONException if a called function fails
- */
- public static JSONArray toJSONArray(String string, char delimiter) throws JSONException {
- return toJSONArray(new JSONTokener(string), delimiter);
- }
-
- /**
- * Produce a JSONArray of JSONObjects from a comma delimited text string,
- * using the first row as a source of names.
- * @param x The JSONTokener containing the comma delimited text.
- * @return A JSONArray of JSONObjects.
- * @throws JSONException if a called function fails
- */
- public static JSONArray toJSONArray(JSONTokener x) throws JSONException {
- return toJSONArray(x, ',');
- }
-
- /**
- * Produce a JSONArray of JSONObjects from a comma delimited text string,
- * using the first row as a source of names.
- * @param x The JSONTokener containing the comma delimited text.
- * @param delimiter custom delimiter char
- * @return A JSONArray of JSONObjects.
- * @throws JSONException if a called function fails
- */
- public static JSONArray toJSONArray(JSONTokener x, char delimiter) throws JSONException {
- return toJSONArray(rowToJSONArray(x, delimiter), x, delimiter);
- }
-
- /**
- * Produce a JSONArray of JSONObjects from a comma delimited text string
- * using a supplied JSONArray as the source of element names.
- * @param names A JSONArray of strings.
- * @param string The comma delimited text.
- * @return A JSONArray of JSONObjects.
- * @throws JSONException if a called function fails
- */
- public static JSONArray toJSONArray(JSONArray names, String string) throws JSONException {
- return toJSONArray(names, string, ',');
- }
-
- /**
- * Produce a JSONArray of JSONObjects from a comma delimited text string
- * using a supplied JSONArray as the source of element names.
- * @param names A JSONArray of strings.
- * @param string The comma delimited text.
- * @param delimiter custom delimiter char
- * @return A JSONArray of JSONObjects.
- * @throws JSONException if a called function fails
- */
- public static JSONArray toJSONArray(JSONArray names, String string, char delimiter) throws JSONException {
- return toJSONArray(names, new JSONTokener(string), delimiter);
- }
-
- /**
- * Produce a JSONArray of JSONObjects from a comma delimited text string
- * using a supplied JSONArray as the source of element names.
- * @param names A JSONArray of strings.
- * @param x A JSONTokener of the source text.
- * @return A JSONArray of JSONObjects.
- * @throws JSONException if a called function fails
- */
- public static JSONArray toJSONArray(JSONArray names, JSONTokener x) throws JSONException {
- return toJSONArray(names, x, ',');
- }
-
- /**
- * Produce a JSONArray of JSONObjects from a comma delimited text string
- * using a supplied JSONArray as the source of element names.
- * @param names A JSONArray of strings.
- * @param x A JSONTokener of the source text.
- * @param delimiter custom delimiter char
- * @return A JSONArray of JSONObjects.
- * @throws JSONException if a called function fails
- */
- public static JSONArray toJSONArray(JSONArray names, JSONTokener x, char delimiter) throws JSONException {
- if (names == null || names.length() == 0) {
- return null;
- }
- JSONArray ja = new JSONArray();
- for (;;) {
- JSONObject jo = rowToJSONObject(names, x, delimiter);
- if (jo == null) {
- break;
- }
- ja.put(jo);
- }
- if (ja.length() == 0) {
- return null;
- }
-
- // The following block accounts for empty datasets (no keys or vals)
- if (ja.length() == 1) {
- JSONObject j = ja.getJSONObject(0);
- if (j.length() == 1) {
- String key = j.keys().next();
- if ("".equals(key) && "".equals(j.get(key))) {
- return null;
- }
- }
- }
- return ja;
- }
-
-
- /**
- * Produce a comma delimited text from a JSONArray of JSONObjects. The
- * first row will be a list of names obtained by inspecting the first
- * JSONObject.
- * @param ja A JSONArray of JSONObjects.
- * @return A comma delimited text.
- * @throws JSONException if a called function fails
- */
- public static String toString(JSONArray ja) throws JSONException {
- return toString(ja, ',');
- }
-
- /**
- * Produce a comma delimited text from a JSONArray of JSONObjects. The
- * first row will be a list of names obtained by inspecting the first
- * JSONObject.
- * @param ja A JSONArray of JSONObjects.
- * @param delimiter custom delimiter char
- * @return A comma delimited text.
- * @throws JSONException if a called function fails
- */
- public static String toString(JSONArray ja, char delimiter) throws JSONException {
- JSONObject jo = ja.optJSONObject(0);
- if (jo != null) {
- JSONArray names = jo.names();
- if (names != null) {
- return rowToString(names, delimiter) + toString(names, ja, delimiter);
- }
- }
- return null;
- }
-
- /**
- * Produce a comma delimited text from a JSONArray of JSONObjects using
- * a provided list of names. The list of names is not included in the
- * output.
- * @param names A JSONArray of strings.
- * @param ja A JSONArray of JSONObjects.
- * @return A comma delimited text.
- * @throws JSONException if a called function fails
- */
- public static String toString(JSONArray names, JSONArray ja) throws JSONException {
- return toString(names, ja, ',');
- }
-
- /**
- * Produce a comma delimited text from a JSONArray of JSONObjects using
- * a provided list of names. The list of names is not included in the
- * output.
- * @param names A JSONArray of strings.
- * @param ja A JSONArray of JSONObjects.
- * @param delimiter custom delimiter char
- * @return A comma delimited text.
- * @throws JSONException if a called function fails
- */
- public static String toString(JSONArray names, JSONArray ja, char delimiter) throws JSONException {
- if (names == null || names.length() == 0) {
- return null;
- }
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < ja.length(); i += 1) {
- JSONObject jo = ja.optJSONObject(i);
- if (jo != null) {
- sb.append(rowToString(jo.toJSONArray(names), delimiter));
- }
- }
- return sb.toString();
- }
-}
diff --git a/src/main/java/org/json/Cookie.java b/src/main/java/org/json/Cookie.java
deleted file mode 100644
index f7bab236f..000000000
--- a/src/main/java/org/json/Cookie.java
+++ /dev/null
@@ -1,212 +0,0 @@
-package org.json;
-
-import java.util.Locale;
-
-/*
-Public Domain.
-*/
-
-/**
- * Convert a web browser cookie specification to a JSONObject and back.
- * JSON and Cookies are both notations for name/value pairs.
- * See also: https://tools.ietf.org/html/rfc6265
- * @author JSON.org
- * @version 2015-12-09
- */
-public class Cookie {
-
- /**
- * Constructs a new Cookie object.
- * @deprecated (Utility class cannot be instantiated)
- */
- @Deprecated()
- public Cookie() {
- }
-
- /**
- * Produce a copy of a string in which the characters '+', '%', '=', ';'
- * and control characters are replaced with "%hh". This is a gentle form
- * of URL encoding, attempting to cause as little distortion to the
- * string as possible. The characters '=' and ';' are meta characters in
- * cookies. By convention, they are escaped using the URL-encoding. This is
- * only a convention, not a standard. Often, cookies are expected to have
- * encoded values. We encode '=' and ';' because we must. We encode '%' and
- * '+' because they are meta characters in URL encoding.
- * @param string The source string.
- * @return The escaped result.
- */
- public static String escape(String string) {
- char c;
- String s = string.trim();
- int length = s.length();
- StringBuilder sb = new StringBuilder(length);
- for (int i = 0; i < length; i += 1) {
- c = s.charAt(i);
- if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') {
- sb.append('%');
- sb.append(Character.forDigit((char)((c >>> 4) & 0x0f), 16));
- sb.append(Character.forDigit((char)(c & 0x0f), 16));
- } else {
- sb.append(c);
- }
- }
- return sb.toString();
- }
-
-
- /**
- * Convert a cookie specification string into a JSONObject. The string
- * must contain a name value pair separated by '='. The name and the value
- * will be unescaped, possibly converting '+' and '%' sequences. The
- * cookie properties may follow, separated by ';', also represented as
- * name=value (except the Attribute properties like "Secure" or "HttpOnly",
- * which do not have a value. The value {@link Boolean#TRUE} will be used for these).
- * The name will be stored under the key "name", and the value will be
- * stored under the key "value". This method does not do checking or
- * validation of the parameters. It only converts the cookie string into
- * a JSONObject. All attribute names are converted to lower case keys in the
- * JSONObject (HttpOnly => httponly). If an attribute is specified more than
- * once, only the value found closer to the end of the cookie-string is kept.
- * @param string The cookie specification string.
- * @return A JSONObject containing "name", "value", and possibly other
- * members.
- * @throws JSONException If there is an error parsing the Cookie String.
- * Cookie strings must have at least one '=' character and the 'name'
- * portion of the cookie must not be blank.
- */
- public static JSONObject toJSONObject(String string) {
- final JSONObject jo = new JSONObject();
- String name;
- Object value;
-
-
- JSONTokener x = new JSONTokener(string);
-
- name = unescape(x.nextTo('=').trim());
- //per RFC6265, if the name is blank, the cookie should be ignored.
- if("".equals(name)) {
- throw new JSONException("Cookies must have a 'name'");
- }
- jo.put("name", name);
- // per RFC6265, if there is no '=', the cookie should be ignored.
- // the 'next' call here throws an exception if the '=' is not found.
- x.next('=');
- jo.put("value", unescape(x.nextTo(';')).trim());
- // discard the ';'
- x.next();
- // parse the remaining cookie attributes
- while (x.more()) {
- name = unescape(x.nextTo("=;")).trim().toLowerCase(Locale.ROOT);
- // don't allow a cookies attributes to overwrite its name or value.
- if("name".equalsIgnoreCase(name)) {
- throw new JSONException("Illegal attribute name: 'name'");
- }
- if("value".equalsIgnoreCase(name)) {
- throw new JSONException("Illegal attribute name: 'value'");
- }
- // check to see if it's a flag property
- if (x.next() != '=') {
- value = Boolean.TRUE;
- } else {
- value = unescape(x.nextTo(';')).trim();
- x.next();
- }
- // only store non-blank attributes
- if(!"".equals(name) && !"".equals(value)) {
- jo.put(name, value);
- }
- }
- return jo;
- }
-
-
- /**
- * Convert a JSONObject into a cookie specification string. The JSONObject
- * must contain "name" and "value" members (case insensitive).
- * If the JSONObject contains other members, they will be appended to the cookie
- * specification string. User-Agents are instructed to ignore unknown attributes,
- * so ensure your JSONObject is using only known attributes.
- * See also: https://tools.ietf.org/html/rfc6265
- * @param jo A JSONObject
- * @return A cookie specification string
- * @throws JSONException thrown if the cookie has no name.
- */
- public static String toString(JSONObject jo) throws JSONException {
- StringBuilder sb = new StringBuilder();
-
- String name = null;
- Object value = null;
- for(String key : jo.keySet()){
- if("name".equalsIgnoreCase(key)) {
- name = jo.getString(key).trim();
- }
- if("value".equalsIgnoreCase(key)) {
- value=jo.getString(key).trim();
- }
- if(name != null && value != null) {
- break;
- }
- }
-
- if(name == null || "".equals(name.trim())) {
- throw new JSONException("Cookie does not have a name");
- }
- if(value == null) {
- value = "";
- }
-
- sb.append(escape(name));
- sb.append("=");
- sb.append(escape((String)value));
-
- for(String key : jo.keySet()){
- if("name".equalsIgnoreCase(key)
- || "value".equalsIgnoreCase(key)) {
- // already processed above
- continue;
- }
- value = jo.opt(key);
- if(value instanceof Boolean) {
- if(Boolean.TRUE.equals(value)) {
- sb.append(';').append(escape(key));
- }
- // don't emit false values
- } else {
- sb.append(';')
- .append(escape(key))
- .append('=')
- .append(escape(value.toString()));
- }
- }
-
- return sb.toString();
- }
-
- /**
- * Convert %hh sequences to single characters, and
- * convert plus to space.
- * @param string A string that may contain
- * + (plus) and
- * %hh sequences.
- * @return The unescaped string.
- */
- public static String unescape(String string) {
- int length = string.length();
- StringBuilder sb = new StringBuilder(length);
- for (int i = 0; i < length; ++i) {
- char c = string.charAt(i);
- if (c == '+') {
- c = ' ';
- } else if (c == '%' && i + 2 < length) {
- int d = JSONTokener.dehexchar(string.charAt(i + 1));
- int e = JSONTokener.dehexchar(string.charAt(i + 2));
- if (d >= 0 && e >= 0) {
- c = (char)(d * 16 + e);
- i += 2;
- }
- }
- sb.append(c);
- }
- return sb.toString();
- }
-}
diff --git a/src/main/java/org/json/CookieList.java b/src/main/java/org/json/CookieList.java
deleted file mode 100644
index ce47aee02..000000000
--- a/src/main/java/org/json/CookieList.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.json;
-
-/*
-Public Domain.
- */
-
-/**
- * Convert a web browser cookie list string to a JSONObject and back.
- * @author JSON.org
- * @version 2015-12-09
- */
-public class CookieList {
-
- /**
- * Constructs a new CookieList object.
- * @deprecated (Utility class cannot be instantiated)
- */
- @Deprecated
- public CookieList() {
- }
-
- /**
- * Convert a cookie list into a JSONObject. A cookie list is a sequence
- * of name/value pairs. The names are separated from the values by '='.
- * The pairs are separated by ';'. The names and the values
- * will be unescaped, possibly converting '+' and '%' sequences.
- *
- * To add a cookie to a cookie list,
- * cookielistJSONObject.put(cookieJSONObject.getString("name"),
- * cookieJSONObject.getString("value"));
- * @param string A cookie list string
- * @return A JSONObject
- * @throws JSONException if a called function fails
- */
- public static JSONObject toJSONObject(String string) throws JSONException {
- JSONObject jo = new JSONObject();
- JSONTokener x = new JSONTokener(string);
- while (x.more()) {
- String name = Cookie.unescape(x.nextTo('='));
- x.next('=');
- jo.put(name, Cookie.unescape(x.nextTo(';')));
- x.next();
- }
- return jo;
- }
-
- /**
- * Convert a JSONObject into a cookie list. A cookie list is a sequence
- * of name/value pairs. The names are separated from the values by '='.
- * The pairs are separated by ';'. The characters '%', '+', '=', and ';'
- * in the names and values are replaced by "%hh".
- * @param jo A JSONObject
- * @return A cookie list string
- * @throws JSONException if a called function fails
- */
- public static String toString(JSONObject jo) throws JSONException {
- boolean isEndOfPair = false;
- final StringBuilder sb = new StringBuilder();
- // Don't use the new entrySet API to maintain Android support
- for (final String key : jo.keySet()) {
- final Object value = jo.opt(key);
- if (!JSONObject.NULL.equals(value)) {
- if (isEndOfPair) {
- sb.append(';');
- }
- sb.append(Cookie.escape(key));
- sb.append("=");
- sb.append(Cookie.escape(value.toString()));
- isEndOfPair = true;
- }
- }
- return sb.toString();
- }
-}
diff --git a/src/main/java/org/json/HTTP.java b/src/main/java/org/json/HTTP.java
deleted file mode 100644
index 44ab3a6d3..000000000
--- a/src/main/java/org/json/HTTP.java
+++ /dev/null
@@ -1,148 +0,0 @@
-package org.json;
-
-/*
-Public Domain.
-*/
-
-import java.util.Locale;
-
-/**
- * Convert an HTTP header to a JSONObject and back.
- * @author JSON.org
- * @version 2015-12-09
- */
-public class HTTP {
-
- /**
- * Constructs a new HTTP object.
- */
- public HTTP() {
- }
-
- /** Carriage return/line feed. */
- public static final String CRLF = "\r\n";
-
- /**
- * Convert an HTTP header string into a JSONObject. It can be a request
- * header or a response header. A request header will contain
- *
{
- * Method: "POST" (for example),
- * "Request-URI": "/" (for example),
- * "HTTP-Version": "HTTP/1.1" (for example)
- * }
- * A response header will contain
- * {
- * "HTTP-Version": "HTTP/1.1" (for example),
- * "Status-Code": "200" (for example),
- * "Reason-Phrase": "OK" (for example)
- * }
- * In addition, the other parameters in the header will be captured, using
- * the HTTP field names as JSON names, so that {@code
- * Date: Sun, 26 May 2002 18:06:04 GMT
- * Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
- * Cache-Control: no-cache}
- * become
- * {@code
- * Date: "Sun, 26 May 2002 18:06:04 GMT",
- * Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
- * "Cache-Control": "no-cache",
- * ...}
- * It does no further checking or conversion. It does not parse dates.
- * It does not do '%' transforms on URLs.
- * @param string An HTTP header string.
- * @return A JSONObject containing the elements and attributes
- * of the XML string.
- * @throws JSONException if a called function fails
- */
- public static JSONObject toJSONObject(String string) throws JSONException {
- JSONObject jo = new JSONObject();
- HTTPTokener x = new HTTPTokener(string);
- String token;
-
- token = x.nextToken();
- if (token.toUpperCase(Locale.ROOT).startsWith("HTTP")) {
-
-// Response
-
- jo.put("HTTP-Version", token);
- jo.put("Status-Code", x.nextToken());
- jo.put("Reason-Phrase", x.nextTo('\0'));
- x.next();
-
- } else {
-
-// Request
-
- jo.put("Method", token);
- jo.put("Request-URI", x.nextToken());
- jo.put("HTTP-Version", x.nextToken());
- }
-
-// Fields
-
- while (x.more()) {
- String name = x.nextTo(':');
- x.next(':');
- jo.put(name, x.nextTo('\0'));
- x.next();
- }
- return jo;
- }
-
-
- /**
- * Convert a JSONObject into an HTTP header. A request header must contain
- * {
- * Method: "POST" (for example),
- * "Request-URI": "/" (for example),
- * "HTTP-Version": "HTTP/1.1" (for example)
- * }
- * A response header must contain
- * {
- * "HTTP-Version": "HTTP/1.1" (for example),
- * "Status-Code": "200" (for example),
- * "Reason-Phrase": "OK" (for example)
- * }
- * Any other members of the JSONObject will be output as HTTP fields.
- * The result will end with two CRLF pairs.
- * @param jo A JSONObject
- * @return An HTTP header string.
- * @throws JSONException if the object does not contain enough
- * information.
- */
- public static String toString(JSONObject jo) throws JSONException {
- StringBuilder sb = new StringBuilder();
- if (jo.has("Status-Code") && jo.has("Reason-Phrase")) {
- sb.append(jo.getString("HTTP-Version"));
- sb.append(' ');
- sb.append(jo.getString("Status-Code"));
- sb.append(' ');
- sb.append(jo.getString("Reason-Phrase"));
- } else if (jo.has("Method") && jo.has("Request-URI")) {
- sb.append(jo.getString("Method"));
- sb.append(' ');
- sb.append('"');
- sb.append(jo.getString("Request-URI"));
- sb.append('"');
- sb.append(' ');
- sb.append(jo.getString("HTTP-Version"));
- } else {
- throw new JSONException("Not enough material for an HTTP header.");
- }
- sb.append(CRLF);
- // Don't use the new entrySet API to maintain Android support
- for (final String key : jo.keySet()) {
- String value = jo.optString(key);
- if (!"HTTP-Version".equals(key) && !"Status-Code".equals(key) &&
- !"Reason-Phrase".equals(key) && !"Method".equals(key) &&
- !"Request-URI".equals(key) && !JSONObject.NULL.equals(value)) {
- sb.append(key);
- sb.append(": ");
- sb.append(jo.optString(key));
- sb.append(CRLF);
- }
- }
- sb.append(CRLF);
- return sb.toString();
- }
-}
diff --git a/src/main/java/org/json/HTTPTokener.java b/src/main/java/org/json/HTTPTokener.java
deleted file mode 100644
index 48cad31a3..000000000
--- a/src/main/java/org/json/HTTPTokener.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package org.json;
-
-/*
-Public Domain.
-*/
-
-/**
- * The HTTPTokener extends the JSONTokener to provide additional methods
- * for the parsing of HTTP headers.
- * @author JSON.org
- * @version 2015-12-09
- */
-public class HTTPTokener extends JSONTokener {
-
- /**
- * Construct an HTTPTokener from a string.
- * @param string A source string.
- */
- public HTTPTokener(String string) {
- super(string);
- }
-
-
- /**
- * Get the next token or string. This is used in parsing HTTP headers.
- * @return A String.
- * @throws JSONException if a syntax error occurs
- */
- public String nextToken() throws JSONException {
- char c;
- char q;
- StringBuilder sb = new StringBuilder();
- do {
- c = next();
- } while (Character.isWhitespace(c));
- if (c == '"' || c == '\'') {
- q = c;
- for (;;) {
- c = next();
- if (c < ' ') {
- throw syntaxError("Unterminated string.");
- }
- if (c == q) {
- return sb.toString();
- }
- sb.append(c);
- }
- }
- for (;;) {
- if (c == 0 || Character.isWhitespace(c)) {
- return sb.toString();
- }
- sb.append(c);
- c = next();
- }
- }
-}
diff --git a/src/main/java/org/json/JSONArray.java b/src/main/java/org/json/JSONArray.java
index 2a3c553a6..b1226b44f 100644
--- a/src/main/java/org/json/JSONArray.java
+++ b/src/main/java/org/json/JSONArray.java
@@ -5,6 +5,7 @@
*/
import java.io.IOException;
+import java.io.UncheckedIOException;
import java.io.Writer;
import java.lang.reflect.Array;
import java.math.BigDecimal;
@@ -71,7 +72,7 @@ public class JSONArray implements Iterable