List of usage examples for com.google.gson.stream JsonReader nextInt
public int nextInt() throws IOException
From source file:io.github.rcarlosdasilva.weixin.core.json.adapter.OpenPlatformAuthGetLicenseInformationResponseTypeAdapter.java
private void readLicensedAccessToken(JsonReader in, OpenPlatformAuthGetLicenseInformationResponse model) throws IOException { LicensingInformation licensingInformation = new LicensingInformation(); in.beginObject();//w w w.j a v a 2 s. c om while (in.hasNext()) { String key = in.nextName(); switch (key) { case Convention.OPEN_PLATFORM_AUTH_LICENSED_APPID_ALIAS_KEY: case Convention.OPEN_PLATFORM_AUTH_LICENSED_APPID_KEY: licensingInformation.setAppId(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSED_ACCESS_TOKEN_KEY: model.getLicensedAccessToken().setAccessToken(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSED_ACCESS_TOKEN_EXPIRES_IN_KEY: model.getLicensedAccessToken().setExpiresIn(in.nextInt()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSED_REFRESH_TOKEN_KEY: model.getLicensedAccessToken().setRefreshToken(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSED_FUNCTIONS_INFO_KEY: { in.beginArray(); while (in.hasNext()) { in.beginObject(); in.nextName(); in.beginObject(); in.nextName(); licensingInformation.addLicencedFunction(in.nextInt()); in.endObject(); in.endObject(); } in.endArray(); break; } default: if (in.hasNext()) { String value = in.nextString(); logger.warn(LOG_UNKNOWN_JSON_KEY, key, value); } } } in.endObject(); model.setLicensingInformation(licensingInformation); }
From source file:io.github.rcarlosdasilva.weixin.core.json.adapter.OpenPlatformAuthGetLicenseInformationResponseTypeAdapter.java
private void readLicensorInformation(JsonReader in, OpenPlatformAuthGetLicenseInformationResponse model) throws IOException { LicensorInfromation licensorInfromation = new LicensorInfromation(); in.beginObject();// ww w. j a v a2 s .c o m while (in.hasNext()) { String key = in.nextName(); switch (key) { case Convention.OPEN_PLATFORM_AUTH_LICENSOR_NICKNAME_KEY: licensorInfromation.setNickName(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_LOGO_KEY: licensorInfromation.setLogo(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_ACCOUNT_TYPE_KEY: { in.beginObject(); in.nextName(); licensorInfromation.setAccountType(in.nextInt()); in.endObject(); break; } case Convention.OPEN_PLATFORM_AUTH_LICENSOR_ACCOUNT_VERIFIED_TYPE_KEY: { in.beginObject(); in.nextName(); licensorInfromation.setAccountVerifiedType(in.nextInt()); in.endObject(); break; } case Convention.OPEN_PLATFORM_AUTH_LICENSOR_MPID_KEY: licensorInfromation.setMpId(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_PRINCIPAL_NAME_KEY: licensorInfromation.setPrincipalName(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_ACCOUNT_NAME_KEY: licensorInfromation.setAccountName(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_QRCODE_URL_KEY: licensorInfromation.setQrCodeUrl(in.nextString()); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_INFO_KEY: readBusinessInfo(in, licensorInfromation); break; default: if (in.hasNext()) { String value = in.nextString(); logger.warn(LOG_UNKNOWN_JSON_KEY, key, value); } } } in.endObject(); model.setLicensorInfromation(licensorInfromation); }
From source file:io.github.rcarlosdasilva.weixin.core.json.adapter.OpenPlatformAuthGetLicenseInformationResponseTypeAdapter.java
private void readBusinessInfo(JsonReader in, LicensorInfromation licensorInfromation) throws IOException { in.beginObject();//from w w w. ja v a 2 s . c o m while (in.hasNext()) { String key = in.nextName(); switch (key) { case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_STORE_KEY: licensorInfromation.setBusinessStoreOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_SCAN_KEY: licensorInfromation.setBusinessScanOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_PAY_KEY: licensorInfromation.setBusinessPayOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_CARD_KEY: licensorInfromation.setBusinessCardOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER); break; case Convention.OPEN_PLATFORM_AUTH_LICENSOR_BUSINESS_SHAKE_KEY: licensorInfromation.setBusinessShakeOpened(in.nextInt() == Convention.GLOBAL_TRUE_NUMBER); break; default: if (in.hasNext()) { String value = in.nextString(); logger.warn(LOG_UNKNOWN_JSON_KEY, key, value); } } } in.endObject(); }
From source file:net.evecom.android.json.JsonSysOrgansData.java
License:Open Source License
public static ArrayList<MianPerson> getData(final String path, String entity_str) throws Exception { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); byte[] entity = entity_str.getBytes(); conn.setConnectTimeout(5000);//from ww w . j a v a 2 s . c om conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Content-Length", String.valueOf(entity.length)); conn.getOutputStream().write(entity); if (conn.getResponseCode() == 200) { InputStream inputstream = conn.getInputStream(); StringBuffer buffer = new StringBuffer(); byte[] b = new byte[1024]; for (int i; (i = inputstream.read(b)) != -1;) { buffer.append(new String(b, 0, i)); } StringReader reader = new StringReader(buffer.toString()); JsonReader jsonReader = new JsonReader(reader); list = new ArrayList<MianPerson>(); jsonReader.beginObject(); while (jsonReader.hasNext()) { String nextname1 = ""; if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextname1 = jsonReader.nextInt() + ""; } else { nextname1 = jsonReader.nextName(); } if ("rows".equals(nextname1)) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); MianPerson person = new MianPerson(); while (jsonReader.hasNext()) { String nextName = ""; if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextName = jsonReader.nextInt() + ""; } else if (jsonReader.peek() == JsonToken.STRING) { nextName = jsonReader.nextString() + ""; } else { nextName = jsonReader.nextName(); } String nextValue = ""; if (nextName.equals("IDCARDNO")) {// if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextValue = jsonReader.nextInt() + ""; } else { nextValue = jsonReader.nextString(); } // nextValue = jsonReader.nextString(); person.setIDCARDNO(nextValue); } else if (nextName.equals("HOUSEHOLDID")) {// if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextValue = jsonReader.nextInt() + ""; } else { nextValue = jsonReader.nextString(); } // nextValue = jsonReader.nextString(); person.setHOUSEHOLDID(nextValue); } else if (nextName.equals("AREAID")) {// id if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextValue = jsonReader.nextInt() + ""; } else { nextValue = jsonReader.nextString(); } // nextValue = jsonReader.nextString(); person.setAREAID(nextValue); } else if (nextName.equals("AREANAME")) {// if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextValue = jsonReader.nextInt() + ""; } else { nextValue = jsonReader.nextString(); } // nextValue = jsonReader.nextString(); person.setAREANAME(nextValue); } else if (nextName.equals("PERSONNAME")) {// if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextValue = jsonReader.nextInt() + ""; } else { nextValue = jsonReader.nextString(); } // nextValue = jsonReader.nextString(); person.setPERSONNAME(nextValue); } else if (nextName.equals("MALEDICTID")) {// 1 // 2 if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextValue = jsonReader.nextInt() + ""; } else { nextValue = jsonReader.nextString(); } // nextValue = jsonReader.nextString(); if (null != nextValue && "1".equals(nextValue)) { person.setMALEDICTID(""); } else if (null != nextValue && "2".equals(nextValue)) { person.setMALEDICTID(""); } } else if (nextName.equals("BIRTH")) {// if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextValue = jsonReader.nextInt() + ""; } else { nextValue = jsonReader.nextString(); } // nextValue = jsonReader.nextString(); person.setBIRTH(nextValue); } else if (nextName.equals("HOUSEADDR")) {// if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextValue = jsonReader.nextInt() + ""; } else { nextValue = jsonReader.nextString(); } // nextValue = jsonReader.nextString(); person.setHOUSEADDR(nextValue); } else if (nextName.equals("PERSONID")) {// id if (jsonReader.peek() == JsonToken.NULL) { jsonReader.nextNull(); } else if (jsonReader.peek() == JsonToken.NUMBER) { nextValue = jsonReader.nextInt() + ""; } else { nextValue = jsonReader.nextString(); } // nextValue = jsonReader.nextString(); person.setPERSONID(nextValue); } System.out.println(nextName + "=" + nextValue); } list.add(person); person = null; jsonReader.endObject(); } jsonReader.endArray(); } // } jsonReader.endObject(); // XmlPullParser xml = Xml.newPullParser(); // xml.setInput(inputstream, "UTF-8"); // int event = xml.getEventType(); // while (event != XmlPullParser.END_DOCUMENT) { // switch (event) { // // // case XmlPullParser.START_DOCUMENT: // list = new ArrayList<SysOrgan>(); // break; // case XmlPullParser.START_TAG: // // String value = xml.getName(); // if (value.equals("QY")) { // organ = new SysOrgan(); // } else if (value.equals("SO_ID")) { // organ.setSoId(xml.nextText()); // } else if (value.equals("so_Name")) { // organ.setSoName(xml.nextText()); // } // break; // case XmlPullParser.END_TAG: // if (xml.getName().equals("QY")) { // list.add(organ); // organ = null; // } // break; // default: // break; // } // // // event = xml.next(); // } return list; } else { return null; } }
From source file:org.apache.hadoop.dynamodb.importformat.ImportInputFormat.java
License:Open Source License
/** * An example manifest file looks like//from w w w . java 2 s. co m * * {"name":"DynamoDB-export","version":3, "entries":[ * {"url":"s3://path/to/object/92dd1414-a049-4c68-88fb-a23acd44907e","mandatory":true}, * {"url":"s3://path/to/object/ba3f3535-7aa1-4f97-a530-e72938bf4b76","mandatory":true} ]} */ // @formatter:on private List<InputSplit> parseManifest(FileSystem fs, Path manifestPath, JobConf job) throws IOException { List<InputSplit> splits = null; FSDataInputStream fp = fs.open(manifestPath); JsonReader reader = new JsonReader(new InputStreamReader(fp, Charsets.UTF_8)); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); switch (name) { case VERSION_JSON_KEY: job.set(DynamoDBConstants.EXPORT_FORMAT_VERSION, String.valueOf(reader.nextInt())); break; case ENTRIES_JSON_KEY: splits = readEntries(reader, job); break; default: log.info("Skipping a JSON key in the manifest file: " + name); reader.skipValue(); break; } } reader.endObject(); if (splits == null) { return Collections.emptyList(); } return splits; }
From source file:org.apache.hadoop.fs.http.client.ContentSummary.java
License:Apache License
public static TypeAdapter adapter() { return new TypeAdapter<ContentSummary>() { @Override/*from w ww . j ava2 s .com*/ public void write(JsonWriter out, ContentSummary value) throws IOException { /* not implemented */ } @Override public ContentSummary read(JsonReader in) throws IOException { ContentSummary instance = null; in.setLenient(true); if (in.peek() == JsonToken.BEGIN_OBJECT) { in.beginObject(); if (in.nextName().equalsIgnoreCase("ContentSummary")) { String name; in.beginObject(); instance = new ContentSummary(); while (in.hasNext()) { name = in.nextName(); if (name.equalsIgnoreCase("directoryCount")) { instance.directoryCount = in.nextInt(); } else if (name.equalsIgnoreCase("fileCount")) { instance.fileCount = in.nextInt(); } else if (name.equalsIgnoreCase("length")) { instance.length = in.nextInt(); } else if (name.equalsIgnoreCase("quota")) { instance.quota = in.nextInt(); } else if (name.equalsIgnoreCase("spaceConsumed")) { instance.spaceConsumed = in.nextInt(); } else if (name.equalsIgnoreCase("spaceQuota")) { instance.spaceQuota = in.nextInt(); } } in.endObject(); } in.endObject(); } return instance; } }; }
From source file:org.apache.hadoop.fs.http.client.FileStatus.java
License:Apache License
public static TypeAdapter adapter() { return new TypeAdapter<FileStatus>() { @Override/*from w ww.j a v a 2s. c o m*/ public void write(JsonWriter out, FileStatus value) throws IOException { /* not implemented */ } @Override public FileStatus read(JsonReader in) throws IOException { FileStatus instance = null; in.setLenient(true); if (in.peek() == JsonToken.BEGIN_OBJECT) { in.beginObject(); if (in.nextName().equalsIgnoreCase("FileStatus")) { String name; in.beginObject(); instance = new FileStatus(); while (in.hasNext()) { name = in.nextName(); if (name.equalsIgnoreCase("accessTime")) { instance.accessTime = in.nextLong(); } else if (name.equalsIgnoreCase("blockSize")) { instance.blockSize = in.nextInt(); } else if (name.equalsIgnoreCase("length")) { instance.length = in.nextLong(); } else if (name.equalsIgnoreCase("modificationTime")) { instance.modTime = in.nextLong(); } else if (name.equalsIgnoreCase("replication")) { instance.replication = in.nextInt(); } else if (name.equalsIgnoreCase("group")) { instance.group = in.nextString(); } else if (name.equalsIgnoreCase("owner")) { instance.owner = in.nextString(); } else if (name.equalsIgnoreCase("pathSuffix")) { instance.suffix = in.nextString(); } else if (name.equalsIgnoreCase("permission")) { instance.permission = in.nextString(); } else if (name.equalsIgnoreCase("type")) { instance.type = FileType.valueOf(in.nextString()); } } in.endObject(); } in.endObject(); } return instance; } }; }
From source file:org.apache.olingo.odata2.core.ep.consumer.JsonPropertyConsumer.java
License:Apache License
private Object readSimpleProperty(final JsonReader reader, final EntityPropertyInfo entityPropertyInfo, final Object typeMapping, final EntityProviderReadProperties readProperties) throws EdmException, EntityProviderException, IOException { final EdmSimpleType type = (EdmSimpleType) entityPropertyInfo.getType(); Object value = null;// ww w.ja v a 2 s .co m final JsonToken tokenType = reader.peek(); if (tokenType == JsonToken.NULL) { reader.nextNull(); } else { switch (EdmSimpleTypeKind.valueOf(type.getName())) { case Boolean: if (tokenType == JsonToken.BOOLEAN) { value = reader.nextBoolean(); value = value.toString(); } else { throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE .addContent(entityPropertyInfo.getName())); } break; case Byte: case SByte: case Int16: case Int32: if (tokenType == JsonToken.NUMBER) { value = reader.nextInt(); value = value.toString(); } else { throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE .addContent(entityPropertyInfo.getName())); } break; case Single: case Double: if (tokenType == JsonToken.STRING) { value = reader.nextString(); } else if (tokenType == JsonToken.NUMBER) { value = reader.nextDouble(); value = value.toString(); } else { throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE .addContent(entityPropertyInfo.getName())); } break; default: if (tokenType == JsonToken.STRING) { value = reader.nextString(); } else { throw new EntityProviderException(EntityProviderException.INVALID_PROPERTY_VALUE .addContent(entityPropertyInfo.getName())); } break; } } final Class<?> typeMappingClass = typeMapping == null ? type.getDefaultType() : (Class<?>) typeMapping; final EdmFacets facets = readProperties == null || readProperties.isValidatingFacets() ? entityPropertyInfo.getFacets() : null; return type.valueOfString((String) value, EdmLiteralKind.JSON, facets, typeMappingClass); }
From source file:org.bimserver.client.ClientIfcModel.java
License:Open Source License
private Object readPrimitive(JsonReader jsonReader, EStructuralFeature eStructuralFeature) throws IOException { EClassifier eClassifier = eStructuralFeature.getEType(); if (eClassifier == EcorePackage.eINSTANCE.getEString()) { return jsonReader.nextString(); } else if (eClassifier == EcorePackage.eINSTANCE.getEDouble() || eClassifier == EcorePackage.eINSTANCE.getEDoubleObject()) { return jsonReader.nextDouble(); } else if (eClassifier == EcorePackage.eINSTANCE.getEFloat() || eClassifier == EcorePackage.eINSTANCE.getEFloatObject()) { return (float) jsonReader.nextDouble(); } else if (eClassifier == EcorePackage.eINSTANCE.getEBoolean() || eClassifier == EcorePackage.eINSTANCE.getEBooleanObject()) { return jsonReader.nextBoolean(); } else if (eClassifier == EcorePackage.eINSTANCE.getEInt() || eClassifier == EcorePackage.eINSTANCE.getEIntegerObject()) { return jsonReader.nextInt(); } else if (eClassifier == EcorePackage.eINSTANCE.getEEnum()) { // TODO DOES THIS EVER HAPPEN?? if (jsonReader.peek() == JsonToken.BOOLEAN) { EEnum eEnum = (EEnum) eStructuralFeature.getEType(); return eEnum.getEEnumLiteral(("" + jsonReader.nextBoolean()).toUpperCase()).getInstance(); } else {/*from w w w . j ava 2s . c o m*/ EEnum eEnum = (EEnum) eStructuralFeature.getEType(); return eEnum.getEEnumLiteral(jsonReader.nextString()).getInstance(); } } else if (eClassifier instanceof EClass) { throw new RuntimeException(); } else if (eClassifier == EcorePackage.eINSTANCE.getEByteArray()) { return Base64.decodeBase64(jsonReader.nextString().getBytes(Charsets.UTF_8)); } else if (eClassifier instanceof EEnum) { if (jsonReader.peek() == JsonToken.BOOLEAN) { EEnum eEnum = (EEnum) eStructuralFeature.getEType(); return eEnum.getEEnumLiteral(("" + jsonReader.nextBoolean()).toUpperCase()).getInstance(); } else { EEnum eEnum = (EEnum) eStructuralFeature.getEType(); return eEnum.getEEnumLiteral(jsonReader.nextString()).getInstance(); } } else { throw new RuntimeException("Unimplemented type " + eStructuralFeature.getEType().getName()); } }
From source file:org.bimserver.client.ClientIfcModel.java
License:Open Source License
@SuppressWarnings({ "unused", "resource" }) public void getGeometry(IfcProduct ifcProduct) { try {/*from w w w . j ava 2 s .c om*/ Long downloadByOids = bimServerClient.getBimsie1ServiceInterface().downloadByOids( Collections.singleton(roid), Collections.singleton(ifcProduct.getOid()), getJsonGeometrySerializerOid(), true, false); InputStream downloadData = bimServerClient.getDownloadData(downloadByOids, getJsonGeometrySerializerOid()); JsonReader jsonReader = new JsonReader(new InputStreamReader(downloadData)); jsonReader.beginObject(); if (jsonReader.nextName().equals("geometry")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); if (jsonReader.nextName().equals("material")) { String material = jsonReader.nextString(); if (jsonReader.nextName().equals("type")) { String type = jsonReader.nextString(); if (jsonReader.nextName().equals("coreId")) { String coreid = jsonReader.nextString(); if (jsonReader.nextName().equals("primitive")) { String primitive = jsonReader.nextString(); if (jsonReader.nextName().equals("positions")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { double position = jsonReader.nextDouble(); } jsonReader.endArray(); if (jsonReader.nextName().equals("normals")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { double normal = jsonReader.nextDouble(); } jsonReader.endArray(); if (jsonReader.nextName().equals("nrindices")) { int nrindices = jsonReader.nextInt(); } } } } } } } jsonReader.endObject(); } jsonReader.endArray(); } jsonReader.endObject(); } catch (Exception e) { LOGGER.error("", e); } }