public <T extends PackObject> T unPackMessage(String interfaceCode, String respValue, Class<T> clazz, String sysType) throws IOException { log.info(">> unPackMessage start, interfaceCode is {}, respValue is {}", interfaceCode, respValue); Map<String, Object> result = null; // get pack_convert.prop file content PackConvertMessage packConvertMessage = getPackConvertFileContent(); String func = packConvertMessage.getInterfaceMapping().get(interfaceCode); if (StringUtils.isBlank(func)){ log.error("<< unPackMessage error, No response message with current interface configured"); return null; } String respSerialNumber = packConvertMessage.getRespFuncMapping().get(func); String currPackType = PackConvertConstant.SystermType.CLIENT.equals(sysType) ? client_pack_type : pack_type; switch (currPackType){ case PackConvertConstant.PackType.NON_FIXED_LENGTH: result = unpackNoFixedMessage(respValue, connect_char, respSerialNumber, PACK_CONVERT_FILE_MAPPING_SEPARATOR, sysType); break; case PackConvertConstant.PackType.FIXED_LENGTH: result = unpackFixedMessage(respValue, respSerialNumber, PACK_CONVERT_FILE_MAPPING_SEPARATOR); break; case PackConvertConstant.PackType.XML: result = unpackXmlMessage(respValue, respSerialNumber, PACK_CONVERT_FILE_MAPPING_SEPARATOR); break; case PackConvertConstant.PackType.JSON: result = unpackJsonMessage(respValue, respSerialNumber); break; } log.info("<< unPackMessage success, return value is {}", JSON.toJSONString(result)); T t = JSON.toJavaObject(JSON.parseObject(JSON.toJSONString(result)), clazz); return t; }
public <E extends BaseLiquidation, T extends BaseLiquidation> List<E> convertFileToObj(String localFilePath, Class<E> clazz, Class<T> tclazz) throws IOException, NoSuchMethodException, IllegalAccessException, InstantiationException { logger.info(">> convertFileToObj, localFilePath is {}, clazz is {}", localFilePath, clazz.getName()); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(localFilePath),"utf-8")); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null){ sb.append(line); sb.append(System.getProperty("line.separator")); } List<E> result = messageToObj(sb.toString(), clazz); logger.info("<< convertFileToObj end"); return result; }
public <E extends BaseLiquidation> List<E> convertFileToObj(String localFilePath, Class<E> clazz) throws IOException, NoSuchMethodException, IllegalAccessException, InstantiationException { logger.info(">> convertFileToObj, localFilePath is {}, clazz is {}", localFilePath, clazz.getName()); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(localFilePath),"utf-8")); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null){ sb.append(line); sb.append(System.getProperty("line.separator")); } List<E> result = messageToObj(sb.toString(), clazz); logger.info("<< convertFileToObj end"); return result; }