List of usage examples for com.google.gson.stream JsonReader setLenient
public final void setLenient(boolean lenient)
From source file:org.couchbase.mock.subdoc.Executor.java
License:Apache License
private static <T> T parseStrictJson(String text, Class<T> klass) { try {//from w w w . j a v a2s . c o m JSONValue.parseWithException(text); } catch (ParseException ex) { throw new JsonSyntaxException(ex); } catch (NumberFormatException ex2) { // Ignore number formats. GSON uses BigInteger if it's too big anyway. It's perfectly valid JSON } JsonReader reader = new JsonReader(new StringReader(text)); reader.setLenient(false); return gs.fromJson(reader, klass); }
From source file:org.dfotos.rssfilter.util.Utils.java
License:Open Source License
/** * Conversion JSON(string)->List containing POJO's. * @param pJson JSON as string// www . ja va 2 s. com * @param pType Type specification of items in the returned list. * @return list Of objects created from resultStrJson. Type of each objects * in the List: as specified by "collectionType". */ @SuppressWarnings("rawtypes") public static List convertJsonToPojo(final String pJson, final Type pType) { List<RssItem> result = new ArrayList<RssItem>(); Gson gson = new Gson(); JsonReader reader = new JsonReader(new StringReader(pJson)); reader.setLenient(true); result = gson.fromJson(reader, pType); return result; }
From source file:org.homedns.mkh.databuffer.DataBuffer.java
License:Apache License
/** * Puts data as json string to the data buffer. * /*from www .j ava 2 s. co m*/ * @param sJsonData * the data as json string to put * * @throws SQLException * @throws ParseException * @throws InvalidDatabufferDesc * @throws IOException */ public void putJson(String sJsonData) throws SQLException, ParseException, InvalidDatabufferDesc, IOException { LOG.debug(sJsonData); String[][] data; JsonReader reader = null; try { reader = new JsonReader(new StringReader(sJsonData)); reader.setLenient(true); Gson gson = new Gson(); data = gson.fromJson(reader, String[][].class); } finally { if (reader != null) { reader.close(); } } for (String[] row : data) { moveToInsertRow(); for (Column col : _metaData.getColList()) { Object value = null; String sValue = row[col.getColNum()]; int iType = _metaData.getColumnType(col.getColNum() + 1); try { if (iType == Types.TIMESTAMP) { value = new Timestamp((getEnvironment().getServerDateFormat().parse((sValue)).getTime())); } else if (iType == Types.TINYINT || iType == Types.SMALLINT || iType == Types.INTEGER) { value = new Integer(sValue); } else if (iType == Types.BIGINT) { value = new Long(sValue); } else if (iType == Types.DOUBLE) { value = new Double(sValue); } else if (iType == Types.FLOAT) { value = new Float(sValue); } else if (iType == Types.BOOLEAN) { value = new Boolean(sValue); } else if (iType == Types.VARCHAR) { value = sValue; } } catch (ParseException e) { ParseException ex = new ParseException(col.getName() + ": " + sValue, 0); ex.initCause(e); throw ex; } updateObject(col.getColNum() + 1, value); } insertRow(); moveToCurrentRow(); last(); } LOG.debug("putJson: success"); }
From source file:org.ipvision.byteBuilder.PacketMaker.java
public ArrayList<byte[]> getListOfPackets() { //RequestParameters requestParameters = new RequestParameters(); Gson gson = new Gson(); ArrayList<byte[]> listOfPackets = null; System.out.println(this.request); //System.out.println("ACtion " + authParameters.getAction() + " Client Packet ID " + authParameters.getPacketId()); JsonReader reader = new JsonReader(new StringReader(this.request)); reader.setLenient(true); JsonObject requestObject = gson.fromJson(reader, JsonObject.class); int totalHeaderSize = 0; int action = requestObject.get("actn").getAsInt(); switch (action) { /**//from www.java2 s . c o m * Sign in response */ case 20: { AuthParameters authParameters = gson.fromJson(this.request, AuthParameters.class); UserAuthFeedBack userAuthFeedBack = new UserAuthFeedBack(); userAuthFeedBack.setIsEmailVerified(0); userAuthFeedBack.setOfflineIP("38.127.68.55"); userAuthFeedBack.setMood(1); userAuthFeedBack.setProfileImageId(0); userAuthFeedBack.setUserIdentity(authParameters.getUserIdentity()); // userAuthFeedBack.setSessionID(String.valueOf((new Random().nextInt()) % 100000)); userAuthFeedBack.setSessionID("abaaadsfdf"); userAuthFeedBack.setOfflinePort(1246); userAuthFeedBack.setProfileImage(""); userAuthFeedBack.setSuccess(true); userAuthFeedBack.setPassword(authParameters.getPassword()); userAuthFeedBack.setIsMyNumberVerified(0); userAuthFeedBack.setLiveStatus(2); userAuthFeedBack.setEmoticonVersion(0); userAuthFeedBack.setLastOnlineTime(new Date().getTime()); userAuthFeedBack.setIsPasswordSeted(true); userAuthFeedBack.setFullName("Messi"); userAuthFeedBack.setUserTableID(52349); // String jsonResponse = gson.toJson(userAuthFeedBack); // System.out.println(jsonResponse); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = userAuthFeedBack.getSessionId().getBytes().length; // System.out.println("Session Byte size " + sessionIdBytes); int clientPacketIdBytes = authParameters.getPacketId().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + sessionIdBytes + clientPacketIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, authParameters.getAction(), 4) .addString(Code.CLIENT_PACKET_ID, authParameters.getPacketId()) .addString(Code.SESSION_ID, userAuthFeedBack.getSessionId()).getHeader(); printHeaderBytes(header); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header) .addInt(Code.IS_EMAIL_VERIFIED, userAuthFeedBack.getIsEmailVerified(), 2) .addString(Code.OFFLINE_SERVER_IP, userAuthFeedBack.getOfflineIP()) .addInt(Code.MOOD, userAuthFeedBack.getMood(), 2) .addLong(Code.PROFILE_IMAGE_ID, userAuthFeedBack.getProfileImageId(), 6) .addString(Code.USER_IDENTITY, userAuthFeedBack.getUserIdentity()) .addInt(Code.OFFLINE_SERVER_PORT, userAuthFeedBack.getOfflinePort(), 4) .addString(Code.PROFILE_IMAGE, userAuthFeedBack.getProfileImage()) .addBool(Code.SUCCESS, userAuthFeedBack.isSuccess()) .addString(Code.PASSWORD, userAuthFeedBack.getPassword()) .addInt(Code.IS_MY_NUMBER_VERIFIED, userAuthFeedBack.getIsEmailVerified(), 1) .addInt(Code.LIVE_STATUS, userAuthFeedBack.getLiveStatus(), 2) .addDouble(Code.EMOTICON_VERSION, userAuthFeedBack.getEmoticonVersion()) .addLong(Code.LAST_ONLINE_TIME, userAuthFeedBack.getLastOnlineTime(), 8) .addBool(Code.PASSWORD_SETED, userAuthFeedBack.getIsPasswordSeted()) .addString(Code.USER_NAME, userAuthFeedBack.getFullName()) .addLong(Code.USER_ID, userAuthFeedBack.getUserTableID(), 8).build(); break; } /** * * Email verification code request & verification confirmation * response */ case 220: { AuthParameters authParameters = gson.fromJson(this.request, AuthParameters.class); JsonObject jsonObject = gson.fromJson(this.request, JsonObject.class); UserAuthFeedBack userAuthFeedBack = new UserAuthFeedBack(); String authParamString = gson.toJson(authParameters); System.out.println(authParamString); int Type = 2; int Length = 1; int actionBytes = 4; int clientPacketIdBytes = authParameters.getPacketId().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); byte[] header = null; listOfPackets = null; //System.err.println(authParameters.getEmailVerificationCode()); totalHeaderSize = 2 * (Type + Length) + actionBytes + clientPacketIdBytes; header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, authParameters.getAction(), 4) .addString(Code.CLIENT_PACKET_ID, authParameters.getPacketId()).getHeader(); printHeaderBytes(header); String verificationCode = jsonObject.get("evc").getAsString(); if (verificationCode != null) { String emailVerification = "1000"; if (!verificationCode.equals(emailVerification)) { userAuthFeedBack.setSuccess(false); userAuthFeedBack.setMessage("Verification code failed. Please Try again"); userAuthFeedBack.setReasonCode(0); listOfPackets = new ByteBuilder().setHeader(header) .addBool(Code.SUCCESS, userAuthFeedBack.isSuccess()) .addString(Code.MESSAGE, userAuthFeedBack.getMessage()) .addString(Code.EMAIL_VERIFICATION_CODE, verificationCode) .addInt(Code.REASON_CODE, userAuthFeedBack.getReasonCode(), 4).build(); } else { userAuthFeedBack.setSuccess(true); userAuthFeedBack.setReasonCode(0); listOfPackets = new ByteBuilder().setHeader(header) .addBool(Code.SUCCESS, userAuthFeedBack.isSuccess()) .addString(Code.EMAIL_VERIFICATION_CODE, verificationCode) .addInt(Code.REASON_CODE, userAuthFeedBack.getReasonCode(), 4).build(); } } else { userAuthFeedBack.setSuccess(true); userAuthFeedBack.setMessage("Verification is sent to your mobile"); userAuthFeedBack.setReasonCode(28); listOfPackets = new ByteBuilder().setHeader(header) .addBool(Code.SUCCESS, userAuthFeedBack.isSuccess()) .addString(Code.MESSAGE, userAuthFeedBack.getMessage()) .addInt(Code.REASON_CODE, userAuthFeedBack.getReasonCode(), 4).build(); } break; } /** * * User update request responses */ case 126: { AuthParameters authParameters = gson.fromJson(this.request, AuthParameters.class); String responseString = "{\"sucs\":true,\"dwnMnd\":false,\"uId\":\"2110077639\",\"nm\":\"Neymar\",\"uIdChng\":false,\"uf\":1,\"pstd\":false,\"usrPw\":\"123456\",\"rc\":0}"; UserAuthFeedBack userAuthFeedBack = new Gson().fromJson(responseString, UserAuthFeedBack.class); String sessionId = UUID.randomUUID().toString(); // String jsonResponse = gson.toJson(userAuthFeedBack); // System.out.println(jsonResponse); int Type = 2; int Length = 1; int actionBytes = 4; int clientPacketIdBytes = authParameters.getPacketId().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionId.length(); // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, authParameters.getAction(), 4) .addString(Code.SESSION_ID, sessionId) .addString(Code.CLIENT_PACKET_ID, authParameters.getPacketId()).getHeader(); printHeaderBytes(header); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header) .addBool(Code.DOWNLOAD_MANDATORY, userAuthFeedBack.getDownloadMandatory()) .addString(Code.USER_IDENTITY, userAuthFeedBack.getUserIdentity()) .addBool(Code.SUCCESS, userAuthFeedBack.isSuccess()) .addString(Code.PASSWORD, userAuthFeedBack.getPassword()) .addString(Code.USER_NAME, userAuthFeedBack.getName()) .addBool(Code.USER_ID_CHANGE, userAuthFeedBack.getUserIdChanged()) .addInt(Code.USER_FOUND, userAuthFeedBack.getUserFound(), 4) .addBool(Code.PASSWORD_SETED, userAuthFeedBack.getIsPasswordSeted()) .addInt(Code.REASON_CODE, userAuthFeedBack.getReasonCode(), 2).build(); break; } /** * * Add friend response */ case Code.TYPE_ADD_FRIEND: { AuthParameters authParameters = gson.fromJson(this.request, AuthParameters.class); String responseString = "{\"sucs\":true,\"uId\":\"2110010016\",\"fn\":\"A 10016\",\"gr\":\"\",\"frnS\":3,\"prIm\":\"cloud/uploaded-136/2110010016/4176251453118517972.jpg\",\"prImId\":9928,\"utId\":9, \"ct\":2,\"nmf\":2,\"mb\":0,\"ut\":1457422058660,\"cla\":1,\"chta\":1,\"fda\":1}"; ContactFeedBack contactFeedBack = new Gson().fromJson(responseString, ContactFeedBack.class); // String jsonResponse = gson.toJson(userAuthFeedBack); // System.out.println(jsonResponse); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = authParameters.getSessionId().length(); int clientPacketIdBytes = authParameters.getPacketId().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, authParameters.getAction(), 4) .addString(Code.CLIENT_PACKET_ID, authParameters.getPacketId()) .addString(Code.SESSION_ID, authParameters.getSessionId()).getHeader(); printHeaderBytes(header); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header) .addString(Code.USER_IDENTITY, authParameters.getUserIdentity()) .addBool(Code.SUCCESS, contactFeedBack.isSuccess()) .addString(Code.USER_NAME, contactFeedBack.getFullName()) .addString(Code.GENDER, contactFeedBack.getGender()) .addString(Code.PROFILE_IMAGE, contactFeedBack.getProfileImage()) .addLong(Code.PROFILE_IMAGE_ID, contactFeedBack.getProfileImageId(), 8) .addLong(Code.USER_ID, contactFeedBack.getUserTableID(), 8) .addInt(Code.CONTACT_TYPE, contactFeedBack.getContactType(), 4) .addInt(Code.MUTUAL_FRIEND_COUNT, contactFeedBack.getNoOfMutualFriends(), 4) .addInt(Code.MATCH_BY, contactFeedBack.getMatchedBy(), 4) .addLong(Code.UPDATE_TIME, contactFeedBack.getUpdateTime(), 8) .addInt(Code.CALL_ACCESS, contactFeedBack.getCallAccess(), 4) .addInt(Code.CHAT_ACCESS, contactFeedBack.getChatAccess(), 4) .addInt(Code.FEED_ACCESS, contactFeedBack.getFeedAccess(), 4).build(); break; } case Code.TYPE_DELETE_FRIEND: { AuthParameters authParameters = gson.fromJson(this.request, AuthParameters.class); String responseString = "{\"uId\":\"2110067045\",\"utId\":52559,\"sucs\":true,\"rc\":0}"; ContactFeedBack contactFeedBack = new Gson().fromJson(responseString, ContactFeedBack.class); // String jsonResponse = gson.toJson(userAuthFeedBack); // System.out.println(jsonResponse); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = authParameters.getSessionId().length(); int clientPacketIdBytes = authParameters.getPacketId().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, authParameters.getAction(), 4) .addString(Code.CLIENT_PACKET_ID, authParameters.getPacketId()) .addString(Code.SESSION_ID, authParameters.getSessionId()).getHeader(); printHeaderBytes(header); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header) .addString(Code.USER_IDENTITY, authParameters.getUserIdentity()) .addBool(Code.SUCCESS, contactFeedBack.isSuccess()) .addLong(Code.USER_ID, contactFeedBack.getUserTableID(), 8) .addInt(Code.REASON_CODE, contactFeedBack.getReasonCode(), 4).build(); break; } case Code.TYPE_ACCEPT_FRIEND: { AuthParameters authParameters = gson.fromJson(this.request, AuthParameters.class); String responseString = "{\"sucs\":true,\"uId\":\"2110067045\",\"fn\":\"Tuhin\",\"gr\":\"\",\"frnS\":1,\"prIm\":\"\",\"prImId\":0,\"utId\":52559,\"ct\":2,\"nmf\":6,\"ut\":1457422535496,\"cla\":1,\"chta\":1,\"fda\":1}"; ContactFeedBack contactFeedBack = new Gson().fromJson(responseString, ContactFeedBack.class); // String jsonResponse = gson.toJson(userAuthFeedBack); // System.out.println(jsonResponse); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = authParameters.getSessionId().length(); int clientPacketIdBytes = authParameters.getPacketId().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, authParameters.getAction(), 4) .addString(Code.CLIENT_PACKET_ID, authParameters.getPacketId()) .addString(Code.SESSION_ID, authParameters.getSessionId()).getHeader(); printHeaderBytes(header); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header) .addString(Code.USER_IDENTITY, contactFeedBack.getUserIdentity()) .addBool(Code.SUCCESS, contactFeedBack.isSuccess()) .addString(Code.USER_NAME, contactFeedBack.getFullName()) .addString(Code.GENDER, contactFeedBack.getGender()) .addInt(Code.FRIENDSHIP_STATUS, contactFeedBack.getFriendShipStatus(), 4) .addString(Code.PROFILE_IMAGE, contactFeedBack.getProfileImage()) .addLong(Code.PROFILE_IMAGE_ID, contactFeedBack.getProfileImageId(), 8) .addLong(Code.USER_ID, contactFeedBack.getUserTableID(), 8) .addInt(Code.CONTACT_TYPE, contactFeedBack.getContactType(), 4) .addInt(Code.MUTUAL_FRIEND_COUNT, contactFeedBack.getNoOfMutualFriends(), 4) .addLong(Code.UPDATE_TIME, contactFeedBack.getUpdateTime(), 8) .addInt(Code.CALL_ACCESS, contactFeedBack.getCallAccess(), 4) .addInt(Code.CHAT_ACCESS, contactFeedBack.getChatAccess(), 4) .addInt(Code.FEED_ACCESS, contactFeedBack.getFeedAccess(), 4).build(); break; } case Code.TYPE_ACTION_UPDATE_CONTACT_ACCESS: { AuthParameters authParameters = gson.fromJson(this.request, AuthParameters.class); String responseString = "{\"utId\":52349,\"sucs\":true,\"sn\":6,\"sv\":0,\"rc\":0}"; FeedBack feedBack = new Gson().fromJson(responseString, FeedBack.class); JsonObject jsonObject = gson.fromJson(this.request, JsonObject.class); feedBack.setSettingsName(jsonObject.get("sn").getAsInt()); feedBack.setSettingsValue(jsonObject.get("sv").getAsInt()); feedBack.setUserTableID(jsonObject.get("utId").getAsLong()); // String jsonResponse = gson.toJson(userAuthFeedBack); // System.out.println(jsonResponse); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = authParameters.getSessionId().length(); int clientPacketIdBytes = authParameters.getPacketId().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, authParameters.getAction(), 4) .addString(Code.CLIENT_PACKET_ID, authParameters.getPacketId()) .addString(Code.SESSION_ID, authParameters.getSessionId()).getHeader(); printHeaderBytes(header); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header).addBool(Code.SUCCESS, feedBack.isSuccess()) .addInt(Code.SETTINGS_NAME, feedBack.getSettingsName(), 4) .addInt(Code.SETTINGS_VALUE, feedBack.getSettingsValue(), 4) .addLong(Code.USER_ID, feedBack.getUserTableID(), 8) .addInt(Code.REASON_CODE, feedBack.getReasonCode(), 4).build(); break; } case Code.TYPE_SEND_REGISTER: { String responseString = "{\"fndId\":\"2110067045\",\"swIp\":\"38.127.68.57\",\"swPr\":1250,\"sucs\":true,\"psnc\":2,\"mood\":1,\"dvc\":2,\"callID\":\"jCRGryWt14608826592710249\",\"tm\":5688689304929771,\"dt\":\"dG6hFdvYraw:APA91bG0e23l164jp0liUyj9DPvoFUdT4419JvGmroyhgMHWcFnugpspvAyyzyjNAQkccDkg2cRs_LlostHH7myOBioOYyq0C6crpuGMgr-kXZ50mK63FamOY1QHECo_xMRzOP-H7ecZ\",\"fn\":\"Tuhin\",\"idc\":false,\"apt\":1,\"calT\":1,\"p2p\":2,\"rpt\":1}"; // FeedBack feedBack = new Gson().fromJson(responseString, FeedBack.class); JsonObject jsonObject = gson.fromJson(this.request, JsonObject.class); CallParameters callParameters = gson.fromJson(responseString, CallParameters.class); callParameters.setAction(jsonObject.get("actn").getAsInt()); callParameters.setFriendId(jsonObject.get("fndId").getAsLong()); callParameters.setSessionId(jsonObject.get("sId").getAsString()); callParameters.setPacketId(jsonObject.get("pckId").getAsString()); callParameters.setCallID(jsonObject.get("callID").getAsString()); if (callParameters.getMessage() == null) { callParameters.setMessage(""); } if (callParameters.getDeviceToken() == null) { callParameters.setDeviceToken(""); } // String jsonResponse = gson.toJson(userAuthFeedBack); // System.out.println(jsonResponse); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = callParameters.getSessionId().length(); int clientPacketIdBytes = callParameters.getPacketId().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, callParameters.getAction(), 4) .addString(Code.CLIENT_PACKET_ID, callParameters.getPacketId()) .addString(Code.SESSION_ID, callParameters.getSessionId()).getHeader(); printHeaderBytes(header); System.out.println(callParameters.getSwitchIp()); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header) .addLong(Code.FRIEND_ID, callParameters.getFriendId(), 8) .addString(Code.SWITCH_IP, callParameters.getSwitchIp()) .addInt(Code.SWITCH_PORT, callParameters.getSwitchPort(), 4) .addBool(Code.SUCCESS, callParameters.isSuccess()) .addInt(Code.PRESENCE, callParameters.getPresence(), 4) .addInt(Code.MOOD, callParameters.getMood(), 4) .addInt(Code.DEVICE, callParameters.getDevice(), 4) .addString(Code.CALL_ID, callParameters.getCallID()) .addLong(Code.CALL_TIME, callParameters.getCallTime(), 8) .addString(Code.DEVICE_TOKEN, callParameters.getDeviceToken()) .addString(Code.USER_NAME, callParameters.getFullName()) .addBool(Code.IS_DIVERTED_CALL, callParameters.getIsDivertedCall()) .addInt(Code.APPLICATION_TYPE, callParameters.getAppType(), 4) .addInt(Code.P2P_STATUS, callParameters.getP2pCallStatus(), 4) .addInt(Code.REMOTE_PUSH_TYPE, callParameters.getRemotePushType(), 4) .addString(Code.MESSAGE, callParameters.getMessage()).build(); break; } case Code.TYPE_ACTION_STORE_CONTACT_LIST: { break; } case Code.ACTION_USER_SHORT_DETAILS: { String responseString = "{\"sucs\":true,\"userDetails\":{\"uId\":\"2110033856\",\"fn\":\"Bptpzsbcub\",\"prIm\":\"xxxxx\",\"cIm\":\"yyyyy\",\"prImId\":0,\"prImPr\":1,\"utId\":22061,\"ispc\":1,\"isepc\":1,\"frnS\":1,\"fda\":1,\"cla\":1,\"chta\":1},\"utId\":22061}"; // FeedBack feedBack = new Gson().fromJson(responseString, FeedBack.class); JsonReader responseReader = new JsonReader(new StringReader(responseString)); responseReader.setLenient(true); JsonObject responseObject = gson.fromJson(responseReader, JsonObject.class); UserDetailsFeedBack userDetailsFeedBack = gson.fromJson(responseObject, UserDetailsFeedBack.class); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = requestObject.get("sId").getAsString().getBytes().length; int clientPacketIdBytes = requestObject.get("pckId").getAsString().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, action, 4) .addString(Code.CLIENT_PACKET_ID, requestObject.get("pckId").getAsString()) .addString(Code.SESSION_ID, requestObject.get("sId").getAsString()).getHeader(); printHeaderBytes(header); UserDTO userDTO = gson.fromJson(responseObject.get("userDetails").getAsJsonObject(), UserDTO.class); System.out.println(userDTO.getUserIdentity()); byte[] userDTObytes = new ListByteBuilder().addString(Code.USER_IDENTITY, userDTO.getUserIdentity()) .addString(Code.USER_NAME, userDTO.getFullName()) .addString(Code.PROFILE_IMAGE, userDTO.getProfileImage()) .addLong(Code.PROFILE_IMAGE_ID, userDTO.getProfileImageId(), 8) .addLong(Code.USER_ID, userDTO.getUserTableID(), 8) .addInt(Code.IS_PICKED_FROM_PHONE, userDTO.getIsNumberPicked(), 4) .addInt(Code.IS_PICKED_EMAIL_FROM_PHONE, userDTO.getIsEmailPicked(), 4) .addInt(Code.FRIENDSHIP_STATUS, userDTO.getFriendShipStatus(), 2) .addInt(Code.FEED_ACCESS, userDTO.getFeedAccess(), 1) .addInt(Code.CALL_ACCESS, userDTO.getCallAccess(), 1) .addInt(Code.CHAT_ACCESS, userDTO.getChatAccess(), 1).getListBytes(); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header) .addBool(Code.SUCCESS, userDetailsFeedBack.isSuccess()).addByte(Code.USER_DETAILS, userDTObytes) .addLong(Code.USER_ID, userDTO.getUserTableID(), 8).build(); break; } case Code.ACTION_BLOCK_UNBLOCK_FRIEND: { String responseString = "{\"sucs\":true,\"bv\":1,\"rc\":0,\"idList\":[52349],\"cla\":1,\"chta\":1,\"fda\":1}"; FeedBack feedBack = gson.fromJson(responseString, FeedBack.class); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = requestObject.get("sId").getAsString().getBytes().length; int clientPacketIdBytes = requestObject.get("pckId").getAsString().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, action, 4) .addString(Code.CLIENT_PACKET_ID, requestObject.get("pckId").getAsString()) .addString(Code.SESSION_ID, requestObject.get("sId").getAsString()).getHeader(); printHeaderBytes(header); ArrayList<Long> idList = feedBack.getUserIds(); listOfPackets = new ArrayList<>(); ByteBuilder byteBuilder = new ByteBuilder().setHeader(header) .addBool(Code.SUCCESS, feedBack.isSuccess()) .addInt(Code.BLOCK_VALUE, feedBack.getBlockValue(), 4) .addInt(Code.REASON_CODE, feedBack.getReasonCode(), 4) .addInt(Code.CALL_ACCESS, feedBack.getCallAccess(), 4) .addInt(Code.CHAT_ACCESS, feedBack.getChatAccess(), 4) .addInt(Code.FEED_ACCESS, feedBack.getFeedAccess(), 4); for (Long id : idList) { System.out.println(id); byteBuilder = byteBuilder.addLong(Code.USER_IDENTITY, id, 8); } listOfPackets = byteBuilder.build(); break; } case Code.TYPE_CHECK_PRESENCE: { String responseString = "{\"fndId\":\"2110067045\",\"psnc\":3,\"dvc\":2,\"sucs\":true,\"lot\":1460868436099,\"mood\":1,\"isclb\":false}"; ChatParameters chatParameters = gson.fromJson(responseString, ChatParameters.class); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = requestObject.get("sId").getAsString().getBytes().length; int clientPacketIdBytes = requestObject.get("pckId").getAsString().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, action, 4) .addString(Code.CLIENT_PACKET_ID, requestObject.get("pckId").getAsString()) .addString(Code.SESSION_ID, requestObject.get("sId").getAsString()).getHeader(); printHeaderBytes(header); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header) .addLong(Code.FRIEND_ID, Long.parseLong(chatParameters.getFriendIdentity()), 8) .addBool(Code.SUCCESS, chatParameters.isSuccess()) .addInt(Code.PRESENCE, chatParameters.getPresence(), 4) .addInt(Code.MOOD, chatParameters.getMood(), 4) .addInt(Code.DEVICE, chatParameters.getDevice(), 4) .addLong(Code.LAST_ONLINE_TIME, chatParameters.getLastOnlineTime(), 8) .addBool(Code.IS_CELEBRITY, chatParameters.isIsCelebrity()).build(); break; } case Code.TYPE_START_FRIEND_CHAT: { String responseString = "{\"fndId\":\"2110067045\",\"sucs\":false,\"psnc\":3,\"dvc\":2," + "\"dt\":\"dG6hFdvYraw:APA91bG0e23l164jp0liUyj9DPvoFUdT4419JvGmroyhgMHWcFnugpspvAyyzyjNAQkccDkg2cRs_LlostHH7myOBioOYyq0C6crpuGMgr-kXZ50mK63FamOY1QHECo_xMRzOP-H7ecZ\"," + "\"lot\":1460868436099,\"nm\":\"Tuhin\",\"rc\":0,\"apt\":1,\"mood\":1,\"utId\":52559,\"isclb\":false,\"rpt\":1}"; ChatParameters chatParameters = gson.fromJson(responseString, ChatParameters.class); int Type = 2; int Length = 1; int actionBytes = 4; int sessionIdBytes = requestObject.get("sId").getAsString().getBytes().length; int clientPacketIdBytes = requestObject.get("pckId").getAsString().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 3 * (Type + Length) + actionBytes + clientPacketIdBytes + sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, action, 4) .addString(Code.CLIENT_PACKET_ID, requestObject.get("pckId").getAsString()) .addString(Code.SESSION_ID, requestObject.get("sId").getAsString()).getHeader(); printHeaderBytes(header); listOfPackets = new ArrayList<>(); listOfPackets = new ByteBuilder().setHeader(header) .addLong(Code.FRIEND_ID, Long.parseLong(chatParameters.getFriendIdentity()), 8) .addBool(Code.SUCCESS, chatParameters.isSuccess()) .addInt(Code.PRESENCE, chatParameters.getPresence(), 4) .addInt(Code.MOOD, chatParameters.getMood(), 4) .addInt(Code.DEVICE, chatParameters.getDevice(), 4) .addLong(Code.LAST_ONLINE_TIME, chatParameters.getLastOnlineTime(), 8) .addBool(Code.IS_CELEBRITY, chatParameters.isIsCelebrity()) .addString(Code.DEVICE_TOKEN, chatParameters.getDeviceToken()) .addString(Code.FRIEND_NAME, chatParameters.getName()) .addInt(Code.APPLICATION_TYPE, chatParameters.getAppType(), 4) .addLong(Code.USER_ID, chatParameters.getUserTableID(), 8) .addInt(Code.REMOTE_PUSH_TYPE, chatParameters.getRemotePushType(), 4) .addInt(Code.REASON_CODE, chatParameters.getReasonCode(), 4).build(); break; } case Code.ACTION_USERS_DETAILS: { String responseString = "[{\"seq\":\"1/2\",\"contactList\":[{\"ringID\":2110010067,\"uId\":\"2110010067\",\"fn\":\"Wahid_Love_IPvision\",\"gr\":\"Male\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"cloud/uploaded-141/2110010067/4054441459979400103.jpg\",\"prImId\":13757,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":56,\"ut\":1460887625947,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":6,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0},{\"ringID\":2110011243,\"uId\":\"2110011243\",\"fn\":\"Call Test\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"cloud/uploaded-139/2110011243/10139411457539176533.jpg\",\"prImId\":12981,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":642,\"ut\":1457521034826,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":2,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0},{\"ringID\":2110067262,\"uId\":\"2110067262\",\"fn\":\"Salah Uddin\",\"gr\":\"Male\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"\",\"prImId\":0,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":55555,\"ut\":1455195888148,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":2,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0},{\"ringID\":2110071649,\"uId\":\"2110071649\",\"fn\":\"Rajib Pal\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"\",\"prImId\":0,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":55545,\"ut\":1455290367739,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":0,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0},{\"ringID\":2110066959,\"uId\":\"2110066959\",\"fn\":\"Mizan Test\",\"gr\":\"Male\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"\",\"prImId\":0,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":52548,\"ut\":1451209874994,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":0,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0}],\"sucs\":true,\"tr\":10} ,\n" + " {\"seq\":\"2/2\",\"contactList\":[{\"ringID\":2110074941,\"uId\":\"2110074941\",\"fn\":\"FINAL RELEASE\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"\",\"prImId\":0,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":56448,\"ut\":1460958817088,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":1,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0},{\"ringID\":2110010031,\"uId\":\"2110010031\",\"fn\":\"Jhon Snow\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"cloud/uploaded-136/2110010031/3494261453710895305.jpg\",\"prImId\":10449,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":25,\"ut\":1459254948848,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":1,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0},{\"ringID\":2110010188,\"uId\":\"2110010188\",\"fn\":\"towhid\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"2110010188/1442394235711.jpg\",\"prImId\":369,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":448,\"ut\":1455193190172,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":0,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0},{\"ringID\":2110010028,\"uId\":\"2110010028\",\"fn\":\"Alamgir Kabir\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"\",\"prImId\":0,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":18,\"ut\":1436424093413,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":0,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0},{\"ringID\":2110075137,\"uId\":\"2110075137\",\"fn\":\"naseeftest\",\"cnId\":0,\"bDay\":0,\"psnc\":0,\"dvc\":0,\"prIm\":\"\",\"prImId\":0,\"cImId\":0,\"prImPr\":1,\"isf\":false,\"utId\":56483,\"ut\":1455203044296,\"cut\":0,\"ists\":0,\"actv\":0,\"mtl\":false,\"nmf\":0,\"nvldt\":0,\"cimX\":0,\"cimY\":0,\"ispc\":0,\"isepc\":0,\"ismnv\":0,\"iev\":0,\"ianv\":0,\"wle\":0,\"ple\":0,\"itp\":0,\"ct\":0,\"frnS\":0,\"mDay\":0,\"bv\":0,\"rc\":0,\"del\":0,\"mb\":0,\"cft\":0,\"apt\":0,\"fda\":0,\"cla\":0,\"chta\":0,\"anc\":0,\"mfc\":0,\"maxID\":0}],\"sucs\":true,\"tr\":10}]"; /* Type listType = new TypeToken<ArrayList<ContactListDTO>>() { }.getType(); JsonParser parser = new JsonParser(); JsonElement tradeElement = parser.parse(responseString); JsonArray trade = tradeElement.getAsJsonArray(); List<ContactListDTO> contactLists = new Gson().fromJson(trade, listType);*/ JsonReader responseReader = new JsonReader(new StringReader(responseString)); responseReader.setLenient(true); ContactListDTO[] contactListDTOs = new Gson().fromJson(responseReader, ContactListDTO[].class); //ContactListDTO contactListDTO = gson.fromJson(responseString, ContactListDTO.class); int Type = 1; int Length = 1; int actionBytes = 4; int sessionIdBytes = requestObject.get("sId").getAsString().getBytes().length; int clientPacketIdBytes = requestObject.get("pckId").getAsString().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); totalHeaderSize = 4 * (Type + Length) + actionBytes + clientPacketIdBytes + 2 * sessionIdBytes; // System.out.println("Total header size " + totalHeaderSize); byte[] header = new BrokenHeaderBuilder(totalHeaderSize) .addString(Code.UNIQUE_KEY, requestObject.get("sId").getAsString()) .addInt(Code.ACTION, action, 4) .addString(Code.CLIENT_PACKET_ID, requestObject.get("pckId").getAsString()) .addString(Code.SESSION_ID, requestObject.get("sId").getAsString()).getBrokenHeader(); printHeaderBytes(header); // List<UserDTO> contactList = contactListDTO.getContactList(); listOfPackets = new ArrayList<>(); ListByteBuilder listBuilder = new ListByteBuilder(); ByteBuilder byteBuilder = new ByteBuilder().setHeader(header); for (ContactListDTO contactListDTO : contactListDTOs) { List<UserDTO> contactList = contactListDTO.getContactList(); for (UserDTO userDTO : contactList) { if (userDTO.getGender() == null) { userDTO.setGender(" "); } listBuilder = listBuilder .addLong(Code.USER_IDENTITY, Long.parseLong(userDTO.getUserIdentity()), 8) .addString(Code.USER_NAME, userDTO.getFullName()) .addString(Code.GENDER, userDTO.getGender()) .addInt(Code.COUNTRY_ID, userDTO.getCountryID(), 4) .addLong(Code.BIRTH_DATE, userDTO.getBirthDate(), 8) .addInt(Code.PRESENCE, userDTO.getPresence(), 4) .addInt(Code.DEVICE, userDTO.getDevice(), 4) .addString(Code.PROFILE_IMAGE, userDTO.getProfileImage()) .addLong(Code.PROFILE_IMAGE_ID, userDTO.getProfileImageId(), 8) .addLong(Code.COVER_IMAGE_ID, userDTO.getCoverImageId(), 8) .addInt(Code.PRIVACY, userDTO.getProfileImagePrivacy(), 4) .addBool(Code.FRIENDSHIP_STATUS, userDTO.getIsFriend()) .addLong(Code.USER_ID, userDTO.getUserTableID(), 8) .addLong(Code.UPDATE_TIME, userDTO.getUpdateTime(), 8) .addLong(Code.CONTACT_UPDATE_TIME, userDTO.getContactUpdateTime(), 8) .addInt(Code.STATUS, userDTO.getStatus(), 4) .addInt(Code.IS_ACTIVE, userDTO.getIsActive(), 4) .addBool(Code.IS_MUTUAL, userDTO.getMutual()) .addInt(Code.NO_MUTUAL_FRIENDS, userDTO.getNoOfMutualFriends(), 4) .addInt(Code.NOTIFICATION_VALIDITY, userDTO.getNotificationValidity(), 4) .addInt(Code.COVER_IMAGE_X, userDTO.getCoverImageX(), 4) .addInt(Code.COVER_IMAGE_Y, userDTO.getCoverImageY(), 4) .addInt(Code.IS_PICKED_EMAIL_FROM_PHONE, userDTO.getIsEmailPicked(), 4) .addInt(Code.IS_PICKED_FROM_PHONE, userDTO.getIsNumberPicked(), 4) .addInt(Code.IS_MY_NUMBER_VERIFIED, userDTO.getIsNumberVerified(), 4) .addInt(Code.IS_EMAIL_VERIFIED, userDTO.getIsEmailVerified(), 4) .addInt(Code.WEB_LOGIN_ENABLED, userDTO.getWebLoginEnabled(), 4) .addInt(Code.PC_LOGIN_ENABLED, userDTO.getPcLoginEnabled(), 4) .addInt(Code.INFORMATION_TYPE, userDTO.getInformationType(), 4) .addInt(Code.CONTACT_TYPE, userDTO.getContactType(), 4) .addInt(Code.FRIENDSHIP_STATUS, userDTO.getFriendShipStatus(), 4) .addLong(Code.MARRIAGE_DAY, userDTO.getMarriageDay(), 8) .addInt(Code.BLOCK_VALUE, userDTO.getBlockValue(), 4) .addInt(Code.REASON_CODE, userDTO.getReasonCode(), 4) .addInt(Code.MATCH_BY, userDTO.getMathedBy(), 4) .addLong(Code.CALL_FORWARD_TO, userDTO.getCallForwardTo(), 8) .addInt(Code.CALL_ACCESS, userDTO.getCallAccess(), 4) .addInt(Code.CHAT_ACCESS, userDTO.getChatAccess(), 4) .addInt(Code.FEED_ACCESS, userDTO.getFeedAccess(), 4) .addInt(Code.APPLICATION_TYPE, userDTO.getAppType(), 4) .addInt(Code.ANONYMOUS_CALL, userDTO.getAnonymousCall(), 4) .addInt(Code.MUTUAL_FRIEND_COUNT, userDTO.getMutualFriendCount(), 4); } listBuilder = listBuilder.addBool(Code.SUCCESS, contactListDTO.isSuccess()) .addInt(Code.TOTAL_RECORDS, contactListDTO.getTotalRecord(), 4); byte[] bytes = listBuilder.getListBytes(); /* System.out.println(bytes.length); for (byte aByte : bytes) { System.out.print(aByte +" "); } System.out.println("*****");*/ byteBuilder = byteBuilder.addBrokenBytes(Code.CONTACT, bytes); } listOfPackets = byteBuilder.build(); break; } case Code.ACTION_MOBILE_VERIFICATION: { String responseString = "{\"sucs\":true,\"mg\":\"Verification code has been sent to your phone no.\",\"rc\":0}"; AuthParameters authParameters = gson.fromJson(this.request, AuthParameters.class); JsonObject jsonObject = gson.fromJson(this.request, JsonObject.class); UserAuthFeedBack userAuthFeedBack = new Gson().fromJson(responseString, UserAuthFeedBack.class); String authParamString = gson.toJson(authParameters); int Type = 2; int Length = 1; int actionBytes = 4; int clientPacketIdBytes = authParameters.getPacketId().getBytes().length; // System.out.println("Client Packet Id Byte size " + clientPacketIdBytes); listOfPackets = null; //System.err.println(authParameters.getEmailVerificationCode()); totalHeaderSize = 2 * (Type + Length) + actionBytes + clientPacketIdBytes; byte[] header = new HeaderBuilder(totalHeaderSize).addInt(Code.ACTION, authParameters.getAction(), 4) .addString(Code.CLIENT_PACKET_ID, authParameters.getPacketId()).getHeader(); printHeaderBytes(header); authParameters.setVerificationCode(" "); ; System.out.println(userAuthFeedBack.getMessage()); listOfPackets = listOfPackets = new ByteBuilder().setHeader(header) .addBool(Code.SUCCESS, userAuthFeedBack.isSuccess()) .addString(Code.MESSAGE, userAuthFeedBack.getMessage()) .addString(Code.MY_NUMBER_VERIFICATION_CODE, authParameters.getVerificationCode()) .addInt(Code.REASON_CODE, userAuthFeedBack.getReasonCode(), 4).build(); break; } } return listOfPackets; }
From source file:org.jclouds.http.functions.ParseFirstJsonValueNamed.java
License:Apache License
@Override public T apply(HttpResponse arg0) { if (arg0.getPayload() == null) return nothing(); JsonReader reader = null; try {/* ww w . ja v a 2 s . com*/ reader = new JsonReader(new InputStreamReader(arg0.getPayload().getInput())); // in case keys are not in quotes reader.setLenient(true); AtomicReference<String> name = Atomics.newReference(); JsonToken token = reader.peek(); for (; token != JsonToken.END_DOCUMENT && nnn(reader, token, name); token = skipAndPeek(token, reader)) { } if (name.get() == null) { logger.trace("did not object named %s in json from response %s", nameChoices, arg0); return nothing(); } else if (nameChoices.contains(name.get())) { return json.delegate().<T>fromJson(reader, type.getType()); } else { return nothing(); } } catch (IOException e) { throw new RuntimeException( String.format("error reading from stream, parsing object named %s from http response %s", nameChoices, arg0), e); } finally { Closeables2.closeQuietly(reader); arg0.getPayload().release(); } }
From source file:org.kurento.commons.ConfigFilePropertyHolder.java
License:Apache License
public static synchronized void configurePropertiesFromConfigFile(Path configFilePath) throws JsonSyntaxException, JsonIOException, IOException { boolean singleConfigFile = Boolean.getBoolean(SINGLE_CONFIG_FILES_PROPERTY); if (singleConfigFile && lastLoadedConfigFilePath != null) { log.warn("Trying to load a second config file. The first was {} and the " + "current is {}. Ignoring it.", lastLoadedConfigFilePath, configFilePath); return;//from w w w .ja v a 2 s. c o m } ConfigFilePropertyHolder cfph = null; PropertyHolder ph = PropertiesManager.getPropertyHolder(); if (ph != null && ph instanceof ConfigFilePropertyHolder) { cfph = (ConfigFilePropertyHolder) ph; if (cfph.loadedPaths != null) { if (cfph.loadedPaths.contains(configFilePath)) { log.debug("Trying to load again config file {}. Ignoring it.", configFilePath.toAbsolutePath()); return; } } } lastLoadedConfigFilePath = configFilePath; // FIXME shouldn't this be the first sentence in the method? Preconditions.checkNotNull(configFilePath, "configFilePath paramter must be not null."); log.debug("Using configuration file in path '{}' ({})", configFilePath, configFilePath.getClass().getCanonicalName()); JsonReader reader = new JsonReader(Files.newBufferedReader(configFilePath, StandardCharsets.UTF_8)); reader.setLenient(true); JsonObject configFile = gson.fromJson(reader, JsonObject.class); traceConfigContent(configFile); if (cfph == null) { cfph = new ConfigFilePropertyHolder(); } cfph.loadedConfigFiles.add(new ConfigFileObject(configFilePath, configFile)); cfph.loadedPaths.add(configFilePath); PropertiesManager.setPropertyHolder(cfph); }
From source file:org.kurento.tutorial.magicmirror.MagicMirrorRest.java
License:Open Source License
private JsonObject createJson(String bMessage) { JsonReader reader = new JsonReader(new StringReader(bMessage)); reader.setLenient(true); JsonObject request = (JsonObject) new JsonParser().parse(reader); JsonObject response = new JsonObject(); response.addProperty("id", "rest"); response.add("source", request.get("source")); response.add("description", request.get("description")); response.add("value", request.get("value")); return response; }
From source file:org.lanternpowered.server.data.persistence.json.JsonDataFormat.java
License:MIT License
private static JsonReader createReader(String content, boolean lenient) { final JsonReader jsonReader = new JsonReader(new StringReader(content)); if (lenient) { jsonReader.setLenient(true); }/*from w ww . j a va2 s . c o m*/ return jsonReader; }
From source file:org.onos.yangtools.yang.data.codec.gson.JsonParserStream.java
License:Open Source License
public JsonParserStream parse(final JsonReader reader) throws JsonIOException, JsonSyntaxException { // code copied from gson's JsonParser and Stream classes final boolean lenient = reader.isLenient(); reader.setLenient(true); boolean isEmpty = true; try {//from ww w . ja va 2 s . c o m reader.peek(); isEmpty = false; final CompositeNodeDataWithSchema compositeNodeDataWithSchema = new CompositeNodeDataWithSchema( parentNode); read(reader, compositeNodeDataWithSchema); compositeNodeDataWithSchema.write(writer); return this; // return read(reader); } catch (final EOFException e) { if (isEmpty) { return this; // return JsonNull.INSTANCE; } // The stream ended prematurely so it is likely a syntax error. throw new JsonSyntaxException(e); } catch (final MalformedJsonException e) { throw new JsonSyntaxException(e); } catch (final IOException e) { throw new JsonIOException(e); } catch (final NumberFormatException e) { throw new JsonSyntaxException(e); } catch (StackOverflowError | OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e); } finally { reader.setLenient(lenient); } }
From source file:org.opendaylight.controller.sal.rest.gson.JsonParser.java
License:Open Source License
public JsonElement parse(JsonReader reader) throws JsonIOException, JsonSyntaxException { // code copied from gson's JsonParser and Stream classes boolean lenient = reader.isLenient(); reader.setLenient(true); boolean isEmpty = true; try {/*from w w w.j a v a 2 s .com*/ reader.peek(); isEmpty = false; return read(reader); } catch (EOFException e) { if (isEmpty) { return JsonNull.INSTANCE; } // The stream ended prematurely so it is likely a syntax error. throw new JsonSyntaxException(e); } catch (MalformedJsonException e) { throw new JsonSyntaxException(e); } catch (IOException e) { throw new JsonIOException(e); } catch (NumberFormatException e) { throw new JsonSyntaxException(e); } catch (StackOverflowError | OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source: " + reader + " to Json", e); } finally { reader.setLenient(lenient); } }