use of io.github.ihongs.util.verify.Wrong in project HongsCORE by ihongs.
the class UploadHelper method upload.
/**
* 检查文件对象并写入目标目录
* 检查当前文件
* @param file
* @param subn
* @return
* @throws Wrong
*/
public File upload(File file, String subn) throws Wrong {
if (file == null) {
setResultName("", null);
return null;
}
if (file.exists() == false) {
throw new Wrong("core.file.upload.not.exists");
}
/**
* 从文件名中解析类型和提取扩展名
*/
String name = file.getName();
String type = getTypeByName(name);
String extn = getExtnByName(name);
chkTypeOrExtn(type, extn);
setResultName(subn, extn);
/**
* 原始文件与目标文件不同才需移动
*/
File dist = new File(getResultPath());
if (!dist.equals(file)) {
File dirt = dist.getParentFile();
if (!dirt.isDirectory()) {
dirt.mkdirs();
}
file.renameTo(dist);
}
return dist;
}
Aggregations