| | |
| | | import config.PlatformConfig; |
| | | import jakarta.servlet.http.HttpServletRequest; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | |
| | | |
| | | /** |
| | | * 文件处理工具类 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Slf4j |
| | | public class FileUtils |
| | | { |
| | | public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+"; |
| | | |
| | | /** |
| | | * 输出指定文件的byte数组 |
| | | * |
| | | * |
| | | * @param filePath 文件路径 |
| | | * @param os 输出流 |
| | | * @return |
| | |
| | | } |
| | | |
| | | /** |
| | | * 从字符串中提取日期部分 |
| | | * |
| | | * @param inputString 输入字符串 |
| | | * @return 提取的日期字符串,如果未找到则返回 "" |
| | | */ |
| | | public static String extractDateFromString(String inputString) { |
| | | // 使用正则表达式来匹配日期格式 YYYY-MM-DD |
| | | String datePattern = "(\\d{4}-\\d{2}-\\d{2})"; |
| | | java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(datePattern); |
| | | java.util.regex.Matcher matcher = pattern.matcher(inputString); |
| | | if (matcher.find()) { |
| | | return matcher.group(1); |
| | | } |
| | | return ""; |
| | | } |
| | | public static String getImgName(String url) { |
| | | |
| | | // 找到最后一个斜杠的位置 |
| | | int lastSlashIndex = url.lastIndexOf('/'); |
| | | if(lastSlashIndex == -1){ |
| | | return ""; |
| | | } |
| | | // 提取从最后一个斜杠之后的部分 |
| | | return url.substring(lastSlashIndex + 1); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 写数据到文件中 |
| | | * |
| | | * @param data 数据 |
| | |
| | | |
| | | /** |
| | | * 删除文件 |
| | | * |
| | | * |
| | | * @param filePath 文件 |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 文件名称验证 |
| | | * |
| | | * |
| | | * @param filename 文件名称 |
| | | * @return true 正常 false 非法 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 检查文件是否可下载 |
| | | * |
| | | * |
| | | * @param resource 需要下载的文件 |
| | | * @return true 正常 false 非法 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 下载文件名重新编码 |
| | | * |
| | | * |
| | | * @param request 请求对象 |
| | | * @param fileName 文件名 |
| | | * @return 编码后的文件名 |
| | |
| | | |
| | | /** |
| | | * 获取图像后缀 |
| | | * |
| | | * |
| | | * @param photoByte 图像数据 |
| | | * @return 后缀名 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取文件名称 /profile/upload/2022/04/16/ruoyi.png -- ruoyi.png |
| | | * |
| | | * |
| | | * @param fileName 路径名称 |
| | | * @return 没有文件路径的名称 |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 获取不带后缀文件名称 /profile/upload/2022/04/16/ruoyi.png -- ruoyi |
| | | * |
| | | * |
| | | * @param fileName 路径名称 |
| | | * @return 没有文件路径和后缀的名称 |
| | | */ |