diff --git a/src/main/java/com/wang/config/ExceptionAdvice.java b/src/main/java/com/wang/config/ExceptionAdvice.java index f44c23d..8dde47e 100644 --- a/src/main/java/com/wang/config/ExceptionAdvice.java +++ b/src/main/java/com/wang/config/ExceptionAdvice.java @@ -147,11 +147,11 @@ private HttpStatus getStatus(HttpServletRequest request) { * @param fieldErrors * @return */ - private Map getValidError(List fieldErrors){ + private Map getValidError(List fieldErrors) { Map result = new HashMap(16); List errorList = new ArrayList(); StringBuffer errorMsg = new StringBuffer("校验异常(ValidException):"); - for (FieldError error : fieldErrors){ + for (FieldError error : fieldErrors) { errorList.add(error.getField() + "-" + error.getDefaultMessage()); errorMsg.append(error.getField() + "-" + error.getDefaultMessage() + "."); } diff --git a/src/main/java/com/wang/config/redis/JedisConfig.java b/src/main/java/com/wang/config/redis/JedisConfig.java index 8aea0a3..1359f16 100644 --- a/src/main/java/com/wang/config/redis/JedisConfig.java +++ b/src/main/java/com/wang/config/redis/JedisConfig.java @@ -49,7 +49,7 @@ public class JedisConfig { private int minIdle; @Bean - public JedisPool redisPoolFactory(){ + public JedisPool redisPoolFactory() { try { JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); jedisPoolConfig.setMaxIdle(maxIdle); diff --git a/src/main/java/com/wang/config/shiro/UserRealm.java b/src/main/java/com/wang/config/shiro/UserRealm.java index 049ed61..fd3c784 100644 --- a/src/main/java/com/wang/config/shiro/UserRealm.java +++ b/src/main/java/com/wang/config/shiro/UserRealm.java @@ -97,11 +97,11 @@ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) t throw new AuthenticationException("该帐号不存在(The account does not exist.)"); } // 开始认证,要AccessToken认证通过,且Redis中存在RefreshToken,且两个Token时间戳一致 - if(JwtUtil.verify(token) && JedisUtil.exists(Constant.PREFIX_SHIRO_REFRESH_TOKEN + account)){ + if (JwtUtil.verify(token) && JedisUtil.exists(Constant.PREFIX_SHIRO_REFRESH_TOKEN + account)) { // 获取RefreshToken的时间戳 String currentTimeMillisRedis = JedisUtil.getObject(Constant.PREFIX_SHIRO_REFRESH_TOKEN + account).toString(); // 获取AccessToken时间戳,与RefreshToken的时间戳对比 - if(JwtUtil.getClaim(token, Constant.CURRENT_TIME_MILLIS).equals(currentTimeMillisRedis)){ + if (JwtUtil.getClaim(token, Constant.CURRENT_TIME_MILLIS).equals(currentTimeMillisRedis)) { return new SimpleAuthenticationInfo(token, token, "userRealm"); } } diff --git a/src/main/java/com/wang/config/shiro/cache/CustomCache.java b/src/main/java/com/wang/config/shiro/cache/CustomCache.java index d64f557..5cc3cf7 100644 --- a/src/main/java/com/wang/config/shiro/cache/CustomCache.java +++ b/src/main/java/com/wang/config/shiro/cache/CustomCache.java @@ -24,7 +24,7 @@ public class CustomCache implements Cache { * @author Wang926454 * @date 2018/9/4 18:33 */ - private String getKey(Object key){ + private String getKey(Object key) { return Constant.PREFIX_SHIRO_CACHE + JwtUtil.getClaim(key.toString(), Constant.ACCOUNT); } diff --git a/src/main/java/com/wang/config/shiro/jwt/JwtFilter.java b/src/main/java/com/wang/config/shiro/jwt/JwtFilter.java index 2709a8a..e7a356b 100644 --- a/src/main/java/com/wang/config/shiro/jwt/JwtFilter.java +++ b/src/main/java/com/wang/config/shiro/jwt/JwtFilter.java @@ -54,19 +54,19 @@ protected boolean isAccessAllowed(ServletRequest request, ServletResponse respon String msg = e.getMessage(); // 获取应用异常(该Cause是导致抛出此throwable(异常)的throwable(异常)) Throwable throwable = e.getCause(); - if(throwable != null && throwable instanceof SignatureVerificationException ){ + if (throwable != null && throwable instanceof SignatureVerificationException) { // 该异常为JWT的AccessToken认证失败(Token或者密钥不正确) msg = "Token或者密钥不正确(" + throwable.getMessage() + ")"; - } else if(throwable != null && throwable instanceof TokenExpiredException){ + } else if (throwable != null && throwable instanceof TokenExpiredException) { // 该异常为JWT的AccessToken已过期,判断RefreshToken未过期就进行AccessToken刷新 - if(this.refreshToken(request, response)){ + if (this.refreshToken(request, response)) { return true; - }else{ + } else { msg = "Token已过期(" + throwable.getMessage() + ")"; } - } else{ + } else { // 应用异常不为空 - if(throwable != null) { + if (throwable != null) { // 获取应用异常msg msg = throwable.getMessage(); } @@ -128,11 +128,11 @@ private boolean refreshToken(ServletRequest request, ServletResponse response) { // 获取当前Token的帐号信息 String account = JwtUtil.getClaim(token, Constant.ACCOUNT); // 判断Redis中RefreshToken是否存在 - if(JedisUtil.exists(Constant.PREFIX_SHIRO_REFRESH_TOKEN + account)){ + if (JedisUtil.exists(Constant.PREFIX_SHIRO_REFRESH_TOKEN + account)) { // Redis中RefreshToken还存在,获取RefreshToken的时间戳 String currentTimeMillisRedis = JedisUtil.getObject(Constant.PREFIX_SHIRO_REFRESH_TOKEN + account).toString(); // 获取当前AccessToken中的时间戳,与RefreshToken的时间戳对比,如果当前时间戳一致,进行AccessToken刷新 - if(JwtUtil.getClaim(token, Constant.CURRENT_TIME_MILLIS).equals(currentTimeMillisRedis)){ + if (JwtUtil.getClaim(token, Constant.CURRENT_TIME_MILLIS).equals(currentTimeMillisRedis)) { // 获取当前最新时间戳 String currentTimeMillis = String.valueOf(System.currentTimeMillis()); // 读取配置文件,获取refreshTokenExpireTime属性 diff --git a/src/main/java/com/wang/controller/UserController.java b/src/main/java/com/wang/controller/UserController.java index 1aec6e9..ffd6497 100644 --- a/src/main/java/com/wang/controller/UserController.java +++ b/src/main/java/com/wang/controller/UserController.java @@ -62,15 +62,15 @@ public UserController(IUserService userService) { */ @GetMapping @RequiresPermissions(logical = Logical.AND, value = {"user:view"}) - public ResponseBean user(@Validated BaseDto baseDto){ - if(baseDto.getPage() == null || baseDto.getRows() == null){ + public ResponseBean user(@Validated BaseDto baseDto) { + if (baseDto.getPage() == null || baseDto.getRows() == null) { baseDto.setPage(1); baseDto.setRows(10); } PageHelper.startPage(baseDto.getPage(), baseDto.getRows()); List userDtos = userService.selectAll(); PageInfo selectPage = new PageInfo(userDtos); - if(userDtos == null || userDtos.size() <= 0){ + if (userDtos == null || userDtos.size() <= 0) { throw new CustomException("查询失败(Query Failure)"); } Map result = new HashMap(16); @@ -88,12 +88,12 @@ public ResponseBean user(@Validated BaseDto baseDto){ */ @GetMapping("/online") @RequiresPermissions(logical = Logical.AND, value = {"user:view"}) - public ResponseBean online(){ + public ResponseBean online() { List userDtos = new ArrayList(); // 查询所有Redis键 Set keys = JedisUtil.keysS(Constant.PREFIX_SHIRO_REFRESH_TOKEN + "*"); for (String key : keys) { - if(JedisUtil.exists(key)){ + if (JedisUtil.exists(key)) { // 根据:分割key,获取最后一个字符(帐号) String[] strArray = key.split(":"); UserDto userDto = new UserDto(); @@ -104,7 +104,7 @@ public ResponseBean online(){ userDtos.add(userDto); } } - if(userDtos == null || userDtos.size() <= 0){ + if (userDtos == null || userDtos.size() <= 0) { throw new CustomException("查询失败(Query Failure)"); } return new ResponseBean(HttpStatus.OK.value(), "查询成功(Query was successful)", userDtos); @@ -123,7 +123,7 @@ public ResponseBean login(@Validated(UserLoginValidGroup.class) @RequestBody Use UserDto userDtoTemp = new UserDto(); userDtoTemp.setAccount(userDto.getAccount()); userDtoTemp = userService.selectOne(userDtoTemp); - if(userDtoTemp == null){ + if (userDtoTemp == null) { throw new CustomUnauthorizedException("该帐号不存在(The account does not exist.)"); } // 密码进行AES解密 @@ -131,7 +131,7 @@ public ResponseBean login(@Validated(UserLoginValidGroup.class) @RequestBody Use // 因为密码加密是以帐号+密码的形式进行加密的,所以解密后的对比是帐号+密码 if (key.equals(userDto.getAccount() + userDto.getPassword())) { // 清除可能存在的Shiro权限信息缓存 - if(JedisUtil.exists(Constant.PREFIX_SHIRO_CACHE + userDto.getAccount())){ + if (JedisUtil.exists(Constant.PREFIX_SHIRO_CACHE + userDto.getAccount())) { JedisUtil.delKey(Constant.PREFIX_SHIRO_CACHE + userDto.getAccount()); } // 设置RefreshToken,时间戳为当前时间戳,直接设置即可(不用先删后设,会覆盖已有的RefreshToken) @@ -187,9 +187,9 @@ public ResponseBean requireAuth() { */ @GetMapping("/{id}") @RequiresPermissions(logical = Logical.AND, value = {"user:view"}) - public ResponseBean findById(@PathVariable("id") Integer id){ + public ResponseBean findById(@PathVariable("id") Integer id) { UserDto userDto = userService.selectByPrimaryKey(id); - if(userDto == null){ + if (userDto == null) { throw new CustomException("查询失败(Query Failure)"); } return new ResponseBean(HttpStatus.OK.value(), "查询成功(Query was successful)", userDto); @@ -209,18 +209,18 @@ public ResponseBean add(@Validated(UserEditValidGroup.class) @RequestBody UserDt UserDto userDtoTemp = new UserDto(); userDtoTemp.setAccount(userDto.getAccount()); userDtoTemp = userService.selectOne(userDtoTemp); - if(userDtoTemp != null && StringUtil.isNotBlank(userDtoTemp.getPassword())){ + if (userDtoTemp != null && StringUtil.isNotBlank(userDtoTemp.getPassword())) { throw new CustomUnauthorizedException("该帐号已存在(Account exist.)"); } userDto.setRegTime(new Date()); // 密码以帐号+密码的形式进行AES加密 - if(userDto.getPassword().length() > Constant.PASSWORD_MAX_LEN){ + if (userDto.getPassword().length() > Constant.PASSWORD_MAX_LEN) { throw new CustomException("密码最多8位(Password up to 8 bits.)"); } String key = AesCipherUtil.enCrypto(userDto.getAccount() + userDto.getPassword()); userDto.setPassword(key); int count = userService.insert(userDto); - if(count <= 0){ + if (count <= 0) { throw new CustomException("新增失败(Insert Failure)"); } return new ResponseBean(HttpStatus.OK.value(), "新增成功(Insert Success)", userDto); @@ -240,22 +240,22 @@ public ResponseBean update(@Validated(UserEditValidGroup.class) @RequestBody Use UserDto userDtoTemp = new UserDto(); userDtoTemp.setAccount(userDto.getAccount()); userDtoTemp = userService.selectOne(userDtoTemp); - if(userDtoTemp == null){ + if (userDtoTemp == null) { throw new CustomUnauthorizedException("该帐号不存在(Account not exist.)"); - }else{ + } else { userDto.setId(userDtoTemp.getId()); } // FIXME: 如果不一样就说明用户修改了密码,重新加密密码(这个处理不太好,但是没有想到好的处理方式) - if(!userDtoTemp.getPassword().equals(userDto.getPassword())){ + if (!userDtoTemp.getPassword().equals(userDto.getPassword())) { // 密码以帐号+密码的形式进行AES加密 - if(userDto.getPassword().length() > Constant.PASSWORD_MAX_LEN){ + if (userDto.getPassword().length() > Constant.PASSWORD_MAX_LEN) { throw new CustomException("密码最多8位(Password up to 8 bits.)"); } String key = AesCipherUtil.enCrypto(userDto.getAccount() + userDto.getPassword()); userDto.setPassword(key); } int count = userService.updateByPrimaryKeySelective(userDto); - if(count <= 0){ + if (count <= 0) { throw new CustomException("更新失败(Update Failure)"); } return new ResponseBean(HttpStatus.OK.value(), "更新成功(Update Success)", userDto); @@ -270,9 +270,9 @@ public ResponseBean update(@Validated(UserEditValidGroup.class) @RequestBody Use */ @DeleteMapping("/{id}") @RequiresPermissions(logical = Logical.AND, value = {"user:edit"}) - public ResponseBean delete(@PathVariable("id") Integer id){ + public ResponseBean delete(@PathVariable("id") Integer id) { int count = userService.deleteByPrimaryKey(id); - if(count <= 0){ + if (count <= 0) { throw new CustomException("删除失败,ID不存在(Deletion Failed. ID does not exist.)"); } return new ResponseBean(HttpStatus.OK.value(), "删除成功(Delete Success)", null); @@ -287,10 +287,10 @@ public ResponseBean delete(@PathVariable("id") Integer id){ */ @DeleteMapping("/online/{id}") @RequiresPermissions(logical = Logical.AND, value = {"user:edit"}) - public ResponseBean deleteOnline(@PathVariable("id") Integer id){ + public ResponseBean deleteOnline(@PathVariable("id") Integer id) { UserDto userDto = userService.selectByPrimaryKey(id); - if(JedisUtil.exists(Constant.PREFIX_SHIRO_REFRESH_TOKEN + userDto.getAccount())){ - if(JedisUtil.delKey(Constant.PREFIX_SHIRO_REFRESH_TOKEN + userDto.getAccount()) > 0){ + if (JedisUtil.exists(Constant.PREFIX_SHIRO_REFRESH_TOKEN + userDto.getAccount())) { + if (JedisUtil.delKey(Constant.PREFIX_SHIRO_REFRESH_TOKEN + userDto.getAccount()) > 0) { return new ResponseBean(HttpStatus.OK.value(), "剔除成功(Delete Success)", null); } } diff --git a/src/main/java/com/wang/service/IUserService.java b/src/main/java/com/wang/service/IUserService.java index e81992b..26ad133 100644 --- a/src/main/java/com/wang/service/IUserService.java +++ b/src/main/java/com/wang/service/IUserService.java @@ -7,5 +7,5 @@ * @author Wang926454 * @date 2018/8/9 15:44 */ -public interface IUserService extends IBaseService{ +public interface IUserService extends IBaseService { } diff --git a/src/main/java/com/wang/util/AesCipherUtil.java b/src/main/java/com/wang/util/AesCipherUtil.java index 33fa624..bd747a6 100644 --- a/src/main/java/com/wang/util/AesCipherUtil.java +++ b/src/main/java/com/wang/util/AesCipherUtil.java @@ -47,7 +47,7 @@ public void setEncryptAESKey(String encryptAESKey) { * @date 2018/8/31 16:56 */ public static String enCrypto(String str) { - try{ + try { Security.addProvider(new com.sun.crypto.provider.SunJCE()); // 实例化支持AES算法的密钥生成器(算法名称命名需按规定,否则抛出异常) // KeyGenerator 提供对称密钥生成器的功能,支持各种算法 @@ -67,22 +67,22 @@ public static String enCrypto(String str) { byte[] cipherByte = c.doFinal(src); // 先将二进制转换成16进制,再返回Bsae64加密后的String return Base64ConvertUtil.encode(HexConvertUtil.parseByte2HexStr(cipherByte)); - } catch (NoSuchAlgorithmException e){ + } catch (NoSuchAlgorithmException e) { LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); - } catch (UnsupportedEncodingException e){ + } catch (UnsupportedEncodingException e) { LOGGER.error("Bsae64加密异常:" + e.getMessage()); throw new CustomUnauthorizedException("Bsae64加密异常:" + e.getMessage()); - } catch (NoSuchPaddingException e){ + } catch (NoSuchPaddingException e) { LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); - } catch (InvalidKeyException e){ + } catch (InvalidKeyException e) { LOGGER.error("初始化Cipher对象异常:" + e.getMessage()); throw new CustomUnauthorizedException("初始化Cipher对象异常:" + e.getMessage()); - } catch (IllegalBlockSizeException e){ + } catch (IllegalBlockSizeException e) { LOGGER.error("加密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("加密异常,密钥有误:" + e.getMessage()); - } catch (BadPaddingException e){ + } catch (BadPaddingException e) { LOGGER.error("加密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("加密异常,密钥有误:" + e.getMessage()); } @@ -96,7 +96,7 @@ public static String enCrypto(String str) { * @date 2018/8/31 16:56 */ public static String deCrypto(String str) { - try{ + try { Security.addProvider(new com.sun.crypto.provider.SunJCE()); // 实例化支持AES算法的密钥生成器(算法名称命名需按规定,否则抛出异常) // KeyGenerator 提供对称密钥生成器的功能,支持各种算法 @@ -114,22 +114,22 @@ public static String deCrypto(String str) { // 该字节数组负责保存加密的结果,先对str进行Bsae64解密,将16进制转换为二进制 byte[] cipherByte = c.doFinal(HexConvertUtil.parseHexStr2Byte(Base64ConvertUtil.decode(str))); return new String(cipherByte); - } catch (NoSuchAlgorithmException e){ + } catch (NoSuchAlgorithmException e) { LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); - } catch (UnsupportedEncodingException e){ + } catch (UnsupportedEncodingException e) { LOGGER.error("Bsae64加密异常:" + e.getMessage()); throw new CustomUnauthorizedException("Bsae64加密异常:" + e.getMessage()); - } catch (NoSuchPaddingException e){ + } catch (NoSuchPaddingException e) { LOGGER.error("getInstance()方法异常:" + e.getMessage()); throw new CustomUnauthorizedException("getInstance()方法异常:" + e.getMessage()); - } catch (InvalidKeyException e){ + } catch (InvalidKeyException e) { LOGGER.error("初始化Cipher对象异常:" + e.getMessage()); throw new CustomUnauthorizedException("初始化Cipher对象异常:" + e.getMessage()); - } catch (IllegalBlockSizeException e){ + } catch (IllegalBlockSizeException e) { LOGGER.error("解密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("解密异常,密钥有误:" + e.getMessage()); - } catch (BadPaddingException e){ + } catch (BadPaddingException e) { LOGGER.error("解密异常,密钥有误:" + e.getMessage()); throw new CustomUnauthorizedException("解密异常,密钥有误:" + e.getMessage()); } diff --git a/src/main/java/com/wang/util/JedisUtil.java b/src/main/java/com/wang/util/JedisUtil.java index ecc84e2..1a8bec1 100644 --- a/src/main/java/com/wang/util/JedisUtil.java +++ b/src/main/java/com/wang/util/JedisUtil.java @@ -62,7 +62,7 @@ public static synchronized Jedis getJedis() { public static void closePool() { try { jedisPool.close(); - }catch (Exception e){ + } catch (Exception e) { throw new CustomException("释放Jedis资源异常:" + e.getMessage()); } } @@ -79,13 +79,13 @@ public static Object getObject(String key) { try { jedis = jedisPool.getResource(); byte[] bytes = jedis.get(key.getBytes()); - if(StringUtil.isNotNull(bytes)) { + if (StringUtil.isNotNull(bytes)) { return SerializableUtil.unserializable(bytes); } } catch (Exception e) { throw new CustomException("获取Redis键值getObject方法异常:key=" + key + " cause=" + e.getMessage()); } finally { - if(jedis != null) { + if (jedis != null) { jedis.close(); } } @@ -108,7 +108,7 @@ public static String setObject(String key, Object value) { } catch (Exception e) { throw new CustomException("设置Redis键值setObject方法异常:key=" + key + " value=" + value + " cause=" + e.getMessage()); } finally { - if(jedis != null) { + if (jedis != null) { jedis.close(); } } @@ -129,14 +129,14 @@ public static String setObject(String key, Object value, int expiretime) { try { jedis = jedisPool.getResource(); result = jedis.set(key.getBytes(), SerializableUtil.serializable(value)); - if(Constant.OK.equals(result)) { + if (Constant.OK.equals(result)) { jedis.expire(key.getBytes(), expiretime); } return result; } catch (Exception e) { throw new CustomException("设置Redis键值setObject方法异常:key=" + key + " value=" + value + " cause=" + e.getMessage()); } finally { - if(jedis != null) { + if (jedis != null) { jedis.close(); } } @@ -157,7 +157,7 @@ public static String getJson(String key) { } catch (Exception e) { throw new CustomException("获取Redis键值getJson方法异常:key=" + key + " cause=" + e.getMessage()); } finally { - if(jedis != null) { + if (jedis != null) { jedis.close(); } } @@ -179,7 +179,7 @@ public static String setJson(String key, String value) { } catch (Exception e) { throw new CustomException("设置Redis键值setJson方法异常:key=" + key + " value=" + value + " cause=" + e.getMessage()); } finally { - if(jedis != null) { + if (jedis != null) { jedis.close(); } } @@ -200,14 +200,14 @@ public static String setJson(String key, String value, int expiretime) { try { jedis = jedisPool.getResource(); result = jedis.set(key, value); - if(Constant.OK.equals(result)) { + if (Constant.OK.equals(result)) { jedis.expire(key, expiretime); } return result; } catch (Exception e) { throw new CustomException("设置Redis键值setJson方法异常:key=" + key + " value=" + value + " cause=" + e.getMessage()); } finally { - if(jedis != null) { + if (jedis != null) { jedis.close(); } } @@ -225,10 +225,10 @@ public static Long delKey(String key) { try { jedis = jedisPool.getResource(); return jedis.del(key.getBytes()); - }catch(Exception e) { + } catch (Exception e) { throw new CustomException("删除Redis的键delKey方法异常:key=" + key + " cause=" + e.getMessage()); - }finally{ - if(jedis != null) { + } finally { + if (jedis != null) { jedis.close(); } } @@ -246,10 +246,10 @@ public static Boolean exists(String key) { try { jedis = jedisPool.getResource(); return jedis.exists(key.getBytes()); - }catch(Exception e) { + } catch (Exception e) { throw new CustomException("查询Redis的键是否存在exists方法异常:key=" + key + " cause=" + e.getMessage()); - }finally{ - if(jedis != null) { + } finally { + if (jedis != null) { jedis.close(); } } @@ -267,10 +267,10 @@ public static Set keysS(String key) { try { jedis = jedisPool.getResource(); return jedis.keys(key); - }catch(Exception e) { + } catch (Exception e) { throw new CustomException("模糊查询Redis的键集合keysS方法异常:key=" + key + " cause=" + e.getMessage()); - }finally{ - if(jedis != null) { + } finally { + if (jedis != null) { jedis.close(); } } @@ -288,10 +288,10 @@ public static Set keysB(String key) { try { jedis = jedisPool.getResource(); return jedis.keys(key.getBytes()); - }catch(Exception e) { + } catch (Exception e) { throw new CustomException("模糊查询Redis的键集合keysB方法异常:key=" + key + " cause=" + e.getMessage()); - }finally{ - if(jedis != null) { + } finally { + if (jedis != null) { jedis.close(); } } @@ -314,7 +314,7 @@ public static Long ttl(String key) { } catch (Exception e) { throw new CustomException("获取Redis键过期剩余时间ttl方法异常:key=" + key + " cause=" + e.getMessage()); } finally { - if(jedis != null) { + if (jedis != null) { jedis.close(); } } diff --git a/src/main/java/com/wang/util/common/HexConvertUtil.java b/src/main/java/com/wang/util/common/HexConvertUtil.java index 087dce9..e6e1518 100644 --- a/src/main/java/com/wang/util/common/HexConvertUtil.java +++ b/src/main/java/com/wang/util/common/HexConvertUtil.java @@ -44,11 +44,11 @@ public static String parseByte2HexStr(byte[] buff) { * @date 2018/8/31 17:21 */ public static byte[] parseHexStr2Byte(String hexStr) { - if (hexStr.length() < INTEGER_1){ + if (hexStr.length() < INTEGER_1) { return null; } byte[] result = new byte[hexStr.length() / INTEGER_2]; - for (int i = 0, len = hexStr.length() / INTEGER_2;i < len; i++) { + for (int i = 0, len = hexStr.length() / INTEGER_2; i < len; i++) { int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16); int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16); result[i] = (byte) (high * 16 + low); diff --git a/src/main/java/com/wang/util/common/PropertiesUtil.java b/src/main/java/com/wang/util/common/PropertiesUtil.java index 2668de9..6caf665 100644 --- a/src/main/java/com/wang/util/common/PropertiesUtil.java +++ b/src/main/java/com/wang/util/common/PropertiesUtil.java @@ -34,21 +34,21 @@ public class PropertiesUtil { * @author Wang926454 * @date 2018/8/31 17:29 */ - public static void readProperties(String fileName){ + public static void readProperties(String fileName) { InputStream in = null; try { in = PropertiesUtil.class.getResourceAsStream("/" + fileName); BufferedReader bf = new BufferedReader(new InputStreamReader(in)); PROP.load(bf); - } catch (IOException e){ + } catch (IOException e) { LOGGER.error("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage()); throw new CustomException("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage()); } finally { - try{ - if(in != null){ + try { + if (in != null) { in.close(); } - }catch (IOException e){ + } catch (IOException e) { LOGGER.error("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage()); throw new CustomException("PropertiesUtil工具类读取配置文件出现IOException异常:" + e.getMessage()); } diff --git a/src/main/java/com/wang/util/common/SerializableUtil.java b/src/main/java/com/wang/util/common/SerializableUtil.java index aeb2180..262caed 100644 --- a/src/main/java/com/wang/util/common/SerializableUtil.java +++ b/src/main/java/com/wang/util/common/SerializableUtil.java @@ -39,10 +39,10 @@ public static byte[] serializable(Object object) { throw new CustomException("SerializableUtil工具类序列化出现IOException异常:" + e.getMessage()); } finally { try { - if(oos != null) { + if (oos != null) { oos.close(); } - if(baos != null) { + if (baos != null) { baos.close(); } } catch (IOException e) { @@ -74,10 +74,10 @@ public static Object unserializable(byte[] bytes) { throw new CustomException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage()); } finally { try { - if(ois != null) { + if (ois != null) { ois.close(); } - if(bais != null) { + if (bais != null) { bais.close(); } } catch (IOException e) { diff --git a/src/main/java/com/wang/util/common/StringUtil.java b/src/main/java/com/wang/util/common/StringUtil.java index 32e2936..565a44d 100644 --- a/src/main/java/com/wang/util/common/StringUtil.java +++ b/src/main/java/com/wang/util/common/StringUtil.java @@ -40,7 +40,7 @@ public static boolean isNotBlank(String str) { * @author Wang926454 * @date 2018/9/4 15:39 */ - public static boolean isNull(byte[] bytes){ + public static boolean isNull(byte[] bytes) { // 根据byte数组长度为0判断 return bytes.length == 0 || bytes == null; } @@ -67,7 +67,7 @@ public static String camelToUnderline(String param) { if (isNotBlank(param)) { int len = param.length(); StringBuilder sb = new StringBuilder(len); - for (int i = 0; i < len; ++i) { + for (int i = 0; i < len; i++) { char c = param.charAt(i); if (Character.isUpperCase(c)) { sb.append(UNDERLINE); @@ -93,7 +93,7 @@ public static String underlineToCamel(String param) { if (isNotBlank(param)) { int len = param.length(); StringBuilder sb = new StringBuilder(len); - for (int i = 0; i < len; ++i) { + for (int i = 0; i < len; i++) { char c = param.charAt(i); if (c == 95) { ++i;