Commit ba0afae6 authored by yanzg's avatar yanzg

消除成功接收处理

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