List of usage examples for com.google.gson.stream JsonReader JsonReader
public JsonReader(Reader in)
From source file:com.nridge.ds.solr.SolrCollection.java
License:Open Source License
private ArrayList<String> load(InputStream anIS) throws IOException { String jsonName, jsonValue;/*from w w w . j a va 2 s . c o m*/ ArrayList<String> configSetList = new ArrayList<>(); String configSetString = IOUtils.toString(anIS, StrUtl.CHARSET_UTF_8); StringReader stringReader = new StringReader(configSetString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "collections")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonValue = jsonReader.nextString(); configSetList.add(jsonValue); } jsonReader.endArray(); } } jsonReader.endObject(); return configSetList; }
From source file:com.nridge.ds.solr.SolrCollection.java
License:Open Source License
private void parseReply(String aMessage) throws DSException, IOException { String jsonName;//from www . ja v a2 s . c o m Logger appLogger = mAppMgr.getLogger(this, "parseReply"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); int msgCode = 0; String msgString = StringUtils.EMPTY; StringReader stringReader = new StringReader(aMessage); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "exception")) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "msg")) msgString = jsonReader.nextString(); else if (StringUtils.equals(jsonName, "rspCode")) msgCode = jsonReader.nextInt(); else jsonReader.skipValue(); } jsonReader.endObject(); } else jsonReader.skipValue(); } jsonReader.endObject(); if (StringUtils.isNotEmpty(msgString)) throw new DSException(String.format("Solr Exception [%d]: %s", msgCode, msgString)); appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.nridge.ds.solr.SolrConfigJSON.java
License:Open Source License
/** * Parses an JSON string representing the Solr schema and loads it into a document * and returns an instance to it.//from ww w . j a v a2 s. c o m * * @param aConfigString JSON string representation of the Solr schema. * * @return Document instance containing the parsed data. * * @throws IOException I/O related exception. */ public Document loadDocument(String aConfigString) throws IOException { String jsonName, jsonValue; Document componentDocument; Document configDocument = new Document(Solr.DOCUMENT_SCHEMA_TYPE); DataBag configBag = configDocument.getBag(); StringReader stringReader = new StringReader(aConfigString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_RESPONSE_HEADER)) { Document headerDocument = new Document(Solr.RESPONSE_SCHEMA_HEADER); DataBag headerBag = headerDocument.getBag(); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); jsonValue = nextValueAsString(jsonReader); headerBag.add(new DataTextField(jsonName, Field.nameToTitle(jsonName), jsonValue)); } jsonReader.endObject(); configDocument.addRelationship(Solr.RESPONSE_SCHEMA_HEADER, headerDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG)) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_UPDATE_HANDLER)) populateCfgUpdateHandler(jsonReader, configDocument, Solr.RESPONSE_CONFIG_UPDATE_HANDLER); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_QUERY)) populateCfgQuery(jsonReader, configDocument, Solr.RESPONSE_CONFIG_QUERY); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_REQUEST_HANDLER)) populateCfgRequestHandler(jsonReader, configDocument, Solr.RESPONSE_CONFIG_REQUEST_HANDLER); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_RESPONSE_WRITER)) populateQueryResponseWriterHandler(jsonReader, configDocument, Solr.RESPONSE_CONFIG_QUERY_RESPONSE_WRITER); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_SEARCH_COMPONENT)) populateSearchComponent(jsonReader, configDocument, Solr.RESPONSE_CONFIG_SEARCH_COMPONENT); else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_INIT_PARAMS)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_INIT_PARAMS); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_INIT_PARAMETERS, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_INIT_PARAMS, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_LISTENER)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_LISTENER); jsonReader.beginArray(); while (jsonReader.hasNext()) addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_LISTENER_EVENTS, jsonName); jsonReader.endArray(); configDocument.addRelationship(Solr.RESPONSE_CONFIG_LISTENER, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_DIRECTORY_FACTORY)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_DIRECTORY_FACTORY); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_DIRECTORY_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_DIRECTORY_FACTORY, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_CODEC_FACTORY)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_CODEC_FACTORY); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_CODEC_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_CODEC_FACTORY, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_UPDATE_HU_LOG)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_UPDATE_HANDLER_ULOG); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_UHUL_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_UPDATE_HANDLER_ULOG, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_REQUEST_DISPATCHER)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_REQUEST_DISPATCHER); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_RD_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_REQUEST_DISPATCHER, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_INDEX_CONFIG)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_REQUEST_DISPATCHER); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_INDEX_CONFIG, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_IC_ENTRIES, componentDocument); } else if (StringUtils.equals(jsonName, OBJECT_RESPONSE_CONFIG_PEER_SYNC)) { componentDocument = new Document(Solr.RESPONSE_CONFIG_PEER_SYNC); addObjectToDocument(jsonReader, componentDocument, Solr.RESPONSE_CONFIG_PS_ENTRIES, jsonName); configDocument.addRelationship(Solr.RESPONSE_CONFIG_PEER_SYNC, componentDocument); } else { jsonValue = nextValueAsString(jsonReader); addBagTextField(configBag, jsonName, jsonValue); } } jsonReader.endObject(); } else jsonReader.skipValue(); } jsonReader.endObject(); jsonReader.close(); return configDocument; }
From source file:com.nridge.ds.solr.SolrConfigSet.java
License:Open Source License
private ArrayList<String> load(InputStream anIS) throws IOException { String jsonName, jsonValue;/*w w w . j a v a2 s .co m*/ ArrayList<String> configSetList = new ArrayList<>(); String configSetString = IOUtils.toString(anIS, StrUtl.CHARSET_UTF_8); StringReader stringReader = new StringReader(configSetString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "configSets")) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonValue = jsonReader.nextString(); configSetList.add(jsonValue); } jsonReader.endArray(); } } jsonReader.endObject(); return configSetList; }
From source file:com.nridge.ds.solr.SolrSchemaJSON.java
License:Open Source License
private DataTable createSchemaFieldTable(String aSchemaString, String aFieldName, String aTitle) throws IOException { String jsonName;/*from w w w. j ava 2s. c om*/ DataField dataField; DataTable dataTable = new DataTable(aTitle); DataBag dataBag = dataTable.getColumnBag(); StringReader stringReader = new StringReader(aSchemaString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_SCHEMA)) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, aFieldName)) { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); dataField = dataBag.getFieldByName(jsonName); if (dataField == null) { dataField = new DataTextField(jsonName, Field.nameToTitle(jsonName)); dataField.addFeature(Field.FEATURE_IS_STORED, StrUtl.STRING_TRUE); dataBag.add(dataField); } jsonReader.skipValue(); } jsonReader.endObject(); } jsonReader.endArray(); ; } else jsonReader.skipValue(); } jsonReader.endObject(); } else jsonReader.skipValue(); } jsonReader.endObject(); jsonReader.close(); return dataTable; }
From source file:com.nridge.ds.solr.SolrSchemaJSON.java
License:Open Source License
/** * Parses an JSON string representing the Solr schema and loads it into a document * and returns an instance to it.//from w w w . j a va 2 s . c om * * @param aSchemaString JSON string representation of the Solr schema. * * @return Document instance containing the parsed data. * * @throws java.io.IOException I/O related exception. */ public Document loadDocument(String aSchemaString) throws IOException { String jsonName, jsonValue; Document schemaDocument = new Document(Solr.DOCUMENT_SCHEMA_TYPE); DataBag schemaBag = schemaDocument.getBag(); // Parse a subset of the JSON payload to identify the table columns before fully processing it. SolrSchema solrSchema = new SolrSchema(mAppMgr); DataTable fieldsTable = new DataTable(solrSchema.createFieldsBag()); DataTable dynamicFieldsTable = createSchemaFieldTable(aSchemaString, OBJECT_SCHEMA_DYNAMIC_FIELDS, "Solr Schema Dynamic Fields"); DataTable copyFieldsTable = createSchemaFieldTable(aSchemaString, OBJECT_SCHEMA_COPY_FIELDS, "Solr Schema Copy Fields"); StringReader stringReader = new StringReader(aSchemaString); JsonReader jsonReader = new JsonReader(stringReader); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, OBJECT_RESPONSE_HEADER)) { Document headerDocument = new Document(Solr.RESPONSE_SCHEMA_HEADER); headerDocument.setName(jsonName); DataBag headerBag = headerDocument.getBag(); jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); jsonValue = nextValueAsString(jsonReader); headerBag.add(new DataTextField(jsonName, Field.nameToTitle(jsonName), jsonValue)); } jsonReader.endObject(); schemaDocument.addRelationship(Solr.RESPONSE_SCHEMA_HEADER, headerDocument); } else if (StringUtils.equals(jsonName, OBJECT_SCHEMA)) { jsonReader.beginObject(); while (jsonReader.hasNext()) { jsonName = jsonReader.nextName(); if (StringUtils.equals(jsonName, "name")) { jsonValue = nextValueAsString(jsonReader); schemaBag.add(jsonName, Field.nameToTitle(jsonName), jsonValue); } else if (StringUtils.equals(jsonName, "version")) { jsonValue = nextValueAsString(jsonReader); schemaBag.add(jsonName, Field.nameToTitle(jsonName), jsonValue); } else if (StringUtils.equals(jsonName, "uniqueKey")) { jsonValue = nextValueAsString(jsonReader); schemaBag.add(jsonName, Field.nameToTitle(jsonName), jsonValue); } else if (StringUtils.equals(jsonName, OBJECT_SCHEMA_FIELD_TYPES)) { populateSchemaFieldTypes(jsonReader, schemaDocument); } else if (StringUtils.equals(jsonName, OBJECT_SCHEMA_FIELDS)) { populateSchemaFieldTable(jsonReader, fieldsTable); Document fieldsDocument = new Document(Solr.RESPONSE_SCHEMA_FIELD_NAMES, fieldsTable); schemaDocument.addRelationship(Solr.RESPONSE_SCHEMA_FIELD_NAMES, fieldsDocument); } else if (StringUtils.equals(jsonName, OBJECT_SCHEMA_DYNAMIC_FIELDS)) { populateSchemaFieldTable(jsonReader, dynamicFieldsTable); Document dynamicFieldsDocument = new Document(Solr.RESPONSE_SCHEMA_DYNAMIC_FIELDS, dynamicFieldsTable); schemaDocument.addRelationship(Solr.RESPONSE_SCHEMA_DYNAMIC_FIELDS, dynamicFieldsDocument); } else if (StringUtils.equals(jsonName, OBJECT_SCHEMA_COPY_FIELDS)) { populateSchemaFieldTable(jsonReader, copyFieldsTable); Document copyFieldsDocument = new Document(Solr.RESPONSE_SCHEMA_COPY_FIELDS, copyFieldsTable); schemaDocument.addRelationship(Solr.RESPONSE_SCHEMA_COPY_FIELDS, copyFieldsDocument); } else jsonReader.skipValue(); } jsonReader.endObject(); } else jsonReader.skipValue(); } jsonReader.endObject(); jsonReader.close(); return schemaDocument; }
From source file:com.officialgenius.brainiac.diodes.NixDiode.java
License:Apache License
@Override public String getDropBoxPath() throws IOException { Gson gson = new Gson(); Path pathToDropBox = Paths.get(NIX_DROPBOX_INFO_PATH); BufferedReader br = Files.newBufferedReader(pathToDropBox, Charset.forName("UTF-8")); JsonReader jsonReader = new JsonReader(br); JsonObject infoJson = gson.fromJson(jsonReader, JsonObject.class); return infoJson.getAsJsonObject("personal").get("path").getAsString(); }
From source file:com.officialgenius.brainiac.diodes.WindowsDiode.java
License:Apache License
@Override public String getDropBoxPath() throws IOException { Gson gson = new Gson(); Path pathToDropBox = Paths.get(WIN_DROPBOX_INFO_PATH); BufferedReader br = Files.newBufferedReader(pathToDropBox, Charset.forName("UTF-8")); JsonReader jsonReader = new JsonReader(br); JsonObject infoJson = gson.fromJson(jsonReader, JsonObject.class); return infoJson.getAsJsonObject("personal").get("path").getAsString(); }
From source file:com.oneops.inductor.Listener.java
License:Apache License
private CmsWorkOrderSimpleBase getWorkOrderOf(String msgText, Class c) { CmsWorkOrderSimpleBase wo;/* www .j a va 2s . c o m*/ JsonReader reader = new JsonReader(new StringReader(msgText)); reader.setLenient(true); wo = gson.fromJson(reader, c); return wo; }
From source file:com.oneops.inductor.WorkOrderExecutor.java
License:Apache License
/** * getRepoList: gets list of repos from a json string * * @param jsonReposArray String/*from w ww . j a v a 2 s. c om*/ */ private ArrayList<String> getRepoList(String jsonReposArray) { JsonReader reader = new JsonReader(new StringReader(jsonReposArray)); reader.setLenient(true); ArrayList<String> repos = gson.fromJson(reader, ArrayList.class); if (repos == null) { repos = new ArrayList<>(); } return repos; }