This commit is contained in:
Looly 2023-03-27 02:02:10 +08:00
parent 16f7549c7d
commit 4fca8310e7
96 changed files with 307 additions and 315 deletions

View File

@ -86,7 +86,7 @@ public class LineIter extends ComputeIter<String> implements IterableIter<String
@Override
public void close() {
super.finish();
IoUtil.close(bufferedReader);
IoUtil.closeQuietly(bufferedReader);
}
/**

View File

@ -96,7 +96,7 @@ public class Deflate implements Closeable {
@Override
public void close() {
IoUtil.close(this.target);
IoUtil.close(this.source);
IoUtil.closeQuietly(this.target);
IoUtil.closeQuietly(this.source);
}
}

View File

@ -88,7 +88,7 @@ public class Gzip implements Closeable {
@Override
public void close() {
IoUtil.close(this.target);
IoUtil.close(this.source);
IoUtil.closeQuietly(this.target);
IoUtil.closeQuietly(this.source);
}
}

View File

@ -192,9 +192,9 @@ public class ZipReader implements Closeable {
@Override
public void close() throws IORuntimeException {
if (null != this.zipFile) {
IoUtil.close(this.zipFile);
IoUtil.closeQuietly(this.zipFile);
} else {
IoUtil.close(this.in);
IoUtil.closeQuietly(this.in);
}
}

View File

@ -743,7 +743,7 @@ public class ZipUtil {
in = FileUtil.getInputStream(file);
return gzip(in, (int) file.length());
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
@ -852,7 +852,7 @@ public class ZipUtil {
in = FileUtil.getInputStream(file);
return zlib(in, level, (int) file.length());
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}

View File

@ -220,7 +220,7 @@ public class ZipWriter implements Closeable {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(this.out);
IoUtil.closeQuietly(this.out);
}
}
@ -289,7 +289,7 @@ public class ZipWriter implements Closeable {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
IoUtil.flush(this.out);

View File

@ -85,7 +85,7 @@ public class StringConverter extends AbstractConverter {
} catch (final SQLException e) {
throw new ConvertException(e);
} finally {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
}
@ -104,7 +104,7 @@ public class StringConverter extends AbstractConverter {
} catch (final SQLException e) {
throw new ConvertException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
}

View File

@ -92,7 +92,7 @@ public class CharsetDetector {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
return null;
}

View File

@ -340,7 +340,7 @@ public class IoUtil extends NioUtil {
throw new IORuntimeException(e);
} finally {
if (isClose) {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
}
return builder.toString();
@ -884,35 +884,6 @@ public class IoUtil extends NioUtil {
}
}
/**
* 关闭<br>
* 关闭失败不会抛出异常
*
* @param closeable 被关闭的对象
*/
public static void close(final AutoCloseable closeable) {
if (null != closeable) {
try {
closeable.close();
} catch (final Exception e) {
// 静默关闭
}
}
}
/**
* 关闭<br>
* 关闭失败不会抛出异常
*
* @param closeable 被关闭的对象
* @throws IOException IO异常
*/
public static void nullSafeClose(final Closeable closeable) throws IOException {
if (null != closeable) {
closeable.close();
}
}
/**
* 尝试关闭指定对象<br>
* 判断对象如果实现了{@link AutoCloseable}则调用之
@ -922,7 +893,38 @@ public class IoUtil extends NioUtil {
*/
public static void closeIfPossible(final Object obj) {
if (obj instanceof AutoCloseable) {
close((AutoCloseable) obj);
closeQuietly((AutoCloseable) obj);
}
}
/**
* 按照给定顺序连续关闭一系列对象<br>
* 这些对象必须按照顺序关闭否则会出错
*
* @param closeables 需要关闭的对象
*/
public static void closeQuietly(final AutoCloseable... closeables) {
for (final AutoCloseable closeable : closeables) {
if (null != closeable) {
try {
closeable.close();
} catch (final Exception e) {
// 静默关闭
}
}
}
}
/**
* 关闭<br>
* 关闭失败抛出{@link IOException}异常
*
* @param closeable 被关闭的对象
* @throws IOException IO异常
*/
public static void nullSafeClose(final Closeable closeable) throws IOException {
if (null != closeable) {
closeable.close();
}
}

View File

@ -221,20 +221,4 @@ public class NioUtil {
}
return StrUtil.str(buffer, charset);
}
/**
* 关闭<br>
* 关闭失败不会抛出异常
*
* @param closeable 被关闭的对象
*/
public static void close(final AutoCloseable closeable) {
if (null != closeable) {
try {
closeable.close();
} catch (final Exception e) {
// 静默关闭
}
}
}
}

View File

@ -81,7 +81,7 @@ public class ChecksumUtil {
in = new CheckedInputStream(in, checksum);
IoUtil.copy(in, EmptyOutputStream.INSTANCE);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
return checksum;
}

View File

@ -73,8 +73,8 @@ public class FileChannelCopier extends IoCopier<FileChannel, FileChannel> {
outChannel = out.getChannel();
return copy(inChannel, outChannel);
} finally {
IoUtil.close(outChannel);
IoUtil.close(inChannel);
IoUtil.closeQuietly(outChannel);
IoUtil.closeQuietly(inChannel);
}
}

View File

@ -81,7 +81,7 @@ public class FileReader extends FileWrapper {
} catch (final Exception e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
return bytes;
@ -140,7 +140,7 @@ public class FileReader extends FileWrapper {
reader = FileUtil.getReader(file, charset);
IoUtil.readLines(reader, lineHandler);
} finally {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
}
@ -177,7 +177,7 @@ public class FileReader extends FileWrapper {
throw new UtilException(e);
}
} finally {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
return result;
}
@ -233,7 +233,7 @@ public class FileReader extends FileWrapper {
throw new IORuntimeException(e);
} finally{
if(isCloseOut){
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}
}

View File

@ -201,7 +201,7 @@ public class FileTypeUtil {
in = IoUtil.toStream(file);
return getType(in, file.getName(),isExact);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}

View File

@ -249,7 +249,7 @@ public class FileUtil extends PathUtil {
} catch (final IOException e) {
throw new IORuntimeException(StrUtil.format("Can not read file path of [{}]", path), e);
} finally {
IoUtil.close(jarFile);
IoUtil.closeQuietly(jarFile);
}
}
@ -1247,8 +1247,8 @@ public class FileUtil extends PathUtil {
return IoUtil.contentEquals(input1, input2);
} finally {
IoUtil.close(input1);
IoUtil.close(input2);
IoUtil.closeQuietly(input1);
IoUtil.closeQuietly(input2);
}
}
@ -1294,8 +1294,8 @@ public class FileUtil extends PathUtil {
input2 = getReader(file2, charset);
return IoUtil.contentEqualsIgnoreEOL(input1, input2);
} finally {
IoUtil.close(input1);
IoUtil.close(input2);
IoUtil.closeQuietly(input1);
IoUtil.closeQuietly(input2);
}
}
@ -1676,7 +1676,7 @@ public class FileUtil extends PathUtil {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
@ -1796,7 +1796,7 @@ public class FileUtil extends PathUtil {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}

View File

@ -130,7 +130,7 @@ public class FileWriter extends FileWrapper {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(writer);
IoUtil.closeQuietly(writer);
}
return file;
}
@ -344,9 +344,9 @@ public class FileWriter extends FileWrapper {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(out);
IoUtil.closeQuietly(out);
if (isCloseIn) {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
return file;

View File

@ -143,7 +143,7 @@ public class Tailer implements Serializable {
try{
this.executorService.shutdown();
} finally {
IoUtil.close(this.randomAccessFile);
IoUtil.closeQuietly(this.randomAccessFile);
}
}

View File

@ -105,7 +105,7 @@ public class StreamReader {
IoUtil.copy(in, out, IoUtil.DEFAULT_BUFFER_SIZE, limit, null);
} finally {
if (closeAfterRead) {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
return out;

View File

@ -57,7 +57,7 @@ public class StreamWriter {
throw new IORuntimeException(e);
} finally {
if (closeAfterWrite) {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}
}
@ -82,7 +82,7 @@ public class StreamWriter {
throw new IORuntimeException(e);
} finally {
if (closeAfterWrite) {
IoUtil.close(osw);
IoUtil.closeQuietly(osw);
}
}
}
@ -108,7 +108,7 @@ public class StreamWriter {
throw new IORuntimeException(e);
} finally {
if (closeAfterWrite) {
IoUtil.close(osw);
IoUtil.closeQuietly(osw);
}
}
}

View File

@ -87,7 +87,7 @@ public class SyncInputStream extends FilterInputStream {
// 忽略读取流中的EOF错误
}finally {
// 读取结束
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
return copyLength;
}

View File

@ -185,6 +185,6 @@ public class WatchServer extends Thread implements Closeable, Serializable {
@Override
public void close() {
isClosed = true;
IoUtil.close(watchService);
IoUtil.closeQuietly(watchService);
}
}

View File

@ -701,7 +701,7 @@ public class NetUtil {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}

View File

@ -230,7 +230,7 @@ public class UploadFile {
return false;
}
} finally {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
return true;
}

View File

@ -145,7 +145,7 @@ public class RuntimeUtil {
in = process.getInputStream();
return IoUtil.readLines(in, charset, new ArrayList<>());
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
destroy(process);
}
}
@ -175,7 +175,7 @@ public class RuntimeUtil {
in = process.getInputStream();
return IoUtil.read(in, charset);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
destroy(process);
}
}
@ -205,7 +205,7 @@ public class RuntimeUtil {
in = process.getErrorStream();
return IoUtil.read(in, charset);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
destroy(process);
}
}

View File

@ -169,7 +169,7 @@ public class XmlUtil {
in = FileUtil.getInputStream(file);
return readXML(in);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
@ -246,7 +246,7 @@ public class XmlUtil {
in = FileUtil.getInputStream(file);
readBySax(new InputSource(in), contentHandler);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
@ -262,7 +262,7 @@ public class XmlUtil {
try {
readBySax(new InputSource(reader), contentHandler);
} finally {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
}
@ -278,7 +278,7 @@ public class XmlUtil {
try {
readBySax(new InputSource(source), contentHandler);
} finally {
IoUtil.close(source);
IoUtil.closeQuietly(source);
}
}
@ -489,7 +489,7 @@ public class XmlUtil {
writer = FileUtil.getWriter(path, CharsetUtil.charset(charsetName), false);
write(doc, writer, charsetName, INDENT_DEFAULT);
} finally {
IoUtil.close(writer);
IoUtil.closeQuietly(writer);
}
}
@ -833,7 +833,7 @@ public class XmlUtil {
xmlenc.writeObject(bean);
} finally {
// 关闭XMLEncoder会相应关闭OutputStream
IoUtil.close(xmlenc);
IoUtil.closeQuietly(xmlenc);
}
}

View File

@ -730,7 +730,7 @@ public class KeyUtil {
in = FileUtil.getInputStream(keyFile);
return readKeyStore(type, in, password);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}

View File

@ -140,7 +140,7 @@ public class PemUtil {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(pemReader);
IoUtil.closeQuietly(pemReader);
}
}
@ -206,7 +206,7 @@ public class PemUtil {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(pemWriter);
IoUtil.closeQuietly(pemWriter);
}
}
}

View File

@ -218,7 +218,7 @@ public class Digester implements Serializable {
in = FileUtil.getInputStream(file);
return digest(in);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}

View File

@ -131,7 +131,7 @@ public class Mac implements Serializable {
in = FileUtil.getInputStream(file);
return digest(in);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}

View File

@ -308,9 +308,9 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
lock.unlock();
// issue#I4EMST@Gitee
// CipherOutputStream必须关闭才能完全写出
IoUtil.close(cipherOutputStream);
IoUtil.closeQuietly(cipherOutputStream);
if (isClose) {
IoUtil.close(data);
IoUtil.closeQuietly(data);
}
}
}
@ -361,9 +361,9 @@ public class SymmetricCrypto implements SymmetricEncryptor, SymmetricDecryptor,
lock.unlock();
// issue#I4EMST@Gitee
// CipherOutputStream必须关闭才能完全写出
IoUtil.close(cipherInputStream);
IoUtil.closeQuietly(cipherInputStream);
if (isClose) {
IoUtil.close(data);
IoUtil.closeQuietly(data);
}
}
}

View File

@ -1,8 +1,7 @@
package cn.hutool.db;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IoUtil;
import cn.hutool.db.sql.SqlLog;
import cn.hutool.db.ds.DSKeys;
import cn.hutool.log.Log;
import cn.hutool.log.level.Level;
import cn.hutool.setting.Setting;
@ -15,38 +14,6 @@ import cn.hutool.setting.Setting;
public final class DbUtil {
private final static Log log = Log.get();
/**
* 连续关闭一系列的SQL相关对象<br>
* 这些对象必须按照顺序关闭否则会出错
*
* @param objsToClose 需要关闭的对象
*/
public static void close(final Object... objsToClose) {
for (final Object obj : objsToClose) {
if (null != obj) {
if (obj instanceof AutoCloseable) {
IoUtil.close((AutoCloseable) obj);
} else {
log.warn("Object {} not a ResultSet or Statement or PreparedStatement or Connection!", obj.getClass().getName());
}
}
}
}
/**
* 移除配置文件中的Show SQL相关配置项<br>
* 此方法用于移除用户配置在分组下的配置项目
*
* @param setting 配置项
* @since 5.7.2
*/
public static void removeShowSqlParams(final Setting setting) {
setting.remove(SqlLog.KEY_SHOW_SQL);
setting.remove(SqlLog.KEY_FORMAT_SQL);
setting.remove(SqlLog.KEY_SHOW_PARAMS);
setting.remove(SqlLog.KEY_SQL_LEVEL);
}
/**
* 从配置文件中读取SQL打印选项读取后会去除相应属性
*
@ -55,10 +22,10 @@ public final class DbUtil {
*/
public static void setShowSqlGlobal(final Setting setting) {
// 初始化SQL显示
final boolean isShowSql = Convert.toBoolean(setting.remove(SqlLog.KEY_SHOW_SQL), false);
final boolean isFormatSql = Convert.toBoolean(setting.remove(SqlLog.KEY_FORMAT_SQL), false);
final boolean isShowParams = Convert.toBoolean(setting.remove(SqlLog.KEY_SHOW_PARAMS), false);
String sqlLevelStr = setting.remove(SqlLog.KEY_SQL_LEVEL);
final boolean isShowSql = Convert.toBoolean(setting.remove(DSKeys.KEY_SHOW_SQL), false);
final boolean isFormatSql = Convert.toBoolean(setting.remove(DSKeys.KEY_FORMAT_SQL), false);
final boolean isShowParams = Convert.toBoolean(setting.remove(DSKeys.KEY_SHOW_PARAMS), false);
String sqlLevelStr = setting.remove(DSKeys.KEY_SQL_LEVEL);
if (null != sqlLevelStr) {
sqlLevelStr = sqlLevelStr.toUpperCase();
}

View File

@ -1,5 +1,6 @@
package cn.hutool.db;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.text.StrUtil;
@ -85,7 +86,7 @@ public class DialectRunner implements Serializable {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
}
@ -114,7 +115,7 @@ public class DialectRunner implements Serializable {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
} else {
return insertOrUpdate(conn, record, keys);
@ -168,7 +169,7 @@ public class DialectRunner implements Serializable {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
}
@ -195,7 +196,7 @@ public class DialectRunner implements Serializable {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
}
@ -234,7 +235,7 @@ public class DialectRunner implements Serializable {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
}

View File

@ -1,5 +1,7 @@
package cn.hutool.db;
import cn.hutool.core.io.IoUtil;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
@ -15,6 +17,9 @@ import java.util.Map;
*
*/
public enum ThreadLocalConnection {
/**
* 单例
*/
INSTANCE;
private final ThreadLocal<GroupedConnection> threadLocal = new ThreadLocal<>();
@ -97,7 +102,7 @@ public enum ThreadLocalConnection {
// ignore
}
connMap.remove(ds);
DbUtil.close(conn);
IoUtil.closeQuietly(conn);
}
return this;
}

View File

@ -1,16 +1,15 @@
package cn.hutool.db.dialect;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.text.StrUtil;
import cn.hutool.db.DbRuntimeException;
import cn.hutool.db.ds.DSWrapper;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import javax.sql.DataSource;
import cn.hutool.core.text.StrUtil;
import cn.hutool.db.DbRuntimeException;
import cn.hutool.db.DbUtil;
import cn.hutool.db.ds.DSWrapper;
/**
* 驱动相关工具类包括自动获取驱动类名
*
@ -55,7 +54,7 @@ public class DriverUtil {
}
driver = identifyDriver(conn);
} finally {
DbUtil.close(conn);
IoUtil.closeQuietly(conn);
}
return driver;

View File

@ -182,7 +182,7 @@ public abstract class AbstractDSFactory implements DSFactory {
// 移除用户可能误加入的show sql配置项
// issue#I3VW0R@Gitee
DbUtil.removeShowSqlParams(config);
removeShowSqlParams(config);
// 自动识别Driver
String driver = config.getAndRemove(DSKeys.KEY_ALIAS_DRIVER);
@ -194,4 +194,18 @@ public abstract class AbstractDSFactory implements DSFactory {
return DSWrapper.wrap(createDataSource(url, driver, user, pass, config), driver);
}
/**
* 移除配置文件中的Show SQL相关配置项<br>
* 此方法用于移除用户配置在分组下的配置项目
*
* @param setting 配置项
* @since 5.7.2
*/
private static void removeShowSqlParams(final Setting setting) {
setting.remove(DSKeys.KEY_SHOW_SQL);
setting.remove(DSKeys.KEY_FORMAT_SQL);
setting.remove(DSKeys.KEY_SHOW_PARAMS);
setting.remove(DSKeys.KEY_SQL_LEVEL);
}
}

View File

@ -3,20 +3,47 @@ package cn.hutool.db.ds;
/**
* 数据源配置的字段名
*
* @since 6.0.0
* @author Looly
* @since 6.0.0
*/
public interface DSKeys {
/** 某些数据库需要的特殊配置项需要的配置项 */
/**
* 配置文件中配置属性名是否显示SQL
*/
String KEY_SHOW_SQL = "showSql";
/**
* 配置文件中配置属性名是否格式化SQL
*/
String KEY_FORMAT_SQL = "formatSql";
/**
* 配置文件中配置属性名是否显示参数
*/
String KEY_SHOW_PARAMS = "showParams";
/**
* 配置文件中配置属性名显示的日志级别
*/
String KEY_SQL_LEVEL = "sqlLevel";
/**
* 某些数据库需要的特殊配置项需要的配置项
*/
String[] KEY_CONN_PROPS = {"remarks", "useInformationSchema"};
/** 别名字段名URL */
String[] KEY_ALIAS_URL = { "url", "jdbcUrl" };
/** 别名字段名:驱动名 */
String[] KEY_ALIAS_DRIVER = { "driver", "driverClassName" };
/** 别名字段名:用户名 */
String[] KEY_ALIAS_USER = { "user", "username" };
/** 别名字段名:密码 */
String[] KEY_ALIAS_PASSWORD = { "pass", "password" };
/**
* 别名字段名URL
*/
String[] KEY_ALIAS_URL = {"url", "jdbcUrl"};
/**
* 别名字段名驱动名
*/
String[] KEY_ALIAS_DRIVER = {"driver", "driverClassName"};
/**
* 别名字段名用户名
*/
String[] KEY_ALIAS_USER = {"user", "username"};
/**
* 别名字段名密码
*/
String[] KEY_ALIAS_PASSWORD = {"pass", "password"};
}

View File

@ -116,7 +116,7 @@ public class DSWrapper implements Wrapper<DataSource>, DataSource, Closeable, Cl
@Override
public void close() {
if (this.ds instanceof AutoCloseable) {
IoUtil.close((AutoCloseable) this.ds);
IoUtil.closeQuietly((AutoCloseable) this.ds);
}
}

View File

@ -23,7 +23,7 @@ public class GlobalDSFactory {
// JVM关闭时关闭所有连接池
RuntimeUtil.addShutdownHook(()->{
if (null != factory) {
IoUtil.close(factory);
IoUtil.closeQuietly(factory);
StaticLog.debug("DataSource: [{}] closed.", factory.getDataSourceName());
factory = null;
}
@ -68,7 +68,7 @@ public class GlobalDSFactory {
return factory;// 数据源工厂不变时返回原数据源工厂
}
// 自定义数据源工厂前关闭之前的数据源
IoUtil.close(factory);
IoUtil.closeQuietly(factory);
}
StaticLog.debug("Custom use [{}] DataSource.", customDSFactory.getDataSourceName());

View File

@ -1,7 +1,7 @@
package cn.hutool.db.ds.pooled;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.db.DbUtil;
import cn.hutool.setting.dialect.Props;
import java.sql.Connection;
@ -11,10 +11,10 @@ import java.util.Properties;
/**
* 池化
* @author Looly
*
* @author Looly
*/
public class PooledConnection extends ConnectionWraper{
public class PooledConnection extends ConnectionWraper {
private final PooledDataSource ds;
private boolean isClosed;
@ -41,13 +41,19 @@ public class PooledConnection extends ConnectionWraper{
// 其它参数
final Properties connProps = config.getConnProps();
if(MapUtil.isNotEmpty(connProps)){
if (MapUtil.isNotEmpty(connProps)) {
info.putAll(connProps);
}
this.raw = DriverManager.getConnection(config.getUrl(), info);
}
/**
* 构造
*
* @param ds {@link PooledDataSource}
* @param conn {@link Connection}
*/
public PooledConnection(final PooledDataSource ds, final Connection conn) {
this.ds = ds;
this.raw = conn;
@ -74,6 +80,7 @@ public class PooledConnection extends ConnectionWraper{
/**
* 打开连接
*
* @return this
*/
protected PooledConnection open() {
@ -83,10 +90,11 @@ public class PooledConnection extends ConnectionWraper{
/**
* 释放连接
*
* @return this
*/
protected PooledConnection release() {
DbUtil.close(this.raw);
IoUtil.closeQuietly(this.raw);
return this;
}
}

View File

@ -155,7 +155,7 @@ public class PooledDataSource extends AbstractDataSource {
@Override
protected void finalize() {
IoUtil.close(this);
IoUtil.closeQuietly(this);
}
/**

View File

@ -2,17 +2,13 @@ package cn.hutool.db.meta;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.text.StrUtil;
import cn.hutool.db.DbRuntimeException;
import cn.hutool.db.DbUtil;
import cn.hutool.db.Entity;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@ -102,7 +98,7 @@ public class MetaUtil {
} catch (final Exception e) {
throw new DbRuntimeException("Get tables error!", e);
} finally {
DbUtil.close(conn);
IoUtil.closeQuietly(conn);
}
return tables;
}
@ -158,7 +154,7 @@ public class MetaUtil {
} catch (final Exception e) {
throw new DbRuntimeException("Get columns error!", e);
} finally {
DbUtil.close(conn);
IoUtil.closeQuietly(conn);
}
}
@ -277,7 +273,7 @@ public class MetaUtil {
} catch (final SQLException e) {
throw new DbRuntimeException("Get columns error!", e);
} finally {
DbUtil.close(conn);
IoUtil.closeQuietly(conn);
}
return table;

View File

@ -1,18 +1,13 @@
package cn.hutool.db.sql;
import cn.hutool.core.collection.iter.ArrayIter;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.func.SerFunction;
import cn.hutool.db.DbRuntimeException;
import cn.hutool.db.DbUtil;
import cn.hutool.db.StatementUtil;
import cn.hutool.db.handler.RsHandler;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.util.Map;
/**
@ -59,7 +54,7 @@ public class SqlExecutor {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
}
@ -81,7 +76,7 @@ public class SqlExecutor {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(call);
IoUtil.closeQuietly(call);
}
}
@ -150,8 +145,8 @@ public class SqlExecutor {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(ps);
DbUtil.close(rs);
IoUtil.closeQuietly(ps);
IoUtil.closeQuietly(rs);
}
}
@ -174,7 +169,7 @@ public class SqlExecutor {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
}
@ -215,7 +210,7 @@ public class SqlExecutor {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(statement);
IoUtil.closeQuietly(statement);
}
}
@ -273,7 +268,7 @@ public class SqlExecutor {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
}
@ -295,7 +290,7 @@ public class SqlExecutor {
ps = statementFunc.apply(conn);
return executeQuery(ps, rsh);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
}
@ -375,7 +370,7 @@ public class SqlExecutor {
try {
return query(ps, rsh, params);
} finally {
DbUtil.close(ps);
IoUtil.closeQuietly(ps);
}
}
@ -398,7 +393,7 @@ public class SqlExecutor {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
DbUtil.close(rs);
IoUtil.closeQuietly(rs);
}
}
// -------------------------------------------------------------------------------------------------------------------------------- Private method end

View File

@ -11,43 +11,37 @@ import cn.hutool.log.level.Level;
* @since 4.1.0
*/
public enum SqlLog {
/**
* 单例
*/
INSTANCE;
/**
* 配置文件中配置属性名是否显示SQL
*/
public static final String KEY_SHOW_SQL = "showSql";
/**
* 配置文件中配置属性名是否格式化SQL
*/
public static final String KEY_FORMAT_SQL = "formatSql";
/**
* 配置文件中配置属性名是否显示参数
*/
public static final String KEY_SHOW_PARAMS = "showParams";
/**
* 配置文件中配置属性名显示的日志级别
*/
public static final String KEY_SQL_LEVEL = "sqlLevel";
private final static Log log = LogFactory.get();
/** 是否debugSQL */
/**
* 是否debugSQL
*/
private boolean showSql;
/** 是否格式化SQL */
/**
* 是否格式化SQL
*/
private boolean formatSql;
/** 是否显示参数 */
/**
* 是否显示参数
*/
private boolean showParams;
/** 默认日志级别 */
/**
* 默认日志级别
*/
private Level level = Level.DEBUG;
/**
* 设置全局配置是否通过debug日志显示SQL
*
* @param isShowSql 是否显示SQL
* @param isFormatSql 是否格式化显示的SQL
* @param isShowSql 是否显示SQL
* @param isFormatSql 是否格式化显示的SQL
* @param isShowParams 是否打印参数
* @param level 日志级别
* @param level 日志级别
*/
public void init(final boolean isShowSql, final boolean isFormatSql, final boolean isShowParams, final Level level) {
this.showSql = isShowSql;
@ -81,7 +75,7 @@ public enum SqlLog {
/**
* 打印SQL日志
*
* @param sql SQL语句
* @param sql SQL语句
* @param paramValues 参数可为null
*/
public void log(final String sql, final Object paramValues) {

View File

@ -161,7 +161,7 @@ public class SqlUtil {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
}
@ -181,7 +181,7 @@ public class SqlUtil {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
@ -204,9 +204,9 @@ public class SqlUtil {
} catch (final SQLException e) {
throw new DbRuntimeException(e);
} finally {
IoUtil.close(out);
IoUtil.closeQuietly(out);
if (closeAfterUse) {
IoUtil.close(dataStream);
IoUtil.closeQuietly(dataStream);
}
}
return blob;

View File

@ -110,7 +110,7 @@ public class SevenZArchiver implements Archiver {
throw new IORuntimeException(e);
}
}
IoUtil.close(this.sevenZOutputFile);
IoUtil.closeQuietly(this.sevenZOutputFile);
}
/**

View File

@ -145,7 +145,7 @@ public class StreamArchiver implements Archiver {
} catch (final Exception ignore) {
//ignore
}
IoUtil.close(this.out);
IoUtil.closeQuietly(this.out);
}
/**

View File

@ -158,6 +158,6 @@ public class SevenZExtractor implements Extractor, RandomAccess {
@Override
public void close() {
IoUtil.close(this.sevenZFile);
IoUtil.closeQuietly(this.sevenZFile);
}
}

View File

@ -90,7 +90,7 @@ public class StreamExtractor implements Extractor {
}
} catch (final ArchiveException e) {
// issue#2384如果报错可能持有文件句柄导致无法删除文件
IoUtil.close(in);
IoUtil.closeQuietly(in);
throw new CompressException(e);
}
}
@ -168,6 +168,6 @@ public class StreamExtractor implements Extractor {
@Override
public void close() {
IoUtil.close(this.in);
IoUtil.closeQuietly(this.in);
}
}

View File

@ -294,7 +294,7 @@ public class Mail implements Builder<MimeMessage> {
in = FileUtil.getInputStream(imageFile);
return addImage(cid, in, FileTypeMap.getDefaultFileTypeMap().getContentType(imageFile));
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}

View File

@ -411,7 +411,7 @@ public class MailUtil {
for (final Entry<String, InputStream> entry : imageMap.entrySet()) {
mail.addImage(entry.getKey(), entry.getValue());
// 关闭流
IoUtil.close(entry.getValue());
IoUtil.closeQuietly(entry.getValue());
}
}

View File

@ -566,7 +566,7 @@ public class JakartaServletUtil {
} catch (final IOException e) {
throw new UtilException(e);
} finally {
IoUtil.close(writer);
IoUtil.closeQuietly(writer);
}
}
@ -585,7 +585,7 @@ public class JakartaServletUtil {
in = FileUtil.getInputStream(file);
write(response, in, contentType, fileName);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
@ -658,8 +658,8 @@ public class JakartaServletUtil {
} catch (final IOException e) {
throw new UtilException(e);
} finally {
IoUtil.close(out);
IoUtil.close(in);
IoUtil.closeQuietly(out);
IoUtil.closeQuietly(in);
}
}

View File

@ -565,7 +565,7 @@ public class ServletUtil {
} catch (final IOException e) {
throw new UtilException(e);
} finally {
IoUtil.close(writer);
IoUtil.closeQuietly(writer);
}
}
@ -584,7 +584,7 @@ public class ServletUtil {
in = FileUtil.getInputStream(file);
write(response, in, contentType, fileName);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
@ -657,8 +657,8 @@ public class ServletUtil {
} catch (final IOException e) {
throw new UtilException(e);
} finally {
IoUtil.close(out);
IoUtil.close(in);
IoUtil.closeQuietly(out);
IoUtil.closeQuietly(in);
}
}

View File

@ -477,7 +477,7 @@ public class JschUtil {
} catch (final JSchException e) {
throw new JschRuntimeException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
close(channel);
}
}
@ -511,8 +511,8 @@ public class JschUtil {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(out);
IoUtil.close(in);
IoUtil.closeQuietly(out);
IoUtil.closeQuietly(in);
close(shell);
}
}

View File

@ -255,7 +255,7 @@ public class SshjSftp extends AbstractFtp {
} catch (final Exception e) {
throw new FtpException(e);
} finally {
IoUtil.close(session);
IoUtil.closeQuietly(session);
}
}
}

View File

@ -45,7 +45,7 @@ public interface Template {
out = FileUtil.getOutputStream(file);
this.render(bindingMap, out);
} finally {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}

View File

@ -115,7 +115,7 @@ public class JAXBUtil {
} catch (final Exception e) {
throw new RuntimeException("convertToJava2 错误:" + e.getMessage(), e);
} finally {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
}
}

View File

@ -19,7 +19,7 @@ public class FtpTest {
ftp.cd("/file/aaa");
Console.log(ftp.pwd());
IoUtil.close(ftp);
IoUtil.closeQuietly(ftp);
}
@Test
@ -30,7 +30,7 @@ public class FtpTest {
final boolean upload = ftp.uploadFile("/temp", FileUtil.file("d:/test/test.zip"));
Console.log(upload);
IoUtil.close(ftp);
IoUtil.closeQuietly(ftp);
}
@Test
@ -54,7 +54,7 @@ public class FtpTest {
Console.log("打印pwd: " + ftp.pwd());
IoUtil.close(ftp);
IoUtil.closeQuietly(ftp);
}
@Test
@ -63,7 +63,7 @@ public class FtpTest {
final Ftp ftp = new Ftp("looly.centos");
ftp.recursiveDownloadFolder("/",FileUtil.file("d:/test/download"));
IoUtil.close(ftp);
IoUtil.closeQuietly(ftp);
}
@Test
@ -75,7 +75,7 @@ public class FtpTest {
Console.log(ftp.pwd());
ftp.recursiveDownloadFolder("/",FileUtil.file("d:/test/download"));
IoUtil.close(ftp);
IoUtil.closeQuietly(ftp);
}
@Test
@ -90,7 +90,7 @@ public class FtpTest {
FileUtil.file("d:/test/download/" + name));
}
IoUtil.close(ftp);
IoUtil.closeQuietly(ftp);
}
@Test

View File

@ -71,7 +71,7 @@ public class JschUtilTest {
Console.log("打印pwd: " + sftp.pwd());
IoUtil.close(sftp);
IoUtil.closeQuietly(sftp);
}
@Test

View File

@ -50,7 +50,7 @@ public interface HttpBody {
try {
write(out);
} finally {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}

View File

@ -127,7 +127,7 @@ public class MultipartOutputStream extends OutputStream {
@Override
public void close() {
finish();
IoUtil.close(this.out);
IoUtil.closeQuietly(this.out);
}
/**

View File

@ -106,7 +106,7 @@ public class ResponseBody implements HttpBody, Closeable {
return this.bodyStream.copyTo(out, streamProgress);
} finally {
if (isCloseOut) {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}
}

View File

@ -48,7 +48,7 @@ public class HttpClient4Engine implements ClientEngine {
public HttpClient4Engine setConfig(final ClientConfig config) {
this.config = config;
// 重置客户端
IoUtil.close(this.engine);
IoUtil.closeQuietly(this.engine);
this.engine = null;
return this;
}

View File

@ -53,7 +53,7 @@ public class HttpClient5Engine implements ClientEngine {
public HttpClient5Engine setConfig(final ClientConfig config) {
this.config = config;
// 重置客户端
IoUtil.close(this.engine);
IoUtil.closeQuietly(this.engine);
this.engine = null;
return this;
}

View File

@ -66,7 +66,7 @@ public class JdkClientEngine implements ClientEngine {
doSend(message);
} catch (final IOException e) {
// 出错后关闭连接
IoUtil.close(this);
IoUtil.closeQuietly(this);
throw new RuntimeException(e);
}
@ -110,7 +110,7 @@ public class JdkClientEngine implements ClientEngine {
*/
private void initConn(final Request message) {
// 执行下次请求时自动关闭上次请求常用于转发
IoUtil.close(this);
IoUtil.closeQuietly(this);
this.conn = buildConn(message);
}

View File

@ -202,7 +202,7 @@ public class JdkHttpResponse implements Response, Closeable {
@Override
public void close() {
// 关闭流
IoUtil.close(this.body);
IoUtil.closeQuietly(this.body);
// 关闭连接
this.httpConnection.disconnectQuietly();
}

View File

@ -351,8 +351,8 @@ public class HttpServerResponse extends HttpServerBase {
out = this.httpExchange.getResponseBody();
IoUtil.copy(in, out);
} finally {
IoUtil.close(out);
IoUtil.close(in);
IoUtil.closeQuietly(out);
IoUtil.closeQuietly(in);
}
return this;
}
@ -391,7 +391,7 @@ public class HttpServerResponse extends HttpServerBase {
in = FileUtil.getInputStream(file);
write(in, (int)fileSize, contentType, fileName);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
return this;
}

View File

@ -540,7 +540,7 @@ public class SoapClient implements HeaderOperation<SoapClient> {
} catch (final IOException | SOAPException e) {
throw new SoapRuntimeException(e);
} finally {
IoUtil.close(res);
IoUtil.closeQuietly(res);
}
}

View File

@ -25,6 +25,6 @@ public class Issue2901Test {
.send();
Console.log(res.bodyStr());
IoUtil.close(res);
IoUtil.closeQuietly(res);
}
}

View File

@ -53,7 +53,7 @@ public class JdkLogFactory extends LogFactory{
Console.error(e, "Read [logging.properties] from [%JRE_HOME%/lib/logging.properties] error!");
}
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
}

View File

@ -263,7 +263,7 @@ public class CsvBaseReader implements Serializable {
rowHandler.accept(csvParser.next());
}
} finally {
IoUtil.close(csvParser);
IoUtil.closeQuietly(csvParser);
}
}

View File

@ -143,6 +143,6 @@ public class CsvReader extends CsvBaseReader implements Iterable<CsvRow>, Closea
@Override
public void close() {
IoUtil.close(this.reader);
IoUtil.closeQuietly(this.reader);
}
}

View File

@ -344,7 +344,7 @@ public final class CsvWriter implements Closeable, Flushable, Serializable {
@Override
public void close() {
IoUtil.close(this.writer);
IoUtil.closeQuietly(this.writer);
}
@Override

View File

@ -505,7 +505,7 @@ public class ExcelBase<T extends ExcelBase<T>> implements Closeable {
*/
@Override
public void close() {
IoUtil.close(this.workbook);
IoUtil.closeQuietly(this.workbook);
this.sheet = null;
this.workbook = null;
this.isClosed = true;

View File

@ -1321,7 +1321,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
throw new IORuntimeException(e);
} finally {
if (isCloseOut) {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}
return this;

View File

@ -147,7 +147,7 @@ public class WorkbookUtil {
} catch (final Exception e) {
throw new POIException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}

View File

@ -148,7 +148,7 @@ public class Excel03SaxReader implements HSSFListener, ExcelSaxReader<Excel03Sax
} catch (final IOException e) {
throw new POIException(e);
} finally {
IoUtil.close(fs);
IoUtil.closeQuietly(fs);
}
return this;
}

View File

@ -174,7 +174,7 @@ public class Excel07SaxReader implements ExcelSaxReader<Excel07SaxReader> {
} catch (final Exception e) {
throw new POIException(e);
} finally {
IoUtil.close(sheetInputStream);
IoUtil.closeQuietly(sheetInputStream);
}
return this;
}

View File

@ -69,7 +69,7 @@ public class SheetRidReader extends DefaultHandler {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(workbookData);
IoUtil.closeQuietly(workbookData);
}
return this;
}

View File

@ -142,6 +142,6 @@ public class OfdWriter implements Serializable, Closeable {
@Override
public void close() {
IoUtil.close(this.doc);
IoUtil.closeQuietly(this.doc);
}
}

View File

@ -208,7 +208,7 @@ public class Word07Writer implements Closeable {
} catch (final IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
return this;
@ -267,7 +267,7 @@ public class Word07Writer implements Closeable {
throw new IORuntimeException(e);
} finally {
if (isCloseOut) {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}
return this;
@ -289,7 +289,7 @@ public class Word07Writer implements Closeable {
* 关闭Word文档但是不写出
*/
protected void closeWithoutFlush() {
IoUtil.close(this.doc);
IoUtil.closeQuietly(this.doc);
this.isClosed = true;
}
}

View File

@ -16,7 +16,7 @@ public class CsvParserTest {
final CsvRow row = parser.nextRow();
//noinspection ConstantConditions
Assert.assertEquals("b\"bba\"", row.getRawList().get(1));
IoUtil.close(parser);
IoUtil.closeQuietly(parser);
}
@Test
@ -26,7 +26,7 @@ public class CsvParserTest {
final CsvRow row = parser.nextRow();
//noinspection ConstantConditions
Assert.assertEquals("\"bba\"bbb", row.getRawList().get(1));
IoUtil.close(parser);
IoUtil.closeQuietly(parser);
}
@Test
@ -36,7 +36,7 @@ public class CsvParserTest {
final CsvRow row = parser.nextRow();
//noinspection ConstantConditions
Assert.assertEquals("bba", row.getRawList().get(1));
IoUtil.close(parser);
IoUtil.closeQuietly(parser);
}
@Test
@ -46,7 +46,7 @@ public class CsvParserTest {
final CsvRow row = parser.nextRow();
//noinspection ConstantConditions
Assert.assertEquals("", row.getRawList().get(1));
IoUtil.close(parser);
IoUtil.closeQuietly(parser);
}
@Test

View File

@ -16,7 +16,7 @@ public class ExcelFileUtilTest {
Assert.assertTrue(ExcelFileUtil.isXls(in));
Assert.assertFalse(ExcelFileUtil.isXlsx(in));
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
@ -27,7 +27,7 @@ public class ExcelFileUtilTest {
Assert.assertFalse(ExcelFileUtil.isXls(in));
Assert.assertTrue(ExcelFileUtil.isXlsx(in));
} finally {
IoUtil.close(in);
IoUtil.closeQuietly(in);
}
}
}

View File

@ -166,7 +166,7 @@ public class GroupedSet extends HashMap<String, LinkedHashSet<String>> {
// log.error(e, "Load GroupSet error!");
return false;
} finally {
IoUtil.close(settingStream);
IoUtil.closeQuietly(settingStream);
}
return true;
}
@ -229,7 +229,7 @@ public class GroupedSet extends HashMap<String, LinkedHashSet<String>> {
valueSet.add(line);
}
} finally {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
}

View File

@ -222,7 +222,7 @@ public class Setting extends AbsSetting implements Map<String, String> {
this.watchMonitor.start();
StaticLog.debug("Auto load for [{}] listenning...", this.resource.getUrl());
} else {
IoUtil.close(this.watchMonitor);
IoUtil.closeQuietly(this.watchMonitor);
this.watchMonitor = null;
}
}

View File

@ -88,7 +88,7 @@ public class SettingLoader {
log.error(e, "Load setting error!");
return false;
} finally {
IoUtil.close(settingStream);
IoUtil.closeQuietly(settingStream);
}
return true;
}
@ -140,7 +140,7 @@ public class SettingLoader {
this.groupedMap.put(group, keyValue[0].trim(), value);
}
} finally {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
}
@ -189,7 +189,7 @@ public class SettingLoader {
writer = FileUtil.getPrintWriter(file, charset, false);
store(writer);
} finally {
IoUtil.close(writer);
IoUtil.closeQuietly(writer);
}
}

View File

@ -219,7 +219,7 @@ public final class Props extends Properties implements TypeGetter<CharSequence>
});
this.watchMonitor.start();
} else {
IoUtil.close(this.watchMonitor);
IoUtil.closeQuietly(this.watchMonitor);
this.watchMonitor = null;
}
}
@ -399,7 +399,7 @@ public final class Props extends Properties implements TypeGetter<CharSequence>
} catch (final IOException e) {
throw new IORuntimeException(e, "Store properties to [{}] error!", absolutePath);
} finally {
IoUtil.close(writer);
IoUtil.closeQuietly(writer);
}
}

View File

@ -96,7 +96,7 @@ public class YamlUtil {
return yaml.loadAs(reader, type);
} finally {
if (isCloseReader) {
IoUtil.close(reader);
IoUtil.closeQuietly(reader);
}
}
}

View File

@ -54,7 +54,7 @@ public class ChannelUtil {
try {
channel.connect(address).get();
} catch (final InterruptedException | ExecutionException e) {
IoUtil.close(channel);
IoUtil.closeQuietly(channel);
throw new SocketRuntimeException(e);
}
return channel;

View File

@ -147,7 +147,7 @@ public class AioServer implements Closeable {
*/
@Override
public void close() {
IoUtil.close(this.channel);
IoUtil.closeQuietly(this.channel);
if (null != this.group && false == this.group.isShutdown()) {
try {

View File

@ -199,7 +199,7 @@ public class AioSession implements Closeable{
*/
@Override
public void close() {
IoUtil.close(this.channel);
IoUtil.closeQuietly(this.channel);
this.readBuffer = null;
this.writeBuffer = null;
}

View File

@ -161,7 +161,7 @@ public class NioClient implements Closeable {
@Override
public void close() {
IoUtil.close(this.selector);
IoUtil.close(this.channel);
IoUtil.closeQuietly(this.selector);
IoUtil.closeQuietly(this.channel);
}
}

View File

@ -140,7 +140,7 @@ public class NioServer implements Closeable {
try{
handler.handle(socketChannel);
} catch (final Exception e){
IoUtil.close(socketChannel);
IoUtil.closeQuietly(socketChannel);
log.error(e);
}
}
@ -148,7 +148,7 @@ public class NioServer implements Closeable {
@Override
public void close() {
IoUtil.close(this.selector);
IoUtil.close(this.serverSocketChannel);
IoUtil.closeQuietly(this.selector);
IoUtil.closeQuietly(this.serverSocketChannel);
}
}

View File

@ -33,7 +33,7 @@ public class NioServerTest {
doWrite(sc, body);
} else if (readBytes < 0) {
IoUtil.close(sc);
IoUtil.closeQuietly(sc);
}
} catch (final IOException e){
throw new IORuntimeException(e);

View File

@ -751,7 +751,7 @@ public class Img implements Serializable {
out = ImgUtil.getImageOutputStream(targetFile);
write(out);
} finally {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}

View File

@ -514,7 +514,7 @@ public class ImgUtil {
imageOutputStream = getImageOutputStream(destImageFile);
convert(read(srcImageFile), destExtName, imageOutputStream, StrUtil.equalsIgnoreCase(IMAGE_TYPE_PNG, srcExtName));
} finally {
IoUtil.close(imageOutputStream);
IoUtil.closeQuietly(imageOutputStream);
}
}

View File

@ -96,7 +96,7 @@ public class ImgWriter {
out = ImgUtil.getImageOutputStream(targetFile);
write(out);
} finally {
IoUtil.close(out);
IoUtil.closeQuietly(out);
}
}