35 | * A JSONStringer instance provides a value method for appending
36 | * values to the
37 | * text, and a key
38 | * method for adding keys before values in objects. There are array
39 | * and endArray methods that make and bound array values, and
40 | * object and endObject methods which make and bound
41 | * object values. All of these methods return the JSONWriter instance,
42 | * permitting cascade style. For example,
51 | * The first method called must be array or object.
52 | * There are no methods for adding commas or colons. JSONStringer adds them for
53 | * you. Objects and arrays can be nested up to 20 levels deep.
54 | *
55 | * This can sometimes be easier than using a JSONObject to build a string.
56 | * @author JSON.org
57 | * @version 2008-09-18
58 | */
59 | public class JSONStringer extends JSONWriter {
60 | /**
61 | * Make a fresh JSONStringer. It can be used to build one JSON text.
62 | */
63 | public JSONStringer() {
64 | super(new StringWriter());
65 | }
66 |
67 | /**
68 | * Return the JSON text. This method is used to obtain the product of the
69 | * JSONStringer instance. It will return null if there was a
70 | * problem in the construction of the JSON text (such as the calls to
71 | * array were not properly balanced with calls to
72 | * endArray).
73 | * @return The JSON text.
74 | */
75 | public String toString() {
76 | return this.mode == 'd' ? this.writer.toString() : null;
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.qcloud
5 | qcloud-java-sdk
6 | jar
7 | 2.0.7
8 | qcloud-java-sdk
9 | http://www.qcloud.com
10 | Tencent Cloud Open API SDK for Java
11 |
12 | Copyright (C) Tencent Cloud
13 | All Rights Reserved.
14 |
15 | 版权所有 (C)腾讯云
16 |
17 | http://www.qcloud.com
18 |
19 |
20 | UTF-8
21 |
22 |
23 |
24 |
25 |
26 | org.apache.maven.plugins
27 | maven-compiler-plugin
28 | 2.3.2
29 |
30 | 1.6
31 | 1.6
32 | UTF-8
33 |
34 |
35 |
36 |
37 | org.apache.maven.plugins
38 | maven-jar-plugin
39 | 2.3.2
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.apache.maven.plugins
48 | maven-source-plugin
49 | 2.1
50 |
51 |
52 | attach-sources
53 |
54 | jar-no-fork
55 |
56 |
57 |
58 |
59 |
60 |
61 | org.apache.maven.plugins
62 | maven-javadoc-plugin
63 | 2.10.3
64 |
65 |
66 | attach-javadocs
67 |
68 | jar
69 |
70 |
71 |
72 |
73 | UTF-8
74 |
75 |
76 |
77 |
78 | org.apache.maven.plugins
79 | maven-gpg-plugin
80 | 1.6
81 |
82 |
83 | sign-artifacts
84 | verify
85 |
86 | sign
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 | org.sonatype.plugins
100 | nexus-staging-maven-plugin
101 | 1.6.7
102 | true
103 |
104 | ossrh
105 | https://oss.sonatype.org/
106 | true
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 | ossrh
117 | https://oss.sonatype.org/content/repositories/snapshots
118 |
119 |
120 | ossrh
121 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 | https://github.com/QcloudApi/qcloudapi-sdk-java.git
135 |
136 |
137 |
138 |
139 | alexjtxie
140 | alexjtxie
141 | alexjtxie@tencent.com
142 |
143 |
144 |
145 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Common/Request.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Common;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.DataInputStream;
5 | import java.io.DataOutputStream;
6 | import java.io.File;
7 | import java.io.FileInputStream;
8 | import java.io.InputStreamReader;
9 | import java.io.OutputStream;
10 | import java.io.UnsupportedEncodingException;
11 | import java.net.HttpURLConnection;
12 | import java.net.URL;
13 | import java.net.URLConnection;
14 | import java.net.URLEncoder;
15 | import java.util.Map;
16 | import java.util.Random;
17 | import java.util.TreeMap;
18 |
19 | import javax.net.ssl.HttpsURLConnection;
20 |
21 | import com.qcloud.Utilities.MD5;
22 |
23 | /**
24 | * 请求调用类
25 | * @author robinslsun
26 | */
27 | public class Request {
28 | protected static String requestUrl = "";
29 | protected static String rawResponse = "";
30 | protected static String version = "SDK_JAVA_2.0.7";
31 | protected static int connectTimeout = 5000; // ms
32 | protected static int readTimeout = 90000; // ms
33 |
34 | public static String getRequestUrl() {
35 | return requestUrl;
36 | }
37 |
38 | public static String getRawResponse() {
39 | return rawResponse;
40 | }
41 |
42 | public static String generateUrl(TreeMap params,
43 | String secretId, String secretKey, String requestMethod,
44 | String requestHost, String requestPath) {
45 | if (!params.containsKey("SecretId"))
46 | params.put("SecretId", secretId);
47 |
48 | if (!params.containsKey("Nonce"))
49 | params.put("Nonce",
50 | new Random().nextInt(java.lang.Integer.MAX_VALUE));
51 |
52 | if (!params.containsKey("Timestamp"))
53 | params.put("Timestamp", System.currentTimeMillis() / 1000);
54 |
55 | params.put("RequestClient", version);
56 |
57 | String plainText = Sign.makeSignPlainText(params, requestMethod,
58 | requestHost, requestPath);
59 |
60 | String signatureMethod = "HmacSHA1";
61 | if(params.containsKey("SignatureMethod") && params.get("SignatureMethod").toString().equals("HmacSHA256"))
62 | {
63 | signatureMethod = "HmacSHA256";
64 | }
65 |
66 | try {
67 | params.put("Signature", Sign.sign(plainText, secretKey, signatureMethod));
68 | } catch (Exception e) {
69 | e.printStackTrace();
70 | }
71 |
72 | StringBuilder url = new StringBuilder("https://");
73 | url.append(requestHost).append(requestPath).append("?");
74 | if (requestMethod.equals("GET")) {
75 | for ( String k : params.keySet() ) {
76 | try {
77 | url.append(k.replace("_", "."))
78 | .append("=")
79 | .append(URLEncoder.encode(params.get(k).toString(), "utf-8"))
80 | .append("&");
81 | } catch (UnsupportedEncodingException e) {
82 | // 下面是一个错误的做法。
83 | // 本应该抛出异常让上层捕获处理,但是出于保持兼容性的考虑,
84 | // 并不想让这个方法升级后抛出一个未捕获的异常。
85 | // 而且之所以会有这个异常,是因为有些特殊系统未必支持utf-8,
86 | // 在这些系统上,其实根本无法正常调用云API,
87 | // 所以可以直接忽略,返回一个无用的信息即可。
88 | return "https://" + requestHost + requestPath;
89 | }
90 | }
91 | }
92 |
93 | return url.toString().substring(0, url.length() - 1);
94 | }
95 |
96 | public static String send(TreeMap params, String secretId,
97 | String secretKey, String requestMethod, String requestHost,
98 | String requestPath, String fileName) {
99 | if (!params.containsKey("SecretId"))
100 | params.put("SecretId", secretId);
101 |
102 | if (!params.containsKey("Nonce"))
103 | params.put("Nonce",
104 | new Random().nextInt(java.lang.Integer.MAX_VALUE));
105 |
106 | if (!params.containsKey("Timestamp"))
107 | params.put("Timestamp", System.currentTimeMillis() / 1000);
108 |
109 | params.put("RequestClient", version);
110 | params.remove("Signature");
111 | String plainText = Sign.makeSignPlainText(params, requestMethod,
112 | requestHost, requestPath);
113 |
114 | String signatureMethod = "HmacSHA1";
115 | if(params.containsKey("SignatureMethod") && params.get("SignatureMethod").toString().equals("HmacSHA256"))
116 | {
117 | signatureMethod = "HmacSHA256";
118 | }
119 |
120 | try {
121 | params.put("Signature", Sign.sign(plainText, secretKey, signatureMethod));
122 | } catch (Exception e) {
123 | e.printStackTrace();
124 | }
125 |
126 | String url = "https://" + requestHost + requestPath;
127 |
128 | return sendRequest(url, params, requestMethod, fileName);
129 | }
130 |
131 | public static String sendRequest(String url,
132 | Map requestParams, String requestMethod,
133 | String fileName) {
134 | String result = "";
135 | BufferedReader in = null;
136 | String paramStr = "";
137 |
138 | for (String key : requestParams.keySet()) {
139 | if (!paramStr.isEmpty()) {
140 | paramStr += '&';
141 | }
142 | try {
143 | paramStr += key + '='
144 | + URLEncoder.encode(requestParams.get(key).toString(),"utf-8");
145 | } catch (UnsupportedEncodingException e) {
146 | result = "{\"code\":-2300,\"location\":\"com.qcloud.Common.Request:129\",\"message\":\"api sdk throw exception! "
147 | + e.toString().replace("\"", "\\\"") + "\"}";
148 | }
149 | }
150 |
151 | try {
152 |
153 | if (requestMethod.equals("GET")) {
154 | if (url.indexOf('?') > 0) {
155 | url += '&' + paramStr;
156 | } else {
157 | url += '?' + paramStr;
158 | }
159 | }
160 | requestUrl = url;
161 | String BOUNDARY = "---------------------------"
162 | + MD5.stringToMD5(
163 | String.valueOf(System.currentTimeMillis()))
164 | .substring(0, 15);
165 | URL realUrl = new URL(url);
166 | URLConnection connection = null;
167 | if (url.toLowerCase().startsWith("https")) {
168 | HttpsURLConnection httpsConn = (HttpsURLConnection) realUrl
169 | .openConnection();
170 |
171 | /*httpsConn.setHostnameVerifier(new HostnameVerifier() {
172 | public boolean verify(String hostname, SSLSession session) {
173 | return true;
174 | }
175 | });*/
176 | connection = httpsConn;
177 | } else {
178 | connection = realUrl.openConnection();
179 | }
180 |
181 | // 设置通用的请求属性
182 | connection.setRequestProperty("accept", "*/*");
183 | connection.setRequestProperty("connection", "Keep-Alive");
184 | connection.setRequestProperty("user-agent",
185 | "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
186 | // 设置链接主机超时时间
187 | connection.setConnectTimeout(connectTimeout);
188 | connection.setReadTimeout(readTimeout);
189 |
190 | if (requestMethod.equals("POST")) {
191 | ((HttpURLConnection) connection).setRequestMethod("POST");
192 | // 发送POST请求必须设置如下两行
193 | connection.setDoOutput(true);
194 | connection.setDoInput(true);
195 | connection.setRequestProperty("Content-Type",
196 | "multipart/form-data; boundary=" + BOUNDARY);
197 | OutputStream out = new DataOutputStream(
198 | connection.getOutputStream());
199 | StringBuffer strBuf = new StringBuffer();
200 | for (String key : requestParams.keySet()) {
201 | strBuf.append("\r\n").append("--").append(BOUNDARY)
202 | .append("\r\n");
203 | strBuf.append("Content-Disposition: form-data; name=\""
204 | + key + "\"\r\n\r\n");
205 | strBuf.append(requestParams.get(key));
206 | }
207 | out.write(strBuf.toString().getBytes());
208 | if (fileName != null) {
209 | File file = new File(fileName);
210 | String filename = file.getName();
211 | String contentType = URLConnection.getFileNameMap()
212 | .getContentTypeFor(fileName);
213 |
214 | strBuf = new StringBuffer();
215 | strBuf.append("\r\n").append("--").append(BOUNDARY)
216 | .append("\r\n");
217 | strBuf.append("Content-Disposition: form-data; name=\"entityFile\"; filename=\""
218 | + filename + "\"\r\n");
219 | strBuf.append("Content-Type:" + contentType + "\r\n\r\n");
220 |
221 | out.write(strBuf.toString().getBytes());
222 |
223 | DataInputStream ins = new DataInputStream(
224 | new FileInputStream(file));
225 | int bytes = 0;
226 | byte[] bufferOut = new byte[1024];
227 | while ((bytes = ins.read(bufferOut)) != -1) {
228 | out.write(bufferOut, 0, bytes);
229 | }
230 | ins.close();
231 | }
232 | byte[] endData = ("\r\n--" + BOUNDARY + "--\r\n").getBytes();
233 | out.write(endData);
234 | out.flush();
235 | out.close();
236 | }
237 |
238 | // 建立实际的连接
239 | connection.connect();
240 |
241 | // 定义 BufferedReader输入流来读取URL的响应
242 | in = new BufferedReader(new InputStreamReader(
243 | connection.getInputStream()));
244 |
245 | String line;
246 | while ((line = in.readLine()) != null) {
247 | result += line;
248 | }
249 |
250 | } catch (Exception e) {
251 | result = "{\"code\":-2700,\"location\":\"com.qcloud.Common.Request:225\",\"message\":\"api sdk throw exception! "
252 | + e.toString().replace("\"", "\\\"") + "\"}";
253 | } finally {
254 | // 使用finally块来关闭输入流
255 | try {
256 | if (in != null) {
257 | in.close();
258 | }
259 | } catch (Exception e2) {
260 | result = "{\"code\":-2800,\"location\":\"com.qcloud.Common.Request:234\",\"message\":\"api sdk throw exception! "
261 | + e2.toString().replace("\"", "\\\"") + "\"}";
262 | }
263 | }
264 | rawResponse = result;
265 | return result;
266 | }
267 | }
268 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Utilities/Json/JSONWriter.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Utilities.Json;
2 |
3 | import java.io.IOException;
4 | import java.io.Writer;
5 |
6 | /*
7 | Copyright (c) 2006 JSON.org
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
10 | of this software and associated documentation files (the "Software"), to deal
11 | in the Software without restriction, including without limitation the rights
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | copies of the Software, and to permit persons to whom the Software is
14 | furnished to do so, subject to the following conditions:
15 |
16 | The above copyright notice and this permission notice shall be included in all
17 | copies or substantial portions of the Software.
18 |
19 | The Software shall be used for Good, not Evil.
20 |
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 | SOFTWARE.
28 | */
29 |
30 | /**
31 | * JSONWriter provides a quick and convenient way of producing JSON text.
32 | * The texts produced strictly conform to JSON syntax rules. No whitespace is
33 | * added, so the results are ready for transmission or storage. Each instance of
34 | * JSONWriter can produce one JSON text.
35 | *
36 | * A JSONWriter instance provides a value method for appending
37 | * values to the
38 | * text, and a key
39 | * method for adding keys before values in objects. There are array
40 | * and endArray methods that make and bound array values, and
41 | * object and endObject methods which make and bound
42 | * object values. All of these methods return the JSONWriter instance,
43 | * permitting a cascade style. For example,
51 | * The first method called must be array or object.
52 | * There are no methods for adding commas or colons. JSONWriter adds them for
53 | * you. Objects and arrays can be nested up to 20 levels deep.
54 | *
55 | * This can sometimes be easier than using a JSONObject to build a string.
56 | * @author JSON.org
57 | * @version 2011-11-24
58 | */
59 | public class JSONWriter {
60 | private static final int maxdepth = 200;
61 |
62 | /**
63 | * The comma flag determines if a comma should be output before the next
64 | * value.
65 | */
66 | private boolean comma;
67 |
68 | /**
69 | * The current mode. Values:
70 | * 'a' (array),
71 | * 'd' (done),
72 | * 'i' (initial),
73 | * 'k' (key),
74 | * 'o' (object).
75 | */
76 | protected char mode;
77 |
78 | /**
79 | * The object/array stack.
80 | */
81 | private final JSONObject stack[];
82 |
83 | /**
84 | * The stack top index. A value of 0 indicates that the stack is empty.
85 | */
86 | private int top;
87 |
88 | /**
89 | * The writer that will receive the output.
90 | */
91 | protected Writer writer;
92 |
93 | /**
94 | * Make a fresh JSONWriter. It can be used to build one JSON text.
95 | */
96 | public JSONWriter(Writer w) {
97 | this.comma = false;
98 | this.mode = 'i';
99 | this.stack = new JSONObject[maxdepth];
100 | this.top = 0;
101 | this.writer = w;
102 | }
103 |
104 | /**
105 | * Append a value.
106 | * @param string A string value.
107 | * @return this
108 | * @throws JSONException If the value is out of sequence.
109 | */
110 | private JSONWriter append(String string) throws JSONException {
111 | if (string == null) {
112 | throw new JSONException("Null pointer");
113 | }
114 | if (this.mode == 'o' || this.mode == 'a') {
115 | try {
116 | if (this.comma && this.mode == 'a') {
117 | this.writer.write(',');
118 | }
119 | this.writer.write(string);
120 | } catch (IOException e) {
121 | throw new JSONException(e);
122 | }
123 | if (this.mode == 'o') {
124 | this.mode = 'k';
125 | }
126 | this.comma = true;
127 | return this;
128 | }
129 | throw new JSONException("Value out of sequence.");
130 | }
131 |
132 | /**
133 | * Begin appending a new array. All values until the balancing
134 | * endArray will be appended to this array. The
135 | * endArray method must be called to mark the array's end.
136 | * @return this
137 | * @throws JSONException If the nesting is too deep, or if the object is
138 | * started in the wrong place (for example as a key or after the end of the
139 | * outermost array or object).
140 | */
141 | public JSONWriter array() throws JSONException {
142 | if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') {
143 | this.push(null);
144 | this.append("[");
145 | this.comma = false;
146 | return this;
147 | }
148 | throw new JSONException("Misplaced array.");
149 | }
150 |
151 | /**
152 | * End something.
153 | * @param mode Mode
154 | * @param c Closing character
155 | * @return this
156 | * @throws JSONException If unbalanced.
157 | */
158 | private JSONWriter end(char mode, char c) throws JSONException {
159 | if (this.mode != mode) {
160 | throw new JSONException(mode == 'a'
161 | ? "Misplaced endArray."
162 | : "Misplaced endObject.");
163 | }
164 | this.pop(mode);
165 | try {
166 | this.writer.write(c);
167 | } catch (IOException e) {
168 | throw new JSONException(e);
169 | }
170 | this.comma = true;
171 | return this;
172 | }
173 |
174 | /**
175 | * End an array. This method most be called to balance calls to
176 | * array.
177 | * @return this
178 | * @throws JSONException If incorrectly nested.
179 | */
180 | public JSONWriter endArray() throws JSONException {
181 | return this.end('a', ']');
182 | }
183 |
184 | /**
185 | * End an object. This method most be called to balance calls to
186 | * object.
187 | * @return this
188 | * @throws JSONException If incorrectly nested.
189 | */
190 | public JSONWriter endObject() throws JSONException {
191 | return this.end('k', '}');
192 | }
193 |
194 | /**
195 | * Append a key. The key will be associated with the next value. In an
196 | * object, every value must be preceded by a key.
197 | * @param string A key string.
198 | * @return this
199 | * @throws JSONException If the key is out of place. For example, keys
200 | * do not belong in arrays or if the key is null.
201 | */
202 | public JSONWriter key(String string) throws JSONException {
203 | if (string == null) {
204 | throw new JSONException("Null key.");
205 | }
206 | if (this.mode == 'k') {
207 | try {
208 | this.stack[this.top - 1].putOnce(string, Boolean.TRUE);
209 | if (this.comma) {
210 | this.writer.write(',');
211 | }
212 | this.writer.write(JSONObject.quote(string));
213 | this.writer.write(':');
214 | this.comma = false;
215 | this.mode = 'o';
216 | return this;
217 | } catch (IOException e) {
218 | throw new JSONException(e);
219 | }
220 | }
221 | throw new JSONException("Misplaced key.");
222 | }
223 |
224 |
225 | /**
226 | * Begin appending a new object. All keys and values until the balancing
227 | * endObject will be appended to this object. The
228 | * endObject method must be called to mark the object's end.
229 | * @return this
230 | * @throws JSONException If the nesting is too deep, or if the object is
231 | * started in the wrong place (for example as a key or after the end of the
232 | * outermost array or object).
233 | */
234 | public JSONWriter object() throws JSONException {
235 | if (this.mode == 'i') {
236 | this.mode = 'o';
237 | }
238 | if (this.mode == 'o' || this.mode == 'a') {
239 | this.append("{");
240 | this.push(new JSONObject());
241 | this.comma = false;
242 | return this;
243 | }
244 | throw new JSONException("Misplaced object.");
245 |
246 | }
247 |
248 |
249 | /**
250 | * Pop an array or object scope.
251 | * @param c The scope to close.
252 | * @throws JSONException If nesting is wrong.
253 | */
254 | private void pop(char c) throws JSONException {
255 | if (this.top <= 0) {
256 | throw new JSONException("Nesting error.");
257 | }
258 | char m = this.stack[this.top - 1] == null ? 'a' : 'k';
259 | if (m != c) {
260 | throw new JSONException("Nesting error.");
261 | }
262 | this.top -= 1;
263 | this.mode = this.top == 0
264 | ? 'd'
265 | : this.stack[this.top - 1] == null
266 | ? 'a'
267 | : 'k';
268 | }
269 |
270 | /**
271 | * Push an array or object scope.
272 | * @param jo The scope to open.
273 | * @throws JSONException If nesting is too deep.
274 | */
275 | private void push(JSONObject jo) throws JSONException {
276 | if (this.top >= maxdepth) {
277 | throw new JSONException("Nesting too deep.");
278 | }
279 | this.stack[this.top] = jo;
280 | this.mode = jo == null ? 'a' : 'k';
281 | this.top += 1;
282 | }
283 |
284 |
285 | /**
286 | * Append either the value true or the value
287 | * false.
288 | * @param b A boolean.
289 | * @return this
290 | * @throws JSONException
291 | */
292 | public JSONWriter value(boolean b) throws JSONException {
293 | return this.append(b ? "true" : "false");
294 | }
295 |
296 | /**
297 | * Append a double value.
298 | * @param d A double.
299 | * @return this
300 | * @throws JSONException If the number is not finite.
301 | */
302 | public JSONWriter value(double d) throws JSONException {
303 | return this.value(new Double(d));
304 | }
305 |
306 | /**
307 | * Append a long value.
308 | * @param l A long.
309 | * @return this
310 | * @throws JSONException
311 | */
312 | public JSONWriter value(long l) throws JSONException {
313 | return this.append(Long.toString(l));
314 | }
315 |
316 |
317 | /**
318 | * Append an object value.
319 | * @param object The object to append. It can be null, or a Boolean, Number,
320 | * String, JSONObject, or JSONArray, or an object that implements JSONString.
321 | * @return this
322 | * @throws JSONException If the value is out of sequence.
323 | */
324 | public JSONWriter value(Object object) throws JSONException {
325 | return this.append(JSONObject.valueToString(object));
326 | }
327 | }
328 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Utilities/Json/JSONTokener.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Utilities.Json;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 | import java.io.Reader;
8 | import java.io.StringReader;
9 |
10 | /*
11 | Copyright (c) 2002 JSON.org
12 |
13 | Permission is hereby granted, free of charge, to any person obtaining a copy
14 | of this software and associated documentation files (the "Software"), to deal
15 | in the Software without restriction, including without limitation the rights
16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 | copies of the Software, and to permit persons to whom the Software is
18 | furnished to do so, subject to the following conditions:
19 |
20 | The above copyright notice and this permission notice shall be included in all
21 | copies or substantial portions of the Software.
22 |
23 | The Software shall be used for Good, not Evil.
24 |
25 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 | SOFTWARE.
32 | */
33 |
34 | /**
35 | * A JSONTokener takes a source string and extracts characters and tokens from
36 | * it. It is used by the JSONObject and JSONArray constructors to parse
37 | * JSON source strings.
38 | * @author JSON.org
39 | * @version 2014-05-03
40 | */
41 | public class JSONTokener {
42 |
43 | private long character;
44 | private boolean eof;
45 | private long index;
46 | private long line;
47 | private char previous;
48 | private Reader reader;
49 | private boolean usePrevious;
50 |
51 |
52 | /**
53 | * Construct a JSONTokener from a Reader.
54 | *
55 | * @param reader A reader.
56 | */
57 | public JSONTokener(Reader reader) {
58 | this.reader = reader.markSupported()
59 | ? reader
60 | : new BufferedReader(reader);
61 | this.eof = false;
62 | this.usePrevious = false;
63 | this.previous = 0;
64 | this.index = 0;
65 | this.character = 1;
66 | this.line = 1;
67 | }
68 |
69 |
70 | /**
71 | * Construct a JSONTokener from an InputStream.
72 | * @param inputStream The source.
73 | */
74 | public JSONTokener(InputStream inputStream) throws JSONException {
75 | this(new InputStreamReader(inputStream));
76 | }
77 |
78 |
79 | /**
80 | * Construct a JSONTokener from a string.
81 | *
82 | * @param s A source string.
83 | */
84 | public JSONTokener(String s) {
85 | this(new StringReader(s));
86 | }
87 |
88 |
89 | /**
90 | * Back up one character. This provides a sort of lookahead capability,
91 | * so that you can test for a digit or letter before attempting to parse
92 | * the next number or identifier.
93 | */
94 | public void back() throws JSONException {
95 | if (this.usePrevious || this.index <= 0) {
96 | throw new JSONException("Stepping back two steps is not supported");
97 | }
98 | this.index -= 1;
99 | this.character -= 1;
100 | this.usePrevious = true;
101 | this.eof = false;
102 | }
103 |
104 |
105 | /**
106 | * Get the hex value of a character (base16).
107 | * @param c A character between '0' and '9' or between 'A' and 'F' or
108 | * between 'a' and 'f'.
109 | * @return An int between 0 and 15, or -1 if c was not a hex digit.
110 | */
111 | public static int dehexchar(char c) {
112 | if (c >= '0' && c <= '9') {
113 | return c - '0';
114 | }
115 | if (c >= 'A' && c <= 'F') {
116 | return c - ('A' - 10);
117 | }
118 | if (c >= 'a' && c <= 'f') {
119 | return c - ('a' - 10);
120 | }
121 | return -1;
122 | }
123 |
124 | public boolean end() {
125 | return this.eof && !this.usePrevious;
126 | }
127 |
128 |
129 | /**
130 | * Determine if the source string still contains characters that next()
131 | * can consume.
132 | * @return true if not yet at the end of the source.
133 | */
134 | public boolean more() throws JSONException {
135 | this.next();
136 | if (this.end()) {
137 | return false;
138 | }
139 | this.back();
140 | return true;
141 | }
142 |
143 |
144 | /**
145 | * Get the next character in the source string.
146 | *
147 | * @return The next character, or 0 if past the end of the source string.
148 | */
149 | public char next() throws JSONException {
150 | int c;
151 | if (this.usePrevious) {
152 | this.usePrevious = false;
153 | c = this.previous;
154 | } else {
155 | try {
156 | c = this.reader.read();
157 | } catch (IOException exception) {
158 | throw new JSONException(exception);
159 | }
160 |
161 | if (c <= 0) { // End of stream
162 | this.eof = true;
163 | c = 0;
164 | }
165 | }
166 | this.index += 1;
167 | if (this.previous == '\r') {
168 | this.line += 1;
169 | this.character = c == '\n' ? 0 : 1;
170 | } else if (c == '\n') {
171 | this.line += 1;
172 | this.character = 0;
173 | } else {
174 | this.character += 1;
175 | }
176 | this.previous = (char) c;
177 | return this.previous;
178 | }
179 |
180 |
181 | /**
182 | * Consume the next character, and check that it matches a specified
183 | * character.
184 | * @param c The character to match.
185 | * @return The character.
186 | * @throws JSONException if the character does not match.
187 | */
188 | public char next(char c) throws JSONException {
189 | char n = this.next();
190 | if (n != c) {
191 | throw this.syntaxError("Expected '" + c + "' and instead saw '" +
192 | n + "'");
193 | }
194 | return n;
195 | }
196 |
197 |
198 | /**
199 | * Get the next n characters.
200 | *
201 | * @param n The number of characters to take.
202 | * @return A string of n characters.
203 | * @throws JSONException
204 | * Substring bounds error if there are not
205 | * n characters remaining in the source string.
206 | */
207 | public String next(int n) throws JSONException {
208 | if (n == 0) {
209 | return "";
210 | }
211 |
212 | char[] chars = new char[n];
213 | int pos = 0;
214 |
215 | while (pos < n) {
216 | chars[pos] = this.next();
217 | if (this.end()) {
218 | throw this.syntaxError("Substring bounds error");
219 | }
220 | pos += 1;
221 | }
222 | return new String(chars);
223 | }
224 |
225 |
226 | /**
227 | * Get the next char in the string, skipping whitespace.
228 | * @throws JSONException
229 | * @return A character, or 0 if there are no more characters.
230 | */
231 | public char nextClean() throws JSONException {
232 | for (;;) {
233 | char c = this.next();
234 | if (c == 0 || c > ' ') {
235 | return c;
236 | }
237 | }
238 | }
239 |
240 |
241 | /**
242 | * Return the characters up to the next close quote character.
243 | * Backslash processing is done. The formal JSON format does not
244 | * allow strings in single quotes, but an implementation is allowed to
245 | * accept them.
246 | * @param quote The quoting character, either
247 | * " (double quote) or
248 | * ' (single quote).
249 | * @return A String.
250 | * @throws JSONException Unterminated string.
251 | */
252 | public String nextString(char quote) throws JSONException {
253 | char c;
254 | StringBuilder sb = new StringBuilder();
255 | for (;;) {
256 | c = this.next();
257 | switch (c) {
258 | case 0:
259 | case '\n':
260 | case '\r':
261 | throw this.syntaxError("Unterminated string");
262 | case '\\':
263 | c = this.next();
264 | switch (c) {
265 | case 'b':
266 | sb.append('\b');
267 | break;
268 | case 't':
269 | sb.append('\t');
270 | break;
271 | case 'n':
272 | sb.append('\n');
273 | break;
274 | case 'f':
275 | sb.append('\f');
276 | break;
277 | case 'r':
278 | sb.append('\r');
279 | break;
280 | case 'u':
281 | sb.append((char)Integer.parseInt(this.next(4), 16));
282 | break;
283 | case '"':
284 | case '\'':
285 | case '\\':
286 | case '/':
287 | sb.append(c);
288 | break;
289 | default:
290 | throw this.syntaxError("Illegal escape.");
291 | }
292 | break;
293 | default:
294 | if (c == quote) {
295 | return sb.toString();
296 | }
297 | sb.append(c);
298 | }
299 | }
300 | }
301 |
302 |
303 | /**
304 | * Get the text up but not including the specified character or the
305 | * end of line, whichever comes first.
306 | * @param delimiter A delimiter character.
307 | * @return A string.
308 | */
309 | public String nextTo(char delimiter) throws JSONException {
310 | StringBuilder sb = new StringBuilder();
311 | for (;;) {
312 | char c = this.next();
313 | if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
314 | if (c != 0) {
315 | this.back();
316 | }
317 | return sb.toString().trim();
318 | }
319 | sb.append(c);
320 | }
321 | }
322 |
323 |
324 | /**
325 | * Get the text up but not including one of the specified delimiter
326 | * characters or the end of line, whichever comes first.
327 | * @param delimiters A set of delimiter characters.
328 | * @return A string, trimmed.
329 | */
330 | public String nextTo(String delimiters) throws JSONException {
331 | char c;
332 | StringBuilder sb = new StringBuilder();
333 | for (;;) {
334 | c = this.next();
335 | if (delimiters.indexOf(c) >= 0 || c == 0 ||
336 | c == '\n' || c == '\r') {
337 | if (c != 0) {
338 | this.back();
339 | }
340 | return sb.toString().trim();
341 | }
342 | sb.append(c);
343 | }
344 | }
345 |
346 |
347 | /**
348 | * Get the next value. The value can be a Boolean, Double, Integer,
349 | * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
350 | * @throws JSONException If syntax error.
351 | *
352 | * @return An object.
353 | */
354 | public Object nextValue() throws JSONException {
355 | char c = this.nextClean();
356 | String string;
357 |
358 | switch (c) {
359 | case '"':
360 | case '\'':
361 | return this.nextString(c);
362 | case '{':
363 | this.back();
364 | return new JSONObject(this);
365 | case '[':
366 | this.back();
367 | return new JSONArray(this);
368 | }
369 |
370 | /*
371 | * Handle unquoted text. This could be the values true, false, or
372 | * null, or it can be a number. An implementation (such as this one)
373 | * is allowed to also accept non-standard forms.
374 | *
375 | * Accumulate characters until we reach the end of the text or a
376 | * formatting character.
377 | */
378 |
379 | StringBuilder sb = new StringBuilder();
380 | while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
381 | sb.append(c);
382 | c = this.next();
383 | }
384 | this.back();
385 |
386 | string = sb.toString().trim();
387 | if ("".equals(string)) {
388 | throw this.syntaxError("Missing value");
389 | }
390 | return JSONObject.stringToValue(string);
391 | }
392 |
393 |
394 | /**
395 | * Skip characters until the next character is the requested character.
396 | * If the requested character is not found, no characters are skipped.
397 | * @param to A character to skip to.
398 | * @return The requested character, or zero if the requested character
399 | * is not found.
400 | */
401 | public char skipTo(char to) throws JSONException {
402 | char c;
403 | try {
404 | long startIndex = this.index;
405 | long startCharacter = this.character;
406 | long startLine = this.line;
407 | this.reader.mark(1000000);
408 | do {
409 | c = this.next();
410 | if (c == 0) {
411 | this.reader.reset();
412 | this.index = startIndex;
413 | this.character = startCharacter;
414 | this.line = startLine;
415 | return c;
416 | }
417 | } while (c != to);
418 | } catch (IOException exception) {
419 | throw new JSONException(exception);
420 | }
421 | this.back();
422 | return c;
423 | }
424 |
425 |
426 | /**
427 | * Make a JSONException to signal a syntax error.
428 | *
429 | * @param message The error message.
430 | * @return A JSONException object, suitable for throwing
431 | */
432 | public JSONException syntaxError(String message) {
433 | return new JSONException(message + this.toString());
434 | }
435 |
436 |
437 | /**
438 | * Make a printable string of this JSONTokener.
439 | *
440 | * @return " at {index} [character {character} line {line}]"
441 | */
442 | public String toString() {
443 | return " at " + this.index + " [character " + this.character + " line " +
444 | this.line + "]";
445 | }
446 | }
447 |
--------------------------------------------------------------------------------
/src/main/java/com/qcloud/Utilities/Json/JSONArray.java:
--------------------------------------------------------------------------------
1 | package com.qcloud.Utilities.Json;
2 |
3 | /*
4 | Copyright (c) 2002 JSON.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | The Software shall be used for Good, not Evil.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 | SOFTWARE.
25 | */
26 |
27 | import java.io.IOException;
28 | import java.io.StringWriter;
29 | import java.io.Writer;
30 | import java.lang.reflect.Array;
31 | import java.util.ArrayList;
32 | import java.util.Collection;
33 | import java.util.Iterator;
34 | import java.util.Map;
35 |
36 | /**
37 | * A JSONArray is an ordered sequence of values. Its external text form is a
38 | * string wrapped in square brackets with commas separating the values. The
39 | * internal form is an object having get and opt
40 | * methods for accessing the values by index, and put methods for
41 | * adding or replacing values. The values can be any of these types:
42 | * Boolean, JSONArray, JSONObject,
43 | * Number, String, or the
44 | * JSONObject.NULL object.
45 | *
46 | * The constructor can convert a JSON text into a Java object. The
47 | * toString method converts to JSON text.
48 | *
49 | * A get method returns a value if one can be found, and throws an
50 | * exception if one cannot be found. An opt method returns a
51 | * default value instead of throwing an exception, and so is useful for
52 | * obtaining optional values.
53 | *
54 | * The generic get() and opt() methods return an
55 | * object which you can cast or query for type. There are also typed
56 | * get and opt methods that do type checking and type
57 | * coercion for you.
58 | *
59 | * The texts produced by the toString methods strictly conform to
60 | * JSON syntax rules. The constructors are more forgiving in the texts they will
61 | * accept:
62 | *
63 | *
An extra , (comma) may appear just
64 | * before the closing bracket.
65 | *
The null value will be inserted when there is ,
66 | * (comma) elision.
67 | *
Strings may be quoted with ' (single
68 | * quote).
69 | *
Strings do not need to be quoted at all if they do not begin with a quote
70 | * or single quote, and if they do not contain leading or trailing spaces, and
71 | * if they do not contain any of these characters:
72 | * { } [ ] / \ : , # and if they do not look like numbers and
73 | * if they are not the reserved words true, false, or
74 | * null.
75 | *
76 | *
77 | * @author JSON.org
78 | * @version 2014-05-03
79 | */
80 | public class JSONArray {
81 |
82 | /**
83 | * The arrayList where the JSONArray's properties are kept.
84 | */
85 | private final ArrayList