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 @Override
public void close() { public void close() {
super.finish(); super.finish();
IoUtil.close(bufferedReader); IoUtil.closeQuietly(bufferedReader);
} }
/** /**

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -340,7 +340,7 @@ public class IoUtil extends NioUtil {
throw new IORuntimeException(e); throw new IORuntimeException(e);
} finally { } finally {
if (isClose) { if (isClose) {
IoUtil.close(reader); IoUtil.closeQuietly(reader);
} }
} }
return builder.toString(); 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> * 尝试关闭指定对象<br>
* 判断对象如果实现了{@link AutoCloseable}则调用之 * 判断对象如果实现了{@link AutoCloseable}则调用之
@ -922,7 +893,38 @@ public class IoUtil extends NioUtil {
*/ */
public static void closeIfPossible(final Object obj) { public static void closeIfPossible(final Object obj) {
if (obj instanceof AutoCloseable) { 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); 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); in = new CheckedInputStream(in, checksum);
IoUtil.copy(in, EmptyOutputStream.INSTANCE); IoUtil.copy(in, EmptyOutputStream.INSTANCE);
} finally { } finally {
IoUtil.close(in); IoUtil.closeQuietly(in);
} }
return checksum; return checksum;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -143,7 +143,7 @@ public class Tailer implements Serializable {
try{ try{
this.executorService.shutdown(); this.executorService.shutdown();
} finally { } 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); IoUtil.copy(in, out, IoUtil.DEFAULT_BUFFER_SIZE, limit, null);
} finally { } finally {
if (closeAfterRead) { if (closeAfterRead) {
IoUtil.close(in); IoUtil.closeQuietly(in);
} }
} }
return out; return out;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,7 @@
package cn.hutool.db; package cn.hutool.db;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IoUtil; import cn.hutool.db.ds.DSKeys;
import cn.hutool.db.sql.SqlLog;
import cn.hutool.log.Log; import cn.hutool.log.Log;
import cn.hutool.log.level.Level; import cn.hutool.log.level.Level;
import cn.hutool.setting.Setting; import cn.hutool.setting.Setting;
@ -15,38 +14,6 @@ import cn.hutool.setting.Setting;
public final class DbUtil { public final class DbUtil {
private final static Log log = Log.get(); 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打印选项读取后会去除相应属性 * 从配置文件中读取SQL打印选项读取后会去除相应属性
* *
@ -55,10 +22,10 @@ public final class DbUtil {
*/ */
public static void setShowSqlGlobal(final Setting setting) { public static void setShowSqlGlobal(final Setting setting) {
// 初始化SQL显示 // 初始化SQL显示
final boolean isShowSql = Convert.toBoolean(setting.remove(SqlLog.KEY_SHOW_SQL), false); final boolean isShowSql = Convert.toBoolean(setting.remove(DSKeys.KEY_SHOW_SQL), false);
final boolean isFormatSql = Convert.toBoolean(setting.remove(SqlLog.KEY_FORMAT_SQL), false); final boolean isFormatSql = Convert.toBoolean(setting.remove(DSKeys.KEY_FORMAT_SQL), false);
final boolean isShowParams = Convert.toBoolean(setting.remove(SqlLog.KEY_SHOW_PARAMS), false); final boolean isShowParams = Convert.toBoolean(setting.remove(DSKeys.KEY_SHOW_PARAMS), false);
String sqlLevelStr = setting.remove(SqlLog.KEY_SQL_LEVEL); String sqlLevelStr = setting.remove(DSKeys.KEY_SQL_LEVEL);
if (null != sqlLevelStr) { if (null != sqlLevelStr) {
sqlLevelStr = sqlLevelStr.toUpperCase(); sqlLevelStr = sqlLevelStr.toUpperCase();
} }

View File

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

View File

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

View File

@ -1,16 +1,15 @@
package cn.hutool.db.dialect; 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.Connection;
import java.sql.DatabaseMetaData; import java.sql.DatabaseMetaData;
import java.sql.SQLException; 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); driver = identifyDriver(conn);
} finally { } finally {
DbUtil.close(conn); IoUtil.closeQuietly(conn);
} }
return driver; return driver;

View File

@ -182,7 +182,7 @@ public abstract class AbstractDSFactory implements DSFactory {
// 移除用户可能误加入的show sql配置项 // 移除用户可能误加入的show sql配置项
// issue#I3VW0R@Gitee // issue#I3VW0R@Gitee
DbUtil.removeShowSqlParams(config); removeShowSqlParams(config);
// 自动识别Driver // 自动识别Driver
String driver = config.getAndRemove(DSKeys.KEY_ALIAS_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); 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 * @author Looly
* @since 6.0.0
*/ */
public interface DSKeys { 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"}; String[] KEY_CONN_PROPS = {"remarks", "useInformationSchema"};
/** 别名字段名URL */ /**
String[] KEY_ALIAS_URL = { "url", "jdbcUrl" }; * 别名字段名URL
/** 别名字段名:驱动名 */ */
String[] KEY_ALIAS_DRIVER = { "driver", "driverClassName" }; String[] KEY_ALIAS_URL = {"url", "jdbcUrl"};
/** 别名字段名:用户名 */ /**
String[] KEY_ALIAS_USER = { "user", "username" }; * 别名字段名驱动名
/** 别名字段名:密码 */ */
String[] KEY_ALIAS_PASSWORD = { "pass", "password" }; 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 @Override
public void close() { public void close() {
if (this.ds instanceof AutoCloseable) { 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关闭时关闭所有连接池 // JVM关闭时关闭所有连接池
RuntimeUtil.addShutdownHook(()->{ RuntimeUtil.addShutdownHook(()->{
if (null != factory) { if (null != factory) {
IoUtil.close(factory); IoUtil.closeQuietly(factory);
StaticLog.debug("DataSource: [{}] closed.", factory.getDataSourceName()); StaticLog.debug("DataSource: [{}] closed.", factory.getDataSourceName());
factory = null; factory = null;
} }
@ -68,7 +68,7 @@ public class GlobalDSFactory {
return factory;// 数据源工厂不变时返回原数据源工厂 return factory;// 数据源工厂不变时返回原数据源工厂
} }
// 自定义数据源工厂前关闭之前的数据源 // 自定义数据源工厂前关闭之前的数据源
IoUtil.close(factory); IoUtil.closeQuietly(factory);
} }
StaticLog.debug("Custom use [{}] DataSource.", customDSFactory.getDataSourceName()); StaticLog.debug("Custom use [{}] DataSource.", customDSFactory.getDataSourceName());

View File

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

View File

@ -155,7 +155,7 @@ public class PooledDataSource extends AbstractDataSource {
@Override @Override
protected void finalize() { 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.collection.ListUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.text.StrUtil; import cn.hutool.core.text.StrUtil;
import cn.hutool.db.DbRuntimeException; import cn.hutool.db.DbRuntimeException;
import cn.hutool.db.DbUtil;
import cn.hutool.db.Entity; import cn.hutool.db.Entity;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.sql.Connection; import java.sql.*;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -102,7 +98,7 @@ public class MetaUtil {
} catch (final Exception e) { } catch (final Exception e) {
throw new DbRuntimeException("Get tables error!", e); throw new DbRuntimeException("Get tables error!", e);
} finally { } finally {
DbUtil.close(conn); IoUtil.closeQuietly(conn);
} }
return tables; return tables;
} }
@ -158,7 +154,7 @@ public class MetaUtil {
} catch (final Exception e) { } catch (final Exception e) {
throw new DbRuntimeException("Get columns error!", e); throw new DbRuntimeException("Get columns error!", e);
} finally { } finally {
DbUtil.close(conn); IoUtil.closeQuietly(conn);
} }
} }
@ -277,7 +273,7 @@ public class MetaUtil {
} catch (final SQLException e) { } catch (final SQLException e) {
throw new DbRuntimeException("Get columns error!", e); throw new DbRuntimeException("Get columns error!", e);
} finally { } finally {
DbUtil.close(conn); IoUtil.closeQuietly(conn);
} }
return table; return table;

View File

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

View File

@ -11,34 +11,28 @@ import cn.hutool.log.level.Level;
* @since 4.1.0 * @since 4.1.0
*/ */
public enum SqlLog { public enum SqlLog {
/**
* 单例
*/
INSTANCE; 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(); private final static Log log = LogFactory.get();
/** 是否debugSQL */ /**
* 是否debugSQL
*/
private boolean showSql; private boolean showSql;
/** 是否格式化SQL */ /**
* 是否格式化SQL
*/
private boolean formatSql; private boolean formatSql;
/** 是否显示参数 */ /**
* 是否显示参数
*/
private boolean showParams; private boolean showParams;
/** 默认日志级别 */ /**
* 默认日志级别
*/
private Level level = Level.DEBUG; private Level level = Level.DEBUG;
/** /**

View File

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

View File

@ -110,7 +110,7 @@ public class SevenZArchiver implements Archiver {
throw new IORuntimeException(e); 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) { } catch (final Exception ignore) {
//ignore //ignore
} }
IoUtil.close(this.out); IoUtil.closeQuietly(this.out);
} }
/** /**

View File

@ -158,6 +158,6 @@ public class SevenZExtractor implements Extractor, RandomAccess {
@Override @Override
public void close() { 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) { } catch (final ArchiveException e) {
// issue#2384如果报错可能持有文件句柄导致无法删除文件 // issue#2384如果报错可能持有文件句柄导致无法删除文件
IoUtil.close(in); IoUtil.closeQuietly(in);
throw new CompressException(e); throw new CompressException(e);
} }
} }
@ -168,6 +168,6 @@ public class StreamExtractor implements Extractor {
@Override @Override
public void close() { 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); in = FileUtil.getInputStream(imageFile);
return addImage(cid, in, FileTypeMap.getDefaultFileTypeMap().getContentType(imageFile)); return addImage(cid, in, FileTypeMap.getDefaultFileTypeMap().getContentType(imageFile));
} finally { } finally {
IoUtil.close(in); IoUtil.closeQuietly(in);
} }
} }

View File

@ -411,7 +411,7 @@ public class MailUtil {
for (final Entry<String, InputStream> entry : imageMap.entrySet()) { for (final Entry<String, InputStream> entry : imageMap.entrySet()) {
mail.addImage(entry.getKey(), entry.getValue()); 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) { } catch (final IOException e) {
throw new UtilException(e); throw new UtilException(e);
} finally { } finally {
IoUtil.close(writer); IoUtil.closeQuietly(writer);
} }
} }
@ -585,7 +585,7 @@ public class JakartaServletUtil {
in = FileUtil.getInputStream(file); in = FileUtil.getInputStream(file);
write(response, in, contentType, fileName); write(response, in, contentType, fileName);
} finally { } finally {
IoUtil.close(in); IoUtil.closeQuietly(in);
} }
} }
@ -658,8 +658,8 @@ public class JakartaServletUtil {
} catch (final IOException e) { } catch (final IOException e) {
throw new UtilException(e); throw new UtilException(e);
} finally { } finally {
IoUtil.close(out); IoUtil.closeQuietly(out);
IoUtil.close(in); IoUtil.closeQuietly(in);
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -127,7 +127,7 @@ public class MultipartOutputStream extends OutputStream {
@Override @Override
public void close() { public void close() {
finish(); 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); return this.bodyStream.copyTo(out, streamProgress);
} finally { } finally {
if (isCloseOut) { 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) { public HttpClient4Engine setConfig(final ClientConfig config) {
this.config = config; this.config = config;
// 重置客户端 // 重置客户端
IoUtil.close(this.engine); IoUtil.closeQuietly(this.engine);
this.engine = null; this.engine = null;
return this; return this;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,6 +25,6 @@ public class Issue2901Test {
.send(); .send();
Console.log(res.bodyStr()); 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!"); Console.error(e, "Read [logging.properties] from [%JRE_HOME%/lib/logging.properties] error!");
} }
} finally { } finally {
IoUtil.close(in); IoUtil.closeQuietly(in);
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ public class ExcelFileUtilTest {
Assert.assertTrue(ExcelFileUtil.isXls(in)); Assert.assertTrue(ExcelFileUtil.isXls(in));
Assert.assertFalse(ExcelFileUtil.isXlsx(in)); Assert.assertFalse(ExcelFileUtil.isXlsx(in));
} finally { } finally {
IoUtil.close(in); IoUtil.closeQuietly(in);
} }
} }
@ -27,7 +27,7 @@ public class ExcelFileUtilTest {
Assert.assertFalse(ExcelFileUtil.isXls(in)); Assert.assertFalse(ExcelFileUtil.isXls(in));
Assert.assertTrue(ExcelFileUtil.isXlsx(in)); Assert.assertTrue(ExcelFileUtil.isXlsx(in));
} finally { } 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!"); // log.error(e, "Load GroupSet error!");
return false; return false;
} finally { } finally {
IoUtil.close(settingStream); IoUtil.closeQuietly(settingStream);
} }
return true; return true;
} }
@ -229,7 +229,7 @@ public class GroupedSet extends HashMap<String, LinkedHashSet<String>> {
valueSet.add(line); valueSet.add(line);
} }
} finally { } 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(); this.watchMonitor.start();
StaticLog.debug("Auto load for [{}] listenning...", this.resource.getUrl()); StaticLog.debug("Auto load for [{}] listenning...", this.resource.getUrl());
} else { } else {
IoUtil.close(this.watchMonitor); IoUtil.closeQuietly(this.watchMonitor);
this.watchMonitor = null; this.watchMonitor = null;
} }
} }

View File

@ -88,7 +88,7 @@ public class SettingLoader {
log.error(e, "Load setting error!"); log.error(e, "Load setting error!");
return false; return false;
} finally { } finally {
IoUtil.close(settingStream); IoUtil.closeQuietly(settingStream);
} }
return true; return true;
} }
@ -140,7 +140,7 @@ public class SettingLoader {
this.groupedMap.put(group, keyValue[0].trim(), value); this.groupedMap.put(group, keyValue[0].trim(), value);
} }
} finally { } finally {
IoUtil.close(reader); IoUtil.closeQuietly(reader);
} }
} }
@ -189,7 +189,7 @@ public class SettingLoader {
writer = FileUtil.getPrintWriter(file, charset, false); writer = FileUtil.getPrintWriter(file, charset, false);
store(writer); store(writer);
} finally { } 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(); this.watchMonitor.start();
} else { } else {
IoUtil.close(this.watchMonitor); IoUtil.closeQuietly(this.watchMonitor);
this.watchMonitor = null; this.watchMonitor = null;
} }
} }
@ -399,7 +399,7 @@ public final class Props extends Properties implements TypeGetter<CharSequence>
} catch (final IOException e) { } catch (final IOException e) {
throw new IORuntimeException(e, "Store properties to [{}] error!", absolutePath); throw new IORuntimeException(e, "Store properties to [{}] error!", absolutePath);
} finally { } finally {
IoUtil.close(writer); IoUtil.closeQuietly(writer);
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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