| | |
| | | package com.ard.utils; |
| | | |
| | | import org.springframework.beans.BeansException; |
| | | import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ApplicationContextAware; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.core.io.Resource; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.nio.ByteBuffer; |
| | | import java.util.Properties; |
| | | |
| | | /** |
| | | * @Description: |
| | | * @ClassName: SpringTool |
| | |
| | | return getApplicationContext().getBean(name); |
| | | } |
| | | |
| | | /** |
| | | * Byte字节转Hex |
| | | * @param b 字节 |
| | | * @return Hex |
| | | */ |
| | | public static String byteToHex(byte b) |
| | | { |
| | | String hexString = Integer.toHexString(b & 0xFF); |
| | | //由于十六进制是由0~9、A~F来表示1~16,所以如果Byte转换成Hex后如果是<16,就会是一个字符(比如A=10),通常是使用两个字符来表示16进制位的, |
| | | //假如一个字符的话,遇到字符串11,这到底是1个字节,还是1和1两个字节,容易混淆,如果是补0,那么1和1补充后就是0101,11就表示纯粹的11 |
| | | if (hexString.length() < 2) |
| | | { |
| | | hexString = new StringBuilder(String.valueOf(0)).append(hexString).toString(); |
| | | /*yml配置信息获取*/ |
| | | public static String getYmlInfo(String key) { |
| | | Resource resource = new ClassPathResource("application.yml"); |
| | | Properties properties = null; |
| | | try { |
| | | YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean(); |
| | | yamlFactory.setResources(resource); |
| | | properties = yamlFactory.getObject(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | return hexString.toUpperCase(); |
| | | return properties.get(key).toString(); |
| | | } |
| | | } |