我项目引入了 hutool ,但其代码设计,确实不好,贴代码
/**
* 下载文件
*
* @
param path 文件路径
* @
param fileName 文件名
* @
param outFile 输出文件或目录
*/
public void download(String path, String fileName, File outFile) {
if (outFile.isDirectory()) {
outFile = new File(outFile, fileName);
}
if (false == outFile.exists()) {
FileUtil.touch(outFile);
}
try (OutputStream out = FileUtil.getOutputStream(outFile)) {
download(path, fileName, out);
} catch (IOException e) {
throw new FtpException(e);
}
}
/**
* Ftp 异常
*
* @
author xiaoleilu
*/
public class FtpException extends RuntimeException {
private static final long serialVersionUID = -8490149159895201756L;
public FtpException(Throwable e) {
super(ExceptionUtil.getMessage(e), e);
}
public FtpException(String message) {
super(message);
}
public FtpException(String messageTemplate, Object... params) {
super(StrUtil.format(messageTemplate, params));
}
public FtpException(String message, Throwable throwable) {
super(message, throwable);
}
public FtpException(Throwable throwable, String messageTemplate, Object... params) {
super(StrUtil.format(messageTemplate, params), throwable);
}
}
download 方法把 IO 异常代替为 RuntimeException 。糟糕的设计。