[DMAAP-48] Initial code import
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / json / HTTPTokener.java
1 /*******************************************************************************\r
2  * ============LICENSE_START==================================================\r
3  * * org.onap.dmaap\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.json;\r
24 \r
25 /*\r
26 Copyright (c) 2002 JSON.org\r
27 \r
28 Permission is hereby granted, free of charge, to any person obtaining a copy\r
29 of this software and associated documentation files (the "Software"), to deal\r
30 in the Software without restriction, including without limitation the rights\r
31 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
32 copies of the Software, and to permit persons to whom the Software is\r
33 furnished to do so, subject to the following conditions:\r
34 \r
35 The above copyright notice and this permission notice shall be included in all\r
36 copies or substantial portions of the Software.\r
37 \r
38 The Software shall be used for Good, not Evil.\r
39 \r
40 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
41 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
42 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
43 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
44 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
45 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
46 SOFTWARE.\r
47 */\r
48 \r
49 /**\r
50  * The HTTPTokener extends the JSONTokener to provide additional methods\r
51  * for the parsing of HTTP headers.\r
52  * @author JSON.org\r
53  * @version 2012-11-13\r
54  */\r
55 public class HTTPTokener extends JSONTokener {\r
56 \r
57     /**\r
58      * Construct an HTTPTokener from a string.\r
59      * @param string A source string.\r
60      */\r
61     public HTTPTokener(String string) {\r
62         super(string);\r
63     }\r
64 \r
65 \r
66     /**\r
67      * Get the next token or string. This is used in parsing HTTP headers.\r
68      * @throws JSONException\r
69      * @return A String.\r
70      */\r
71     public String nextToken() throws JSONException {\r
72         char c;\r
73         char q;\r
74         StringBuffer sb = new StringBuffer();\r
75         do {\r
76             c = next();\r
77         } while (Character.isWhitespace(c));\r
78         if (c == '"' || c == '\'') {\r
79             q = c;\r
80             for (;;) {\r
81                 c = next();\r
82                 if (c < ' ') {\r
83                     throw syntaxError("Unterminated string.");\r
84                 }\r
85                 if (c == q) {\r
86                     return sb.toString();\r
87                 }\r
88                 sb.append(c);\r
89             }\r
90         }\r
91         for (;;) {\r
92             if (c == 0 || Character.isWhitespace(c)) {\r
93                 return sb.toString();\r
94             }\r
95             sb.append(c);\r
96             c = next();\r
97         }\r
98     }\r
99 }\r