List of usage examples for com.google.gson.stream JsonReader JsonReader
public JsonReader(Reader in)
From source file:net.cnri.doregistrytools.registrar.replication.ReplicationPoller.java
License:Open Source License
private void getRecentlyModifiedObjects(CloseableHttpClient httpClient, RemoteRepositoryInfo remoteRepository) throws IOException, ClientProtocolException, UnsupportedEncodingException, RepositoryException { String url = remoteRepository.baseUri + "/replicate?since=" + remoteRepository.lastTimestamp; if (remoteRepository.includeTypes != null) { url += "&" + listToParamString(remoteRepository.includeTypes, "include"); }//from w w w .ja v a2s . co m if (remoteRepository.excludeTypes != null) { url += "&" + listToParamString(remoteRepository.excludeTypes, "exclude"); } HttpGet request = new HttpGet(url); // Credentials basicCreds = new Credentials(remoteRepository.username, remoteRepository.password); // String basicAuthHeader = basicCreds.getAuthHeader(); // request.addHeader("Authorization", basicAuthHeader); try { UsernamePasswordCredentials creds = new UsernamePasswordCredentials(remoteRepository.username, remoteRepository.password); request.addHeader(new BasicScheme(Charset.forName("UTF-8")).authenticate(creds, request, null)); } catch (AuthenticationException e) { throw new AssertionError(e); } CloseableHttpResponse response = null; HttpEntity entity = null; long mostRecentModified = 0; try { response = httpClient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode != 200) { logger.error("Exception in getRecentlyModifiedObjects response code: " + statusCode); return; } entity = response.getEntity(); InputStream in = entity.getContent(); Reader reader = new InputStreamReader(in, "UTF-8"); JsonReader jsonReader = new JsonReader(reader); jsonReader.beginArray(); while (jsonReader.hasNext()) { long currentModified = registrar.addReplicatedObject(jsonReader, remoteRepository.baseUri); if (currentModified > mostRecentModified) { mostRecentModified = currentModified; } } if (mostRecentModified > 0) { if (System.currentTimeMillis() - mostRecentModified > 120000) mostRecentModified++; //TODO consider improving this remoteRepository.lastTimestamp = mostRecentModified; } } finally { if (entity != null) EntityUtils.consumeQuietly(entity); if (response != null) try { response.close(); } catch (IOException e) { } } }
From source file:net.daporkchop.toobeetooteebot.text.JsonUtils.java
License:Open Source License
public static <T> T gsonDeserialize(Gson gsonIn, Reader readerIn, Class<T> adapter, boolean lenient) { try {//from w w w.j ava2 s . c o m JsonReader jsonreader = new JsonReader(readerIn); jsonreader.setLenient(lenient); return gsonIn.getAdapter(adapter).read(jsonreader); } catch (IOException ioexception) { throw new JsonParseException(ioexception); } }
From source file:net.daporkchop.toobeetooteebot.text.JsonUtils.java
License:Open Source License
public static <T> T fromJson(Gson p_193838_0_, Reader p_193838_1_, Type p_193838_2_, boolean p_193838_3_) { try {/*from w w w . j a va2 s . com*/ JsonReader jsonreader = new JsonReader(p_193838_1_); jsonreader.setLenient(p_193838_3_); return (T) p_193838_0_.getAdapter(TypeToken.get(p_193838_2_)).read(jsonreader); } catch (IOException ioexception) { throw new JsonParseException(ioexception); } }
From source file:net.evecom.android.EventAddActivity.java
License:Open Source License
/** * getTreeOne/*from w w w .j a va2 s. c om*/ */ private void getTreeOne(final String sbd_id) { progressDialog_getInfo = ProgressDialog.show(EventAddActivity.this, "", "..."); list.removeAll(list); new Thread(new Runnable() { @Override public void run() { Message msg_listData = new Message(); String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + "0"; String strResult = null; try { strResult = connServerForResult(strUrl); } catch (Exception e) { msg_listData.what = MESSAGETYPE_02; handler1.sendMessage(msg_listData); if (null != e) { e.printStackTrace(); } return; } // DialogToast(strResult); // System.out.println(strResult); if (null == strResult || "".equals(strResult)) { msg_listData.what = MESSAGETYPE_02; handler1.sendMessage(msg_listData); return; } StringReader reader = new StringReader(strResult); JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); SysBaseDict dict = new SysBaseDict(); while (jsonReader.hasNext()) { String nextName = jsonReader.nextName(); String nextValue = ""; if (nextName.equals("id")) { nextValue = jsonReader.nextString(); dict.setSbdCode(nextValue); } else if (nextName.equals("name")) { nextValue = jsonReader.nextString(); dict.setSbdName(nextValue); } else if (nextName.equals("isparent")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } else if (nextName.equals("pid")) { nextValue = jsonReader.nextString(); dict.setSbdPid(nextValue); } else if (nextName.equals("type")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } // System.out.println(nextName+"="+nextValue); } list.add(dict); dict = null; jsonReader.endObject(); } jsonReader.endArray(); } catch (IOException e) { if (null != e) { e.printStackTrace(); } } if (null == list || list.size() < 1) { msg_listData.what = MESSAGETYPE_02; } else { msg_listData.what = MESSAGETYPE_01; } handler1.sendMessage(msg_listData); } }).start(); }
From source file:net.evecom.android.EventAddActivity.java
License:Open Source License
/** * getTreeTwo/*ww w.j a v a 2s . c o m*/ */ private void getTreeTwo(final String oneStr) { progressDialog_getInfo = ProgressDialog.show(EventAddActivity.this, "", "..."); list.removeAll(list); final Message msg_listData = new Message(); new Thread(new Runnable() { @Override public void run() { String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + oneStr; String strResult = null; try { strResult = connServerForResult(strUrl); } catch (Exception e) { msg_listData.what = MESSAGETYPE_02; handler2.sendMessage(msg_listData); if (null != e) { e.printStackTrace(); } return; } // DialogToast(strResult); // System.out.println(strResult); if (null == strResult || "".equals(strResult)) { msg_listData.what = MESSAGETYPE_02; handler2.sendMessage(msg_listData); return; } StringReader reader = new StringReader(strResult); JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); SysBaseDict dict = new SysBaseDict(); while (jsonReader.hasNext()) { String nextName = jsonReader.nextName(); String nextValue = ""; if (nextName.equals("id")) { nextValue = jsonReader.nextString(); dict.setSbdCode(nextValue); } else if (nextName.equals("name")) { nextValue = jsonReader.nextString(); dict.setSbdName(nextValue); } else if (nextName.equals("isparent")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } else if (nextName.equals("pid")) { nextValue = jsonReader.nextString(); dict.setSbdPid(nextValue); } else if (nextName.equals("type")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } // System.out.println(nextName+"="+nextValue); } list.add(dict); dict = null; jsonReader.endObject(); } jsonReader.endArray(); } catch (IOException e) { if (null != e) { e.printStackTrace(); } } if (null == list || list.size() < 1) { msg_listData.what = MESSAGETYPE_02; } else { msg_listData.what = MESSAGETYPE_01; } handler2.sendMessage(msg_listData); } }).start(); }
From source file:net.evecom.android.EventAddActivity.java
License:Open Source License
/** * getTreeThree//from ww w .j a va 2s . co m */ private void getTreeThree(final String sbd_id) { progressDialog_getInfo = ProgressDialog.show(EventAddActivity.this, "", "..."); list.removeAll(list); final Message msg_listData = new Message(); new Thread(new Runnable() { @Override public void run() { String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + sbd_id; String strResult = null; try { strResult = connServerForResult(strUrl); } catch (Exception e) { msg_listData.what = MESSAGETYPE_02; handler3.sendMessage(msg_listData); if (null != e) { e.printStackTrace(); } return; } if (null == strResult || "".equals(strResult)) { msg_listData.what = MESSAGETYPE_02; handler3.sendMessage(msg_listData); return; } // System.out.println(strResult); StringReader reader = new StringReader(strResult); JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); SysBaseDict dict = new SysBaseDict(); while (jsonReader.hasNext()) { String nextName = jsonReader.nextName(); String nextValue = ""; if (nextName.equals("id")) { nextValue = jsonReader.nextString(); dict.setSbdCode(nextValue); } else if (nextName.equals("name")) { nextValue = jsonReader.nextString(); dict.setSbdName(nextValue); } else if (nextName.equals("isparent")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } else if (nextName.equals("pid")) { nextValue = jsonReader.nextString(); dict.setSbdPid(nextValue); } else if (nextName.equals("type")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } } list.add(dict); dict = null; jsonReader.endObject(); } jsonReader.endArray(); } catch (IOException e) { if (null != e) { e.printStackTrace(); } } if (null == list || list.size() < 1) { msg_listData.what = MESSAGETYPE_02; } else { msg_listData.what = MESSAGETYPE_01; } handler3.sendMessage(msg_listData); } }).start(); }
From source file:net.evecom.android.EventAddActivity1.java
License:Open Source License
/** * getTreeOne//from w w w . ja va 2s. com */ private void getTreeOne(final String sbd_id) { progressDialog_getInfo = ProgressDialog.show(EventAddActivity1.this, "", "..."); list.removeAll(list); new Thread(new Runnable() { @Override public void run() { Message msg_listData = new Message(); String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + "0"; String strResult = null; try { strResult = connServerForResult(strUrl); } catch (Exception e) { msg_listData.what = MESSAGETYPE_02; handler1.sendMessage(msg_listData); if (null != e) { e.printStackTrace(); } return; } // DialogToast(strResult); // System.out.println(strResult); if (null == strResult || "".equals(strResult)) { msg_listData.what = MESSAGETYPE_02; handler1.sendMessage(msg_listData); return; } StringReader reader = new StringReader(strResult); JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); SysBaseDict dict = new SysBaseDict(); while (jsonReader.hasNext()) { String nextName = jsonReader.nextName(); String nextValue = ""; if (nextName.equals("id")) { nextValue = jsonReader.nextString(); dict.setSbdCode(nextValue); } else if (nextName.equals("name")) { nextValue = jsonReader.nextString(); dict.setSbdName(nextValue); } else if (nextName.equals("isparent")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } else if (nextName.equals("pid")) { nextValue = jsonReader.nextString(); dict.setSbdPid(nextValue); } else if (nextName.equals("type")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } // System.out.println(nextName+"="+nextValue); } list.add(dict); dict = null; jsonReader.endObject(); } jsonReader.endArray(); } catch (IOException e) { if (null != e) { e.printStackTrace(); } } if (null == list || list.size() < 1) { msg_listData.what = MESSAGETYPE_02; } else { msg_listData.what = MESSAGETYPE_01; } handler1.sendMessage(msg_listData); } }).start(); }
From source file:net.evecom.android.EventAddActivity1.java
License:Open Source License
/** * getTreeTwo//ww w .j av a2 s . co m */ private void getTreeTwo(final String oneStr) { progressDialog_getInfo = ProgressDialog.show(EventAddActivity1.this, "", "..."); list.removeAll(list); final Message msg_listData = new Message(); new Thread(new Runnable() { @Override public void run() { String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + oneStr; String strResult = null; try { strResult = connServerForResult(strUrl); } catch (Exception e) { msg_listData.what = MESSAGETYPE_02; handler2.sendMessage(msg_listData); if (null != e) { e.printStackTrace(); } return; } // DialogToast(strResult); // System.out.println(strResult); if (null == strResult || "".equals(strResult)) { msg_listData.what = MESSAGETYPE_02; handler2.sendMessage(msg_listData); return; } StringReader reader = new StringReader(strResult); JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); SysBaseDict dict = new SysBaseDict(); while (jsonReader.hasNext()) { String nextName = jsonReader.nextName(); String nextValue = ""; if (nextName.equals("id")) { nextValue = jsonReader.nextString(); dict.setSbdCode(nextValue); } else if (nextName.equals("name")) { nextValue = jsonReader.nextString(); dict.setSbdName(nextValue); } else if (nextName.equals("isparent")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } else if (nextName.equals("pid")) { nextValue = jsonReader.nextString(); dict.setSbdPid(nextValue); } else if (nextName.equals("type")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } // System.out.println(nextName+"="+nextValue); } list.add(dict); dict = null; jsonReader.endObject(); } jsonReader.endArray(); } catch (IOException e) { if (null != e) { e.printStackTrace(); } } if (null == list || list.size() < 1) { msg_listData.what = MESSAGETYPE_02; } else { msg_listData.what = MESSAGETYPE_01; } handler2.sendMessage(msg_listData); } }).start(); }
From source file:net.evecom.android.EventAddActivity1.java
License:Open Source License
/** * getTreeThree//from ww w.j av a 2s .co m */ private void getTreeThree(final String sbd_id) { progressDialog_getInfo = ProgressDialog.show(EventAddActivity1.this, "", "..."); list.removeAll(list); final Message msg_listData = new Message(); new Thread(new Runnable() { @Override public void run() { String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + sbd_id; String strResult = null; try { strResult = connServerForResult(strUrl); } catch (Exception e) { msg_listData.what = MESSAGETYPE_02; handler3.sendMessage(msg_listData); if (null != e) { e.printStackTrace(); } return; } if (null == strResult || "".equals(strResult)) { msg_listData.what = MESSAGETYPE_02; handler3.sendMessage(msg_listData); return; } // System.out.println(strResult); StringReader reader = new StringReader(strResult); JsonReader jsonReader = new JsonReader(reader); try { jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); SysBaseDict dict = new SysBaseDict(); while (jsonReader.hasNext()) { String nextName = jsonReader.nextName(); String nextValue = ""; if (nextName.equals("id")) { nextValue = jsonReader.nextString(); dict.setSbdCode(nextValue); } else if (nextName.equals("name")) { nextValue = jsonReader.nextString(); dict.setSbdName(nextValue); } else if (nextName.equals("isparent")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } else if (nextName.equals("pid")) { nextValue = jsonReader.nextString(); dict.setSbdPid(nextValue); } else if (nextName.equals("type")) { nextValue = jsonReader.nextString(); dict.setSbdType(nextValue); } } list.add(dict); dict = null; jsonReader.endObject(); } jsonReader.endArray(); } catch (IOException e) { if (null != e) { e.printStackTrace(); } } if (null == list || list.size() < 1) { msg_listData.what = MESSAGETYPE_02; } else { msg_listData.what = MESSAGETYPE_01; } handler3.sendMessage(msg_listData); } }).start(); }
From source file:net.evecom.android.json.JsonMainPersonKeyPersonData.java
License:Open Source License
public static ArrayList<T_PERSON_PERSON> 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 w w w . j a va 2 s .c o m*/ 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<T_PERSON_PERSON>(); jsonReader.beginArray(); while (jsonReader.hasNext()) { jsonReader.beginObject(); T_PERSON_PERSON person_view = new T_PERSON_PERSON(); while (jsonReader.hasNext()) { String nextName = jsonReader.nextName(); String nextValue = ""; if (nextName.equals("PERSONNAME")) { nextValue = jsonReader.nextString(); person_view.setPERSONNAME(nextValue); } else if (nextName.equals("PERSONPHONENO")) { nextValue = jsonReader.nextString(); person_view.setPERSONPHONENO(nextValue); } else if (nextName.equals("PHOTOURL")) { nextValue = jsonReader.nextString(); person_view.setPHOTOURL(nextValue); } else if (nextName.equals("KEYTYPE")) { nextValue = jsonReader.nextString(); person_view.setKEYTYPE(nextValue); } else if (nextName.equals("HOUSEADDR")) { nextValue = jsonReader.nextString(); person_view.setHOUSEADDR(nextValue); } else if (nextName.equals("IDCARDNO")) { nextValue = jsonReader.nextString(); person_view.setIDCARDNO(nextValue); } else if (nextName.equals("MALEDICTID")) { nextValue = jsonReader.nextString(); person_view.setMALEDICTID(nextValue); } else if (nextName.equals("PERSONID")) { nextValue = jsonReader.nextString(); person_view.setPERSONID(nextValue); } } list.add(person_view); person_view = null; jsonReader.endObject(); } jsonReader.endArray(); return list; } else { return null; } }