Commit cff26cf1 authored by xuwei's avatar xuwei

add code annotation

parent e3680b80
......@@ -3,6 +3,15 @@ package com.gmei.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
/**
* ClassName: com.gmei.utils.DateUtils
* Function: TODO ADD FUNCTION.
* Reason: 日期工具类
* Date: 2020-03-03 00:00:00
*
* @author sjxuwei
* @since JDK 1.8
*/
public class DateUtils {
public static long changeDateToLong(String time, SimpleDateFormat simpleDateFormat) throws ParseException {
return simpleDateFormat.parse(time).getTime();
......
......@@ -9,6 +9,15 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Properties;
/**
* ClassName: com.gmei.utils.GmKafkaConsumer
* Function: TODO ADD FUNCTION.
* Reason: 定义kafka数据源,必须定制schama
* Date: 2020-03-03 00:00:00
*
* @author sjxuwei
* @since JDK 1.8
*/
public class GmKafkaConsumer {
private String topic;
private Properties prop;
......
......@@ -5,6 +5,15 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* ClassName: com.gmei.utils.JDBCUtils
* Function: TODO ADD FUNCTION.
* Reason: jdbc工具类
* Date: 2020-03-03 00:00:00
*
* @author sjxuwei
* @since JDK 1.8
*/
public class JDBCUtils {
synchronized public static void close(Connection connection, Statement statement, ResultSet resultSet) throws SQLException {
if(connection != null){
......
......@@ -8,89 +8,24 @@ import java.security.NoSuchAlgorithmException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* ClassName: com.gmei.utils.StringUtils
* Function: TODO ADD FUNCTION.
* Reason: String工具类
* Date: 2020-03-03 00:00:00
*
* @author sjxuwei
* @since JDK 1.8
*/
public class StringUtils {
/**
* 使用gzip进行压缩
*/
public static String gzip(String primStr) {
if (primStr == null || primStr.length() == 0) {
return primStr;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip = null;
try {
gzip = new GZIPOutputStream(out);
gzip.write(primStr.getBytes());
} catch (IOException e) {
e.printStackTrace();
} finally {
if (gzip != null) {
try {
gzip.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return new sun.misc.BASE64Encoder().encode(out.toByteArray());
}
/**
* <p>Description:使用gzip进行解压缩</p>
* Function: TODO ADD FUNCTION.
* Reason: 获得数据md5
* Date: 2020-03-03 00:00:00
*
* @param compressedStr
* @return
* @author sjxuwei
* @since JDK 1.8
*/
public static String gunzip(String compressedStr) {
if (compressedStr == null) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = null;
GZIPInputStream ginzip = null;
byte[] compressed = null;
String decompressed = null;
try {
compressed = new sun.misc.BASE64Decoder().decodeBuffer(compressedStr);
in = new ByteArrayInputStream(compressed);
ginzip = new GZIPInputStream(in);
byte[] buffer = new byte[1024];
int offset = -1;
while ((offset = ginzip.read(buffer)) != -1) {
out.write(buffer, 0, offset);
}
decompressed = out.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ginzip != null) {
try {
ginzip.close();
} catch (IOException e) {
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
return decompressed;
}
public static String getStringMd5(byte[] bytes) throws NoSuchAlgorithmException {
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] digest = md5.digest(bytes);
......@@ -105,11 +40,26 @@ public class StringUtils {
return hexValue.toString();
}
/**
* Function: TODO ADD FUNCTION.
* Reason: 判断对象是否为NULL
* Date: 2020-03-03 00:00:00
*
* @author sjxuwei
* @since JDK 1.8
*/
public static boolean isObjectNull(Object object){
return (object == null);
}
/**
* Function: TODO ADD FUNCTION.
* Reason: 将为NULL的对象转换为长度为0的字符串
* Date: 2020-03-03 00:00:00
*
* @author sjxuwei
* @since JDK 1.8
*/
public static String changeNullTolength0(Object object){
if(object == null){
return "";
......@@ -118,6 +68,14 @@ public class StringUtils {
}
}
/**
* Function: TODO ADD FUNCTION.
* Reason: 将为NULL的对象转换成double类型
* Date: 2020-03-03 00:00:00
*
* @author sjxuwei
* @since JDK 1.8
*/
public static Double isNullToDouble(Object object){
if(object == null){
return 0.0;
......@@ -130,6 +88,14 @@ public class StringUtils {
}
}
/**
* Function: TODO ADD FUNCTION.
* Reason: 从参数中获取第一个不为NULL并且长度大于0的字符串,否则返回长度为0的字符串
* Date: 2020-03-03 00:00:00
*
* @author sjxuwei
* @since JDK 1.8
*/
public static String getNotNull(String... str){
for(String s : str){
if(s != null && s.length() > 0){
......@@ -139,7 +105,14 @@ public class StringUtils {
return "";
}
/**
* Function: TODO ADD FUNCTION.
* Reason: 如果参数1的长度为0则取第二个参数的值
* Date: 2020-03-03 00:00:00
*
* @author sjxuwei
* @since JDK 1.8
*/
public static String changeLength0toOther(String str1,String str2){
if(str1.length() == 0){
return str2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment