本文整理匯總了Java中com.google.gson.stream.JsonToken.END_DOCUMENT屬性的典型用法代碼示例。如果您正苦於以下問題:Java JsonToken.END_DOCUMENT屬性的具體用法?Java JsonToken.END_DOCUMENT怎麽用?Java JsonToken.END_DOCUMENT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類com.google.gson.stream.JsonToken
的用法示例。
在下文中一共展示了JsonToken.END_DOCUMENT屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
try {
JsonReader jsonReader = new JsonReader(json);
JsonElement element = parse(jsonReader);
if (element.isJsonNull() || jsonReader.peek() == JsonToken.END_DOCUMENT) {
return element;
}
throw new JsonSyntaxException("Did not consume the entire document.");
} catch (Throwable e) {
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonIOException(e2);
} catch (Throwable e22) {
throw new JsonSyntaxException(e22);
}
}
示例2: peek
@Override
public JsonToken peek() throws IOException {
JsonToken token = null;
if (state() == State.INITIAL || state() == State.SCOPE_DOCUMENT) {
advance();
token = toGsonToken(delegate.getCurrentBsonType());
} else if (state() == State.TYPE) {
advance();
token = toGsonToken(delegate.getCurrentBsonType());
} else if (state() == State.NAME) {
token = JsonToken.NAME;
} else if (state() == State.END_OF_DOCUMENT) {
token = JsonToken.END_OBJECT;
} else if (state() == State.END_OF_ARRAY) {
token = JsonToken.END_ARRAY;
} else if (state() == State.DONE) {
token = JsonToken.END_DOCUMENT;
} else if (state() == State.VALUE) {
token = toGsonToken(delegate.getCurrentBsonType());
}
if (token == null) {
throw new IllegalStateException("Shouldn't get here (null token). Last state is " + state() + " currentType:" +
delegate.getCurrentBsonType());
}
return token;
}
示例3: assertFullConsumption
private static void assertFullConsumption(Object obj, JsonReader reader) {
if (obj != null) {
try {
if (reader.peek() != JsonToken.END_DOCUMENT) {
throw new JsonIOException("JSON document was not fully consumed.");
}
} catch (Throwable e) {
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonIOException(e2);
}
}
}
示例4: hasNext
public boolean hasNext() {
boolean z;
synchronized (this.lock) {
try {
z = this.parser.peek() != JsonToken.END_DOCUMENT;
} catch (Throwable e) {
throw new JsonSyntaxException(e);
} catch (Throwable e2) {
throw new JsonIOException(e2);
}
}
return z;
}
示例5: toGsonToken
private static JsonToken toGsonToken(BsonType type) {
final JsonToken token;
switch (type) {
case END_OF_DOCUMENT:
token = JsonToken.END_DOCUMENT;
break;
case DOUBLE:
token = JsonToken.NUMBER;
break;
case STRING:
token = JsonToken.STRING;
break;
case DOCUMENT:
token = JsonToken.BEGIN_OBJECT;
break;
case ARRAY:
token = JsonToken.BEGIN_ARRAY;
break;
case OBJECT_ID:
token = JsonToken.STRING;
break;
case BOOLEAN:
token = JsonToken.BOOLEAN;
break;
case DATE_TIME:
token = JsonToken.NUMBER;
break;
case NULL:
token = JsonToken.NULL;
break;
case REGULAR_EXPRESSION:
token = JsonToken.STRING;
break;
case SYMBOL:
token = JsonToken.STRING;
break;
case INT32:
token = JsonToken.NUMBER;
break;
case INT64:
token = JsonToken.NUMBER;
break;
case TIMESTAMP:
token = JsonToken.NUMBER;
break;
case DECIMAL128:
token = JsonToken.NUMBER;
break;
case BINARY:
token = JsonToken.STRING;
break;
default:
// not really sure what to do with this type
token = JsonToken.NULL;
}
return token;
}
示例6: peek
public JsonToken peek() throws IOException {
if (this.stack.isEmpty()) {
return JsonToken.END_DOCUMENT;
}
Iterator<?> o = peekStack();
if (o instanceof Iterator) {
boolean isObject = this.stack.get(this.stack.size() - 2) instanceof JsonObject;
Iterator<?> iterator = o;
if (!iterator.hasNext()) {
return isObject ? JsonToken.END_OBJECT : JsonToken.END_ARRAY;
} else {
if (isObject) {
return JsonToken.NAME;
}
this.stack.add(iterator.next());
return peek();
}
} else if (o instanceof JsonObject) {
return JsonToken.BEGIN_OBJECT;
} else {
if (o instanceof JsonArray) {
return JsonToken.BEGIN_ARRAY;
}
if (o instanceof JsonPrimitive) {
JsonPrimitive primitive = (JsonPrimitive) o;
if (primitive.isString()) {
return JsonToken.STRING;
}
if (primitive.isBoolean()) {
return JsonToken.BOOLEAN;
}
if (primitive.isNumber()) {
return JsonToken.NUMBER;
}
throw new AssertionError();
} else if (o instanceof JsonNull) {
return JsonToken.NULL;
} else {
if (o == SENTINEL_CLOSED) {
throw new IllegalStateException("JsonReader is closed");
}
throw new AssertionError();
}
}
}
示例7: peek
@Override public JsonToken peek() throws IOException {
if (stack.isEmpty()) {
return JsonToken.END_DOCUMENT;
}
Object o = peekStack();
if (o instanceof Iterator) {
boolean isObject = stack.get(stack.size() - 2) instanceof JsonObject;
Iterator<?> iterator = (Iterator<?>) o;
if (iterator.hasNext()) {
if (isObject) {
return JsonToken.NAME;
} else {
stack.add(iterator.next());
return peek();
}
} else {
return isObject ? JsonToken.END_OBJECT : JsonToken.END_ARRAY;
}
} else if (o instanceof JsonObject) {
return JsonToken.BEGIN_OBJECT;
} else if (o instanceof JsonArray) {
return JsonToken.BEGIN_ARRAY;
} else if (o instanceof JsonPrimitive) {
JsonPrimitive primitive = (JsonPrimitive) o;
if (primitive.isString()) {
return JsonToken.STRING;
} else if (primitive.isBoolean()) {
return JsonToken.BOOLEAN;
} else if (primitive.isNumber()) {
return JsonToken.NUMBER;
} else {
throw new AssertionError();
}
} else if (o instanceof JsonNull) {
return JsonToken.NULL;
} else if (o == SENTINEL_CLOSED) {
throw new IllegalStateException("JsonReader is closed");
} else {
throw new AssertionError();
}
}
示例8: isEndOfDocument
/**
* Checks if the stream contains nothing more.
*
* @return true, if the json stream contain nothing more
* @throws IOException
* on IO errors
*/
public boolean isEndOfDocument() throws IOException {
return JsonToken.END_DOCUMENT == stream.peek();
}