/*
* Copyright (C) 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ahsh1688.zhengshi.google.gson.stream;
import com.ahsh1688.zhengshi.google.gson.internal.JsonReaderInternalAccess;
import com.ahsh1688.zhengshi.google.gson.internal.bind.JsonTreeReader;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.Reader;
/**
* Reads a JSON (<a href="http://www.ietf.org/rfc/rfc7159.txt">RFC 7159</a>)
* encoded value as a stream of tokens. This stream includes both literal
* values (strings, numbers, booleans, and nulls) as well as the begin and
* end delimiters of objects and arrays. The tokens are traversed in
* depth-first order, the same order that they appear in the JSON document.
* Within JSON objects, name/value pairs are represented by a single token.
*
* <h3>Parsing JSON</h3>
* To create a recursive descent parser for your own JSON streams, first create
* an entry point method that creates a {@code JsonReader}.
*
* <p>Next, create handler methods for each structure in your JSON text. You'll
* need a method for each object type and for each array type.
* <ul>
* <li>Within <strong>array handling</strong> methods, first call {@link
* #beginArray} to consume the array's opening bracket. Then create a
* while loop that accumulates values, terminating when {@link #hasNext}
* is false. Finally, read the array's closing bracket by calling {@link
* #endArray}.
* <li>Within <strong>object handling</strong> methods, first call {@link
* #beginObject} to consume the object's opening brace. Then create a
* while loop that assigns values to local variables based on their name.
* This loop should terminate when {@link #hasNext} is false. Finally,
* read the object's closing brace by calling {@link #endObject}.
* </ul>
* <p>When a nested object or array is encountered, delegate to the
* corresponding handler method.
*
* <p>When an unknown name is encountered, strict parsers should fail with an
* exception. Lenient parsers should call {@link #skipValue()} to recursively
* skip the value's nested tokens, which may otherwise conflict.
*
* <p>If a value may be null, you should first check using {@link #peek()}.
* Null literals can be consumed using either {@link #nextNull()} or {@link
* #skipValue()}.
*
* <h3>Example</h3>
* Suppose we'd like to parse a stream of messages such as the following: <pre> {@code
* [
* {
* "id": 912345678901,
* "text": "How do I read a JSON stream in Java?",
* "geo": null,
* "user": {
* "name": "json_newb",
* "followers_count": 41
* }
* },
* {
* "id": 912345678902,
* "text": "@json_newb just use JsonReader!",
* "geo": [50.454722, -104.606667],
* "user": {
* "name": "jesse",
* "followers_count": 2
* }
* }
* ]}</pre>
* This code implements the parser for the above structure: <pre> {@code
*
* public List<Message> readJsonStream(InputStream in) throws IOException {
* JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
* try {
* return readMessagesArray(reader);
* } finally {
* reader.close();
* }
* }
*
* public List<Message> readMessagesArray(JsonReader reader) throws IOException {
* List<Message> messages = new ArrayList<Message>();
*
* reader.beginArray();
* while (reader.hasNext()) {
* messages.add(readMessage(reader));
* }
* reader.endArray();
* return messages;
* }
*
* public Message readMessage(JsonReader reader) throws IOException {
* long id = -1;
* String text = null;
* User user = null;
* List<Double> geo = null;
*
* reader.beginObject();
* while (reader.hasNext()) {
* String name = reader.nextName();
* if (name.equals("id")) {
* id = reader.nextLong();
* } else if (name.equals("text")) {
* text = reader.nextString();
* } else if (name.equals("geo") && reader.peek() != JsonToken.NULL) {
* geo = readDoublesArray(reader);
* } else if (name.equals("user")) {
* user = readUser(reader);
* } else {
* reader.skipValue();
* }
* }
* reader.endObject();
* return new Message(id, text, user, geo);
* }
*
* public List<Double> readDoublesArray(JsonReader reader) throws IOException {
* List<Double> doubles = new ArrayList<Double>();
*
* reader.beginArray();
* while (reader.hasNext()) {
* doubles.add(reader.nextDouble());
* }
* reader.endArray();
* return doubles;
* }
*
* public User readUser(JsonReader reader) throws IOException {
* String username = null;
* int followersCount = -1;
*
* reader.beginObject();
* while (reader.hasNext()) {
* String name = reader.nextName();
* if (name.equals("name")) {
* username = reader.nextString();
* } else if (name.equals("followers_count")) {
* followersCount = reader.nextInt();
* } else {
* reader.skipValue();
* }
* }
* reader.endObject();
* return new User(username, followersCount);
* }}</pre>
*
* <h3>Number Handling</h3>
* This reader permits numeric values to be read as strings and string values to
* be read as numbers. For example, both elements of the JSON array {@code
* [1, "1"]} may be read using either {@link #nextInt} or {@link #nextString}.
* This behavior is intended to prevent lossy numeric conversions: double is
* JavaScript's only numeric type and very large values like {@code
* 9007199254740993} cannot be represented exactly on that platform. To minimize
* precision loss, extremely large values should be written and read as strings
* in JSON.
*
* <a name="nonexecuteprefix"/><h3>Non-Execute Prefix</h3>
* Web servers that serve private data using JSON may be vulnerable to <a
* href="http://en.wikipedia.org/wiki/JSON#Cross-site_request_forgery">Cross-site
* request forgery</a> attacks. In such an attack, a malicious site gains access
* to a private JSON file by executing it with an HTML {@code <script>} tag.
*
* <p>Prefixing JSON files with <code>")]}'\n"</code> makes them non-executable
* by {@code <script>} tags, disarming the attack. Since the prefix is malformed
* JSON, strict parsing fails when it is encountered. This class permits the
* non-execute prefix when {@link #setLenient(boolean) lenient parsing} is
* enabled.
*
* <p>Each {@code JsonReader} may be used to read a single JSON stream. Instances
* of this class are not thread safe.
*
* @author Jesse Wilson
* @since 1.6
*/
public class JsonReader implements Closeable {
/** The only non-execute prefix this parser permits */
private static final char[] NON_EXECUTE_PREFIX = ")]}'\n".toCharArray();
private static final long MIN_INCOMPLETE_INTEGER = Long.MIN_VALUE / 10;
private static final int PEEKED_NONE = 0;
private static final int PEEKED_BEGIN_OBJECT = 1;
private static final int PEEKED_END_OBJECT = 2;
private static final int PEEKED_BEGIN_ARRAY = 3;
private static final int PEEKED_END_ARRAY = 4;
private static final int PEEKED_TRUE = 5;
private static final int PEEKED_FALSE = 6;
private static final int PEEKED_NULL = 7;
private static final int PEEKED_SINGLE_QUOTED = 8;
private static final int PEEKED_DOUBLE_QUOTED = 9;
private s
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
臻识车牌识别在行业内首先,特别在门禁、停车场等场景中应用。因工作需要,公司将车牌识别集成到linux环境下使用,思考许久臻识车牌识别相机在linux环境下有好几种方式提供识别结果,有http推磅,有rtsp视频,综合考虑,推送性能最佳,所以选择了使用http创建server监听,然后通过相机的http post推送接收车牌识别结果。
资源推荐
资源详情
资源评论
收起资源包目录
臻识车牌识别TcpForJava推送 (107个子文件)
.gitignore 395B
jgoodies-forms-javadoc.jar 418KB
jgoodies-common-javadoc.jar 224KB
jgoodies-forms-sources.jar 160KB
jgoodies-forms.jar 116KB
jgoodies-common-sources.jar 71KB
intellij_forms_rt.jar 58KB
TableLayout-javadoc.jar 47KB
jgoodies-common.jar 35KB
TableLayout-src.jar 23KB
TableLayout.jar 10KB
JsonReader.java 49KB
Gson.java 41KB
TypeAdapters.java 30KB
LinkedHashTreeMap.java 25KB
GsonBuilder.java 24KB
Convert.java 24KB
$Gson$Types.java 20KB
JsonWriter.java 18KB
LinkedTreeMap.java 17KB
StringUtils.java 14KB
ISO8601Utils.java 14KB
JsonArray.java 12KB
JsonElement.java 12KB
Cameral.java 11KB
TypeAdapter.java 11KB
TypeToken.java 10KB
JsonPrimitive.java 10KB
JsonTreeReader.java 10KB
MapTypeAdapterFactory.java 9KB
ReflectiveTypeAdapterFactory.java 9KB
ConstructorConstructor.java 8KB
Excluder.java 7KB
JsonObject.java 6KB
TypeAdapterFactory.java 6KB
TreeTypeAdapter.java 6KB
JsonTreeWriter.java 6KB
FieldNamingPolicy.java 6KB
MyBatisConfig.java 5KB
LoginWindow.java 5KB
MeterSerialComm.java 4KB
FieldAttributes.java 4KB
UnsafeAllocator.java 4KB
ExclusionStrategy.java 4KB
Primitives.java 4KB
DefaultDateTypeAdapter.java 4KB
JsonStreamParser.java 4KB
TblUserinfoController.java 4KB
InstanceCreator.java 4KB
CollectionTypeAdapterFactory.java 4KB
JsonDeserializer.java 4KB
Streams.java 4KB
JsonAdapter.java 3KB
Expose.java 3KB
JsonSerializer.java 3KB
ArrayTypeAdapter.java 3KB
JsonAdapterAnnotationTypeAdapterFactory.java 3KB
StrFormatter.java 3KB
DateTypeAdapter.java 3KB
SerializedName.java 3KB
JsonParser.java 3KB
TypeAdapterRuntimeTypeWrapper.java 3KB
ObjectTypeAdapter.java 3KB
Constants.java 3KB
TblUserinfo.java 3KB
SqlDateTypeAdapter.java 3KB
Until.java 3KB
TimeTypeAdapter.java 3KB
JsonParseException.java 2KB
LazilyParsedNumber.java 2KB
CharsetKit.java 2KB
Since.java 2KB
JsonToken.java 2KB
SerialPortManager.java 2KB
JsonScope.java 2KB
JsonSerializationContext.java 2KB
LongSerializationPolicy.java 2KB
TblUserinfoServiceImpl.java 2KB
JsonDeserializationContext.java 2KB
MalformedJsonException.java 2KB
JsonNull.java 1KB
ZhengshiApplication.java 1KB
JsonSyntaxException.java 1KB
JsonIOException.java 1KB
$Gson$Preconditions.java 1KB
FieldNamingStrategy.java 1KB
JsonReaderInternalAccess.java 1KB
ObjectConstructor.java 1KB
PageResult.java 661B
TblUserinfoMapper.java 580B
TblUserinfoService.java 528B
package-info.java 465B
package-info.java 296B
ZhengshiApplicationTests.java 224B
package-info.java 195B
package-info.java 192B
LoginWindow.jfd 3KB
MANIFEST.MF 77B
loginface.png 196KB
logo.png 111KB
共 107 条
- 1
- 2
资源评论
文都龙哥
- 粉丝: 14
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功