Commit ba0afae6 authored by yanzg's avatar yanzg

消除成功接收处理

parent 1d1ae937
......@@ -525,7 +525,7 @@ public class ByteHelper {
*/
public static String logBytes(byte[] bytes) {
int length = bytes.length;
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder(length);
for (byte b : bytes) {
sb.append(b);
sb.append(" ");
......
......@@ -60,7 +60,7 @@ public class EnumHelper {
String vName = vMet.getName();
if ("forValue".equals(vName)
&& vMet.getParameterTypes().length == 1) {
Class vTempType = vMet.getParameterTypes()[0];
// Class vTempType = vMet.getParameterTypes()[0];
Object obj = vMet.invoke(null, i);
result = (T) obj;
CacheMethod.put(vType, vMet);
......
......@@ -10,6 +10,7 @@ import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
/**
* HTTP请求工具类
......@@ -28,7 +29,7 @@ public class HttpHelper {
try {
// 打开URL连接
java.net.HttpURLConnection httpConn = getConn(url);
return post(httpConn, url, jsonString);
return post(httpConn, jsonString);
} catch (Exception ex) {
throw new CodeException(ex);
}
......@@ -46,7 +47,7 @@ public class HttpHelper {
// 打开URL连接
java.net.HttpURLConnection httpConn = getConn(url);
httpConn.setRequestProperty("Content-Type", "application/json");
return post(httpConn, url, jsonString);
return post(httpConn, jsonString);
} catch (Exception ex) {
throw new CodeException(ex);
}
......@@ -79,18 +80,18 @@ public class HttpHelper {
/**
* 发送POST请求,当请求失败时,抛出异常或返回空字符串
*
* @param url 目的地址
* @param httpConn 链接信息
* @param jsonString 请求参数,json字符串。
* @return 远程响应结果
*/
public static String post(HttpURLConnection httpConn, String url, String jsonString) throws IOException {
public static String post(HttpURLConnection httpConn, String jsonString) throws IOException {
// 返回的结果
String result = "";
// 读取响应输入流
BufferedReader in = null;
PrintWriter out = null;
// 处理请求参数
StringBuffer sb = new StringBuffer();
// StringBuffer sb = new StringBuffer();
String params = "";
try {
params = jsonString;
......
......@@ -11,11 +11,11 @@ import java.util.Date;
* @author Light
*/
public class LogDate {
public static int MinMillSecond = 1;
public static final int MIN_MILL_SECOND = 1;
private StringBuilder log = new StringBuilder();
private Date start = new Date();
private Date end = new Date();
private long start = System.currentTimeMillis();
private long end = System.currentTimeMillis();
private double lastSecond = 0;
private double totalSecond = 0;
......@@ -42,7 +42,7 @@ public class LogDate {
* 开始记录
*/
public void begin() {
this.start = new Date();
this.start = System.currentTimeMillis();
}
/**
......@@ -59,8 +59,8 @@ public class LogDate {
* 提交日志,用于跟踪时间
*/
public void commit() {
this.end = new Date();
double total = this.end.getTime() - this.start.getTime();
this.end = System.currentTimeMillis();
double total = this.end - this.start;
this.lastSecond = total - this.totalSecond;
this.totalSecond = total;
}
......@@ -74,7 +74,7 @@ public class LogDate {
public void commit(String tag, Object... args) {
this.commit();
if (!StringHelper.isEmpty(tag)) {
String log = String.format("\r\n%s: %f ms 总共: %f ms ", String.format(tag, args), this.lastSecond, this.totalSecond);
String log = String.format("%s: %f ms 总共: %f ms ", String.format(tag, args), this.lastSecond, this.totalSecond);
this.log.append(log);
}
}
......@@ -83,8 +83,8 @@ public class LogDate {
* 将当前日志对象复位
*/
public void clear() {
this.start = new Date();
this.end = new Date();
this.start = System.currentTimeMillis();
this.end = System.currentTimeMillis();
this.lastSecond = 0;
this.totalSecond = 0;
this.log = new StringBuilder();
......@@ -95,7 +95,7 @@ public class LogDate {
*/
public void write() {
// 执行时间为0的不显示日志
if (this.totalSecond >= MinMillSecond) {
if (this.totalSecond >= MIN_MILL_SECOND) {
String vLog = this.log.toString();
if (!StringHelper.isEmpty(vLog)) {
Log.info(LogDate.class, this.log.toString());
......@@ -110,7 +110,7 @@ public class LogDate {
* @return
*/
public StringBuilder getLog() {
return log;
return this.log;
}
/**
......@@ -119,7 +119,7 @@ public class LogDate {
* @return
*/
public Date getStart() {
return start;
return new Date(this.start) ;
}
/**
......@@ -128,7 +128,7 @@ public class LogDate {
* @return
*/
public Date getEnd() {
return end;
return new Date(this.end);
}
/**
......@@ -137,7 +137,7 @@ public class LogDate {
* @return
*/
public double getLastSecond() {
return lastSecond;
return this.lastSecond;
}
/**
......@@ -146,6 +146,6 @@ public class LogDate {
* @return
*/
public double getTotalSecond() {
return totalSecond;
return this.totalSecond;
}
}
\ No newline at end of file
package com.yanzuoguang.util.log;
import com.yanzuoguang.util.helper.DateHelper;
import com.yanzuoguang.util.helper.StringHelper;
/**
* 日志处理默认处理函数
......@@ -15,16 +16,16 @@ public class LogDefault implements RunnableLog {
*/
@Override
public void run(LogInfo info) {
Class<?> cls = info.getCls();
StringBuilder sb = new StringBuilder();
if (info == null) {
return;
}
String clsName = "";
if (info.getCls() != null) {
Class<?> cls = info.getCls();
String clsName = StringHelper.EMPTY;
if (cls != null) {
clsName = info.getCls().getSimpleName();
}
sb.append(String.format("/* %s pid:%d t:%d/%d ms %s %s */ %s",
StringBuilder sb = new StringBuilder(String.format("/* %s pid:%d t:%d/%d ms %s %s */ %s",
DateHelper.getDateTimeString("HH:mm:ss.SSS", info.getNow()),
Thread.currentThread().getId(),
info.getTime(),
......
......@@ -14,7 +14,7 @@ public class LogInfo {
/**
* 错误发生时间
*/
private Date now;
private long now;
/**
* 标记信息
*/
......@@ -95,9 +95,9 @@ public class LogInfo {
*/
public LogInfo(Class<?> cls, Date date, Throwable ex, String msg) {
this.cls = cls;
this.now = date;
this.exception = ex;
this.message = msg;
this.setNow(date);
this.setException(ex);
this.setMessage(msg);
}
public Class<?> getCls() {
......@@ -109,11 +109,21 @@ public class LogInfo {
}
public Date getNow() {
return now;
if(this.now == 0){
return null;
}
else{
return new Date(this.now);
}
}
public void setNow(Date now) {
this.now = now;
if(now != null){
this.now = now.getTime() ;
}
else{
this.now = 0;
}
}
public String getTag() {
......
......@@ -116,10 +116,10 @@ public class TableHeadItem {
}
public boolean isDataColumn() {
return dataColumn;
return this.dataColumn;
}
public void setDataColumn(boolean dataColumn) {
dataColumn = dataColumn;
this.dataColumn = dataColumn;
}
}
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