mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
refactor
This commit is contained in:
@@ -35,7 +35,7 @@ import com.alibaba.druid.proxy.jdbc.PreparedStatementProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxy;
|
||||
import com.alibaba.druid.proxy.jdbc.ResultSetProxyImpl;
|
||||
import com.alibaba.druid.proxy.jdbc.StatementProxy;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
@@ -44,9 +44,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
|
||||
public final static String ATTR_CHARSET_PARAMETER = "ali.charset.param";
|
||||
public final static String ATTR_CHARSET_CONVERTER = "ali.charset.converter";
|
||||
// 数据库客户端编码
|
||||
private String clientEncoding;
|
||||
// 数据库服务器端编码
|
||||
private String serverEncoding;
|
||||
|
||||
public void loadConfig(AbstractDruidFilterConfig druidFilterConfig) {
|
||||
@@ -209,7 +207,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
|
||||
if (object instanceof Reader) {
|
||||
Reader reader = (Reader) object;
|
||||
String text = JdbcUtils.read(reader);
|
||||
String text = IOUtils.read(reader);
|
||||
return new StringReader(decode(connection, text));
|
||||
}
|
||||
|
||||
@@ -223,7 +221,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
|
||||
if (object instanceof Reader) {
|
||||
Reader reader = (Reader) object;
|
||||
String text = JdbcUtils.read(reader);
|
||||
String text = IOUtils.read(reader);
|
||||
return new StringReader(decode(stmt.getConnectionProxy(), text));
|
||||
}
|
||||
|
||||
@@ -401,7 +399,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
@Override
|
||||
public void preparedStatement_setCharacterStream(FilterChain chain, PreparedStatementProxy statement,
|
||||
int parameterIndex, java.io.Reader reader) throws SQLException {
|
||||
String text = JdbcUtils.read(reader);
|
||||
String text = IOUtils.read(reader);
|
||||
String encodedText = encode(statement.getConnectionProxy(), text);
|
||||
super.preparedStatement_setCharacterStream(chain, statement, parameterIndex, new StringReader(encodedText));
|
||||
}
|
||||
@@ -410,7 +408,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
public void preparedStatement_setCharacterStream(FilterChain chain, PreparedStatementProxy statement,
|
||||
int parameterIndex, java.io.Reader reader, int length)
|
||||
throws SQLException {
|
||||
String text = JdbcUtils.read(reader, length);
|
||||
String text = IOUtils.read(reader, length);
|
||||
String encodedText = encode(statement.getConnectionProxy(), text);
|
||||
super.preparedStatement_setCharacterStream(chain, statement, parameterIndex, new StringReader(encodedText),
|
||||
encodedText.length());
|
||||
@@ -420,7 +418,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
public void preparedStatement_setCharacterStream(FilterChain chain, PreparedStatementProxy statement,
|
||||
int parameterIndex, java.io.Reader reader, long length)
|
||||
throws SQLException {
|
||||
String text = JdbcUtils.read(reader, (int) length);
|
||||
String text = IOUtils.read(reader, (int) length);
|
||||
String encodedText = encode(statement.getConnectionProxy(), text);
|
||||
super.preparedStatement_setCharacterStream(chain, statement, parameterIndex, new StringReader(encodedText),
|
||||
encodedText.length());
|
||||
@@ -433,7 +431,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
String encodedText = encode(statement.getConnectionProxy(), (String) x);
|
||||
super.preparedStatement_setObject(chain, statement, parameterIndex, encodedText);
|
||||
} else if (x instanceof Reader) {
|
||||
String text = JdbcUtils.read((Reader) x);
|
||||
String text = IOUtils.read((Reader) x);
|
||||
String encodedText = encode(statement.getConnectionProxy(), text);
|
||||
super.preparedStatement_setObject(chain, statement, parameterIndex, new StringReader(encodedText));
|
||||
} else {
|
||||
@@ -448,7 +446,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
String encodedText = encode(statement.getConnectionProxy(), (String) x);
|
||||
super.preparedStatement_setObject(chain, statement, parameterIndex, encodedText, targetSqlType);
|
||||
} else if (x instanceof Reader) {
|
||||
String text = JdbcUtils.read((Reader) x);
|
||||
String text = IOUtils.read((Reader) x);
|
||||
String encodedText = encode(statement.getConnectionProxy(), text);
|
||||
super.preparedStatement_setObject(chain, statement, parameterIndex, new StringReader(encodedText),
|
||||
targetSqlType);
|
||||
@@ -465,7 +463,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
super.preparedStatement_setObject(chain, statement, parameterIndex, encodedText, targetSqlType,
|
||||
scaleOrLength);
|
||||
} else if (x instanceof Reader) {
|
||||
String text = JdbcUtils.read((Reader) x);
|
||||
String text = IOUtils.read((Reader) x);
|
||||
String encodedText = encode(statement.getConnectionProxy(), text);
|
||||
super.preparedStatement_setObject(chain, statement, parameterIndex, new StringReader(encodedText),
|
||||
targetSqlType, scaleOrLength);
|
||||
@@ -490,7 +488,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
@Override
|
||||
public java.io.Reader clob_getCharacterStream(FilterChain chain, ClobProxy wrapper) throws SQLException {
|
||||
Reader reader = super.clob_getCharacterStream(chain, wrapper);
|
||||
String text = JdbcUtils.read(reader);
|
||||
String text = IOUtils.read(reader);
|
||||
return new StringReader(decode(wrapper.getConnectionWrapper(), text));
|
||||
}
|
||||
|
||||
@@ -498,7 +496,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
public Reader clob_getCharacterStream(FilterChain chain, ClobProxy wrapper, long pos, long length)
|
||||
throws SQLException {
|
||||
Reader reader = super.clob_getCharacterStream(chain, wrapper, pos, length);
|
||||
String text = JdbcUtils.read(reader);
|
||||
String text = IOUtils.read(reader);
|
||||
return new StringReader(decode(wrapper.getConnectionWrapper(), text));
|
||||
}
|
||||
|
||||
@@ -518,7 +516,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
@Override
|
||||
public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement,
|
||||
String parameterName, java.io.Reader reader) throws SQLException {
|
||||
String text = JdbcUtils.read(reader);
|
||||
String text = IOUtils.read(reader);
|
||||
Reader encodeReader = new StringReader(encode(statement.getConnectionProxy(), text));
|
||||
super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader);
|
||||
}
|
||||
@@ -527,7 +525,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement,
|
||||
String parameterName, java.io.Reader reader, int length)
|
||||
throws SQLException {
|
||||
String text = JdbcUtils.read(reader, length);
|
||||
String text = IOUtils.read(reader, length);
|
||||
String encodeText = encode(statement.getConnectionProxy(), text);
|
||||
Reader encodeReader = new StringReader(encodeText);
|
||||
super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader, encodeText.length());
|
||||
@@ -537,7 +535,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
public void callableStatement_setCharacterStream(FilterChain chain, CallableStatementProxy statement,
|
||||
String parameterName, java.io.Reader reader, long length)
|
||||
throws SQLException {
|
||||
String text = JdbcUtils.read(reader, (int) length);
|
||||
String text = IOUtils.read(reader, (int) length);
|
||||
String encodeText = encode(statement.getConnectionProxy(), text);
|
||||
Reader encodeReader = new StringReader(encodeText);
|
||||
super.callableStatement_setCharacterStream(chain, statement, parameterName, encodeReader,
|
||||
@@ -557,7 +555,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
String encodedText = encode(statement.getConnectionProxy(), (String) x);
|
||||
super.callableStatement_setObject(chain, statement, parameterName, encodedText);
|
||||
} else if (x instanceof Reader) {
|
||||
String text = JdbcUtils.read((Reader) x);
|
||||
String text = IOUtils.read((Reader) x);
|
||||
String encodedText = encode(statement.getConnectionProxy(), text);
|
||||
super.callableStatement_setObject(chain, statement, parameterName, new StringReader(encodedText));
|
||||
} else {
|
||||
@@ -572,7 +570,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
String encodedText = encode(statement.getConnectionProxy(), (String) x);
|
||||
super.callableStatement_setObject(chain, statement, parameterName, encodedText, targetSqlType);
|
||||
} else if (x instanceof Reader) {
|
||||
String text = JdbcUtils.read((Reader) x);
|
||||
String text = IOUtils.read((Reader) x);
|
||||
String encodedText = encode(statement.getConnectionProxy(), text);
|
||||
super.callableStatement_setObject(chain, statement, parameterName, new StringReader(encodedText),
|
||||
targetSqlType);
|
||||
@@ -588,7 +586,7 @@ public class EncodingConvertFilter extends FilterAdapter {
|
||||
String encodedText = encode(statement.getConnectionProxy(), (String) x);
|
||||
super.callableStatement_setObject(chain, statement, parameterName, encodedText, targetSqlType, scale);
|
||||
} else if (x instanceof Reader) {
|
||||
String text = JdbcUtils.read((Reader) x);
|
||||
String text = IOUtils.read((Reader) x);
|
||||
String encodedText = encode(statement.getConnectionProxy(), text);
|
||||
super.callableStatement_setObject(chain, statement, parameterName, new StringReader(encodedText),
|
||||
targetSqlType, scale);
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import javax.sql.ConnectionEventListener;
|
||||
import javax.sql.StatementEventListener;
|
||||
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
/**
|
||||
@@ -217,14 +218,14 @@ public final class ConnectionHolder {
|
||||
buf.append("{ID:");
|
||||
buf.append(System.identityHashCode(conn));
|
||||
buf.append(", ConnectTime:\"");
|
||||
buf.append(JdbcUtils.toString(new Date(this.connecttimeMillis)));
|
||||
buf.append(IOUtils.toString(new Date(this.connecttimeMillis)));
|
||||
|
||||
buf.append("\", UseCount:");
|
||||
buf.append(useCount);
|
||||
|
||||
if (lastActiveTimeMillis > 0) {
|
||||
buf.append(", LastActiveTime:\"");
|
||||
buf.append(JdbcUtils.toString(new Date(this.lastActiveTimeMillis)));
|
||||
buf.append(IOUtils.toString(new Date(this.lastActiveTimeMillis)));
|
||||
buf.append("\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ import com.alibaba.druid.stat.JdbcStatManager;
|
||||
import com.alibaba.druid.util.ConcurrentIdentityHashMap;
|
||||
import com.alibaba.druid.util.DruidLoaderUtils;
|
||||
import com.alibaba.druid.util.Histogram;
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
/**
|
||||
@@ -1130,7 +1131,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
public List<String> getActiveConnectionStackTrace() {
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (ActiveConnectionTraceInfo traceInfo : this.activeConnections.values()) {
|
||||
list.add(JdbcUtils.toString(traceInfo.getStackTrace()));
|
||||
list.add(IOUtils.toString(traceInfo.getStackTrace()));
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -1375,7 +1376,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
if (lastConnectionConnectError != null) {
|
||||
map.put("ConnectionConnectErrorLastTime", stat.getConnectionStat().getErrorLastTime());
|
||||
map.put("ConnectionConnectErrorLastMessage", lastConnectionConnectError.getMessage());
|
||||
map.put("ConnectionConnectErrorLastStackTrace", JdbcUtils.getStackTrace(lastConnectionConnectError));
|
||||
map.put("ConnectionConnectErrorLastStackTrace", IOUtils.getStackTrace(lastConnectionConnectError));
|
||||
} else {
|
||||
map.put("ConnectionConnectErrorLastTime", null);
|
||||
map.put("ConnectionConnectErrorLastMessage", null);
|
||||
@@ -1398,7 +1399,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
map.put("StatementLastErrorTime", stat.getStatementStat().getLastErrorTime());
|
||||
map.put("StatementLastErrorMessage", lastStatementError.getMessage());
|
||||
|
||||
map.put("StatementLastErrorStackTrace", JdbcUtils.getStackTrace(lastStatementError));
|
||||
map.put("StatementLastErrorStackTrace", IOUtils.getStackTrace(lastStatementError));
|
||||
} else {
|
||||
map.put("StatementLastErrorTime", null);
|
||||
map.put("StatementLastErrorMessage", null);
|
||||
@@ -1424,7 +1425,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
Throwable lastResultSetError = stat.getResultSetStat().getLastError();
|
||||
if (lastResultSetError != null) {
|
||||
map.put("ResultSetLastErrorMessage", lastResultSetError.getMessage());
|
||||
map.put("ResultSetLastErrorStackTrace", JdbcUtils.getStackTrace(lastResultSetError));
|
||||
map.put("ResultSetLastErrorStackTrace", IOUtils.getStackTrace(lastResultSetError));
|
||||
} else {
|
||||
map.put("ResultSetLastErrorMessage", null);
|
||||
map.put("ResultSetLastErrorStackTrace", null);
|
||||
@@ -1435,7 +1436,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
Throwable lastConnectionError = stat.getConnectionStat().getErrorLast();
|
||||
if (lastConnectionError != null) {
|
||||
map.put("ConnectionErrorLastMessage", lastConnectionError.getMessage());
|
||||
map.put("ConnectionErrorLastStackTrace", JdbcUtils.getStackTrace(lastConnectionError));
|
||||
map.put("ConnectionErrorLastStackTrace", IOUtils.getStackTrace(lastConnectionError));
|
||||
} else {
|
||||
map.put("ConnectionErrorLastMessage", null);
|
||||
map.put("ConnectionErrorLastStackTrace", null);
|
||||
|
||||
@@ -56,6 +56,7 @@ import com.alibaba.druid.proxy.jdbc.DataSourceProxyConfig;
|
||||
import com.alibaba.druid.proxy.jdbc.TransactionInfo;
|
||||
import com.alibaba.druid.stat.DruidDataSourceStatManager;
|
||||
import com.alibaba.druid.stat.JdbcDataSourceStat;
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
/**
|
||||
@@ -237,7 +238,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
return;
|
||||
}
|
||||
|
||||
initStackTrace = JdbcUtils.toString(Thread.currentThread().getStackTrace());
|
||||
initStackTrace = IOUtils.toString(Thread.currentThread().getStackTrace());
|
||||
|
||||
this.id = DruidDriver.createDataSourceId();
|
||||
|
||||
@@ -1270,7 +1271,7 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
|
||||
buf.append("{");
|
||||
|
||||
buf.append("\n\tCreateTime:\"");
|
||||
buf.append(JdbcUtils.toString(getCreatedTime()));
|
||||
buf.append(IOUtils.toString(getCreatedTime()));
|
||||
buf.append("\"");
|
||||
|
||||
buf.append(",\n\tActiveCount:");
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
public abstract class URLConnectionConfigLoader implements ConfigLoader {
|
||||
@@ -71,7 +72,7 @@ public abstract class URLConnectionConfigLoader implements ConfigLoader {
|
||||
conn.connect();
|
||||
|
||||
reader = new InputStreamReader(conn.getInputStream());
|
||||
responseMessage = JdbcUtils.read(reader);
|
||||
responseMessage = IOUtils.read(reader);
|
||||
|
||||
handleResponseMessage();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -169,9 +169,8 @@ public class DruidDriver implements Driver, DruidDriverMBean {
|
||||
}
|
||||
}
|
||||
|
||||
DataSourceProxy oldDataSource = proxyDataSources.putIfAbsent(url, newDataSource); // 多线程处理需要
|
||||
DataSourceProxy oldDataSource = proxyDataSources.putIfAbsent(url, newDataSource);
|
||||
if (oldDataSource == null) {
|
||||
// 放进去的线程负责注册MBean
|
||||
if (config.isJmxOption()) {
|
||||
JMXUtils.register("com.alibaba.druid:type=JdbcStat", JdbcStatManager.getInstance());
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.alibaba.druid.filter.FilterChainImpl;
|
||||
import com.alibaba.druid.filter.stat.StatFilter;
|
||||
import com.alibaba.druid.stat.JdbcDataSourceStat;
|
||||
import com.alibaba.druid.stat.JdbcStatManager;
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
/**
|
||||
@@ -221,7 +222,7 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
if (lastConnectionConnectError != null) {
|
||||
map.put("ConnectionConnectErrorLastTime", stat.getConnectionStat().getErrorLastTime());
|
||||
map.put("ConnectionConnectErrorLastMessage", lastConnectionConnectError.getMessage());
|
||||
map.put("ConnectionConnectErrorLastStackTrace", JdbcUtils.getStackTrace(lastConnectionConnectError));
|
||||
map.put("ConnectionConnectErrorLastStackTrace", IOUtils.getStackTrace(lastConnectionConnectError));
|
||||
} else {
|
||||
map.put("ConnectionConnectErrorLastTime", null);
|
||||
map.put("ConnectionConnectErrorLastMessage", null);
|
||||
@@ -242,7 +243,7 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
map.put("StatementLastErrorTime", stat.getStatementStat().getLastErrorTime());
|
||||
map.put("StatementLastErrorMessage", lastStatementError.getMessage());
|
||||
|
||||
map.put("StatementLastErrorStackTrace", JdbcUtils.getStackTrace(lastStatementError));
|
||||
map.put("StatementLastErrorStackTrace", IOUtils.getStackTrace(lastStatementError));
|
||||
} else {
|
||||
map.put("StatementLastErrorTime", null);
|
||||
map.put("StatementLastErrorMessage", null);
|
||||
@@ -266,7 +267,7 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
Throwable lastResultSetError = stat.getResultSetStat().getLastError();
|
||||
if (lastResultSetError != null) {
|
||||
map.put("ResultSetLastErrorMessage", lastResultSetError.getMessage());
|
||||
map.put("ResultSetLastErrorStackTrace", JdbcUtils.getStackTrace(lastResultSetError));
|
||||
map.put("ResultSetLastErrorStackTrace", IOUtils.getStackTrace(lastResultSetError));
|
||||
} else {
|
||||
map.put("ResultSetLastErrorMessage", null);
|
||||
map.put("ResultSetLastErrorStackTrace", null);
|
||||
@@ -276,7 +277,7 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
|
||||
Throwable lastConnectionError = stat.getConnectionStat().getErrorLast();
|
||||
if (lastConnectionError != null) {
|
||||
map.put("ConnectionErrorLastMessage", lastConnectionError.getMessage());
|
||||
map.put("ConnectionErrorLastStackTrace", JdbcUtils.getStackTrace(lastConnectionError));
|
||||
map.put("ConnectionErrorLastStackTrace", IOUtils.getStackTrace(lastConnectionError));
|
||||
} else {
|
||||
map.put("ConnectionErrorLastMessage", null);
|
||||
map.put("ConnectionErrorLastStackTrace", null);
|
||||
|
||||
@@ -28,8 +28,8 @@ import javax.management.openmbean.OpenType;
|
||||
import javax.management.openmbean.SimpleType;
|
||||
|
||||
import com.alibaba.druid.util.Histogram;
|
||||
import com.alibaba.druid.util.IOUtils;
|
||||
import com.alibaba.druid.util.JMXUtils;
|
||||
import com.alibaba.druid.util.JdbcUtils;
|
||||
|
||||
/**
|
||||
* @author wenshao<szujobs@hotmail.com>
|
||||
@@ -477,7 +477,7 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
map.put("LastErrorMessage", lastError.getMessage());
|
||||
map.put("LastErrorClass", lastError.getClass().getName());
|
||||
|
||||
map.put("LastErrorStackTrace", JdbcUtils.getStackTrace(lastError));
|
||||
map.put("LastErrorStackTrace", IOUtils.getStackTrace(lastError));
|
||||
map.put("LastErrorTime", new Date(executeErrorLastTime));
|
||||
} else {
|
||||
map.put("LastErrorMessage", null);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.alibaba.druid.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class IOUtils {
|
||||
|
||||
public final static int DEFAULT_BUFFER_SIZE = 1024 * 4;
|
||||
|
||||
public static String read(Reader reader) {
|
||||
try {
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
|
||||
int n = 0;
|
||||
while (-1 != (n = reader.read(buffer))) {
|
||||
writer.write(buffer, 0, n);
|
||||
}
|
||||
|
||||
return writer.toString();
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalStateException("read error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static String read(Reader reader, int length) {
|
||||
try {
|
||||
char[] buffer = new char[length];
|
||||
|
||||
int offset = 0;
|
||||
int rest = length;
|
||||
int len;
|
||||
while ((len = reader.read(buffer, offset, rest)) != -1) {
|
||||
rest -= len;
|
||||
offset += len;
|
||||
|
||||
if (rest == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new String(buffer, 0, length - rest);
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalStateException("read error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static String toString(java.util.Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return format.format(date);
|
||||
}
|
||||
|
||||
public static String getStackTrace(Throwable ex) {
|
||||
StringWriter buf = new StringWriter();
|
||||
ex.printStackTrace(new PrintWriter(buf));
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String toString(StackTraceElement[] stackTrace) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (StackTraceElement item : stackTrace) {
|
||||
buf.append(item.toString());
|
||||
buf.append("\n");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public final class JMXUtils {
|
||||
map.put("class", error.getClass().getName());
|
||||
map.put("message", error.getMessage());
|
||||
|
||||
map.put("stackTrace", JdbcUtils.getStackTrace(error));
|
||||
map.put("stackTrace", IOUtils.getStackTrace(error));
|
||||
|
||||
return new CompositeDataSupport(getThrowableCompositeType(), map);
|
||||
}
|
||||
|
||||
@@ -16,12 +16,8 @@
|
||||
package com.alibaba.druid.util;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
@@ -32,7 +28,6 @@ import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -356,46 +351,6 @@ public final class JdbcUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String read(Reader reader) {
|
||||
try {
|
||||
final int DEFAULT_BUFFER_SIZE = 1024 * 4;
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
|
||||
int n = 0;
|
||||
while (-1 != (n = reader.read(buffer))) {
|
||||
writer.write(buffer, 0, n);
|
||||
}
|
||||
|
||||
return writer.toString();
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalStateException("read error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static String read(Reader reader, int length) {
|
||||
try {
|
||||
char[] buffer = new char[length];
|
||||
|
||||
int offset = 0;
|
||||
int rest = length;
|
||||
int len;
|
||||
while ((len = reader.read(buffer, offset, rest)) != -1) {
|
||||
rest -= len;
|
||||
offset += len;
|
||||
|
||||
if (rest == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new String(buffer, 0, length - rest);
|
||||
} catch (IOException ex) {
|
||||
throw new IllegalStateException("read error", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDriverClassName(String rawUrl) throws SQLException {
|
||||
if (rawUrl.startsWith("jdbc:derby:")) {
|
||||
return "org.apache.derby.jdbc.EmbeddedDriver";
|
||||
@@ -518,21 +473,6 @@ public final class JdbcUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getStackTrace(Throwable ex) {
|
||||
StringWriter buf = new StringWriter();
|
||||
ex.printStackTrace(new PrintWriter(buf));
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static String toString(java.util.Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return format.format(date);
|
||||
}
|
||||
|
||||
public static Driver createDriver(String driverClassName) throws SQLException {
|
||||
try {
|
||||
return (Driver) Class.forName(driverClassName).newInstance();
|
||||
@@ -646,13 +586,4 @@ public final class JdbcUtils {
|
||||
stmt.setObject(i + 1, parameters.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public static String toString(StackTraceElement[] stackTrace) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
for (StackTraceElement item : stackTrace) {
|
||||
buf.append(item.toString());
|
||||
buf.append("\n");
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user