Commit caccb540 by songxiang

fix bug 23591

parent e17e44e4
...@@ -47,7 +47,12 @@ public enum TranscodeFromEnum { ...@@ -47,7 +47,12 @@ public enum TranscodeFromEnum {
/** /**
* 音频 * 音频
*/ */
AUDIOAPP_PDF("AUDIOAPP_PDF"); AUDIOAPP_PDF("AUDIOAPP_PDF"),
/**
* 文件管理中心
*/
CONVERT_PDF("CONVERT_PDF");
/** /**
* 值 * 值
......
...@@ -51,228 +51,244 @@ import it.sauronsoftware.jave.InputFormatException; ...@@ -51,228 +51,244 @@ import it.sauronsoftware.jave.InputFormatException;
*/ */
public class FileUtils { public class FileUtils {
/** /**
* logger * logger
*/ */
private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class); private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
/** /**
* PDF * PDF
*/ */
public final static String PDF = "PDF"; public final static String PDF = "PDF";
/** /**
* XML * XML
*/ */
public final static String XML = "XML"; public final static String XML = "XML";
/** /**
* IMAGE * IMAGE
*/ */
public final static String IMAGE = "IMAGE"; public final static String IMAGE = "IMAGE";
/** /**
* 音频 * 音频
*/ */
public final static String AUDIO = "AUDIO"; public final static String AUDIO = "AUDIO";
/** /**
* 视频格式 * 视频格式
*/ */
public final static String VIDEO = "VIDEO"; public final static String VIDEO = "VIDEO";
/** /**
* 压缩格式 * 压缩格式
*/ */
public final static String COMPRESS = "COMPRESS"; public final static String COMPRESS = "COMPRESS";
/** /**
* 办公软件 * 办公软件
*/ */
public final static String EDITOR = "EDITOR"; public final static String EDITOR = "EDITOR";
/** /**
* 文本格式 * 文本格式
*/ */
public final static String TEXT = "TEXT"; public final static String TEXT = "TEXT";
/** /**
* PDF文件格式 * OFFICE
*/ */
public static final String[] PDF_GATHER = {"PDF"}; public final static String OFFICE = "OFFICE";
/** /**
* XML文件格式 * PDF文件格式
*/ */
public static final String[] XML_GATHER = {"XML"}; public static final String[] PDF_GATHER = { "PDF" };
/**
* XML文件格式
*/
public static final String[] XML_GATHER = { "XML" };
/** /**
* 图片文件格式 * 图片文件格式
*/ */
public static final String[] IMAGE_GATHER = { "BMP", "JPG", "GIF", "PNG", "PCX", "TIF", "JPEG", "SVG", "WEBP" }; public static final String[] IMAGE_GATHER = { "BMP", "JPG", "GIF", "PNG", "PCX", "TIF", "JPEG", "SVG", "WEBP" };
/** /**
* 音頻文件格式 【"LRC" 为歌词字幕(这里作为音頻文件上传)】 * 音頻文件格式 【"LRC" 为歌词字幕(这里作为音頻文件上传)】
*/ */
public static final String[] AUDIO_GATHER = {"AMR", "MP3", "WMA", "WAV", "AAC", "APE", "M4A"}; public static final String[] AUDIO_GATHER = { "AMR", "MP3", "WMA", "WAV", "AAC", "APE", "M4A" };
/** /**
* 視頻文件格式 【"SRT", "SSA", "SMI", "SUB" 为视频“外挂型”字幕(这里作为视频文件上传)】 * 視頻文件格式 【"SRT", "SSA", "SMI", "SUB" 为视频“外挂型”字幕(这里作为视频文件上传)】
*/ */
public static final String[] VIDEO_GATHER = {"MPG", "MPEG", "AVI", "MOV", "ASF", "WMV", "NAVI", "3GP", "MKV", public static final String[] VIDEO_GATHER = { "MPG", "MPEG", "AVI", "MOV", "ASF", "WMV", "NAVI", "3GP", "MKV",
"FLV", "F4V", "RMVB", "RM", "MP4", "SRT", "SSA", "SMI", "SUB", "ASX", "M3U8"}; "FLV", "F4V", "RMVB", "RM", "MP4", "SRT", "SSA", "SMI", "SUB", "ASX", "M3U8" };
/** /**
* 压缩包文件格式 * 压缩包文件格式
*/ */
public static final String[] COMPRESS_GATHER = {"RAR", "ZIP"}; public static final String[] COMPRESS_GATHER = { "RAR", "ZIP" };
/** /**
* 文件格式 * 文件格式
*/ */
public static final String[] TEXT_GATHER = {"TXT", "LRC"}; public static final String[] TEXT_GATHER = { "TXT", "LRC" };
/** /**
* 编辑器格式 * 编辑器格式
*/ */
public static final String[] EDITOR_GATHER = {"DOC", "DOCX", "XLS", "XLSX", "PPT", "PPTX"}; public static final String[] EDITOR_GATHER = { "DOC", "DOCX", "XLS", "XLSX", "PPT", "PPTX" };
/** /**
* word格式 * word格式
*/ */
public static final String[] WORD_GATHER = {"DOC", "DOCX"}; public static final String[] WORD_GATHER = { "DOC", "DOCX" };
/** /**
* excel格式 * excel格式
*/ */
public static final String[] EXCEL_GATHER = {"XLS", "XLSX", "XLSM", "XLT", "XLTX", "XLTM", "CSV"}; public static final String[] EXCEL_GATHER = { "XLS", "XLSX", "XLSM", "XLT", "XLTX", "XLTM", "CSV" };
/** /**
* PPT格式 * PPT格式
*/ */
public static final String[] PPT_GATHER = {"PPT", "PPTX"}; public static final String[] PPT_GATHER = { "PPT", "PPTX" };
/** /**
* 根据文件类型获取文件分类 * office
* */
* @param fileType public static final String[] OFFICE_GATHER = { "DOC", "DOCX", "PPT", "PPTX", "XLS", "XLSX", "XLSM", "XLT", "XLTX",
* @return "XLTM", "CSV" };
*/
public static String getGatherName(String fileType) {
if (StringUtil.isEmpty(fileType)) {
return null;
}
// IMAGE
if (Arrays.asList(IMAGE_GATHER).contains(fileType.toUpperCase())) {
return IMAGE;
}
// AUDIO
if (Arrays.asList(AUDIO_GATHER).contains(fileType.toUpperCase())) {
return AUDIO;
}
// VIDEO
if (Arrays.asList(VIDEO_GATHER).contains(fileType.toUpperCase())) {
return VIDEO;
}
// PDF
if (Arrays.asList(PDF_GATHER).contains(fileType.toUpperCase())) {
return PDF;
}
// XML
if (Arrays.asList(XML_GATHER).contains(fileType.toUpperCase())) {
return XML;
}
// COMPRESS
if (Arrays.asList(COMPRESS_GATHER).contains(fileType.toUpperCase())) {
return COMPRESS;
}
// EDITOR
if (Arrays.asList(EDITOR_GATHER).contains(fileType.toUpperCase())) {
return EDITOR;
}
// COMPRESS
if (Arrays.asList(TEXT_GATHER).contains(fileType.toUpperCase())) {
return TEXT;
}
return null;
}
/** /**
* 传入文件夹路径,该方法能够实现创建整个路径 * 根据文件类型获取文件分类
* *
* @param path 文件夹路径,不包含文件名称及后缀名 * @param fileType
*/ * @return
public static boolean isDir(String filePath) { */
if (StringUtil.isEmpty(filePath)) { public static String getGatherName(String fileType) {
return false; if (StringUtil.isEmpty(fileType)) {
} return null;
String[] paths = filePath.split("/"); }
String temp = ""; // IMAGE
for (int i = 0; i < paths.length; i++) { if (Arrays.asList(IMAGE_GATHER).contains(fileType.toUpperCase())) {
if (i == 0) { return IMAGE;
temp = paths[0]; }
} else { // AUDIO
temp += "/" + paths[i]; if (Arrays.asList(AUDIO_GATHER).contains(fileType.toUpperCase())) {
} return AUDIO;
creatDir(temp); }
} // VIDEO
return true; if (Arrays.asList(VIDEO_GATHER).contains(fileType.toUpperCase())) {
} return VIDEO;
}
// PDF
if (Arrays.asList(PDF_GATHER).contains(fileType.toUpperCase())) {
return PDF;
}
// XML
if (Arrays.asList(XML_GATHER).contains(fileType.toUpperCase())) {
return XML;
}
// COMPRESS
if (Arrays.asList(COMPRESS_GATHER).contains(fileType.toUpperCase())) {
return COMPRESS;
}
// EDITOR
if (Arrays.asList(EDITOR_GATHER).contains(fileType.toUpperCase())) {
return EDITOR;
}
// TEXT
if (Arrays.asList(TEXT_GATHER).contains(fileType.toUpperCase())) {
return TEXT;
}
// OFFICE
if (Arrays.asList(OFFICE_GATHER).contains(fileType.toUpperCase())) {
return OFFICE;
}
return null;
}
/** /**
* 该方法用来判断文件是否存在,如果不存在则创建 * 传入文件夹路径,该方法能够实现创建整个路径
* *
* @param filePath * @param path
*/ * 文件夹路径,不包含文件名称及后缀名
public static boolean creatFile(String filePath) { */
if (StringUtil.isEmpty(filePath)) { public static boolean isDir(String filePath) {
return false; if (StringUtil.isEmpty(filePath)) {
} return false;
File file = new File(filePath); }
if (!file.exists()) { String[] paths = filePath.split("/");
try { String temp = "";
file.createNewFile(); for (int i = 0; i < paths.length; i++) {
return true; if (i == 0) {
} catch (Exception e) { temp = paths[0];
LOGGER.error("【文件工具】创建文件失败,<ERROR>:" + e.getMessage(), e); } else {
} temp += "/" + paths[i];
} }
return false; creatDir(temp);
} }
return true;
}
/** /**
* 该方法用来判断文件是否存在,如果不存在则创建,该方法能够实现创建整个路径 * 该方法用来判断文件是否存在,如果不存在则创建
* *
* @param filePath * @param filePath
*/ */
public static boolean creatFiles(String filePath) { public static boolean creatFile(String filePath) {
LOGGER.info("【文件API】创建文件,同时创建整个路径.<START>.[filePath]=" + filePath); if (StringUtil.isEmpty(filePath)) {
if (StringUtil.isEmpty(filePath)) { return false;
return false; }
} File file = new File(filePath);
filePath = filePath.replace(File.separator, "/"); if (!file.exists()) {
String dirPath = filePath.substring(0, filePath.lastIndexOf("/")); try {
File dirFile = new File(dirPath); file.createNewFile();
if (!dirFile.exists()) { return true;
try { } catch (Exception e) {
dirFile.mkdirs(); LOGGER.error("【文件工具】创建文件失败,<ERROR>:" + e.getMessage(), e);
} catch (Exception e) { }
LOGGER.error("【文件工具】创建文件夹失败,<ERROR>:" + e.getMessage(), e); }
return false; return false;
} }
}
File file = new File(filePath); /**
if (!file.exists()) { * 该方法用来判断文件是否存在,如果不存在则创建,该方法能够实现创建整个路径
try { *
file.createNewFile(); * @param filePath
return true; */
} catch (Exception e) { public static boolean creatFiles(String filePath) {
LOGGER.error("【文件工具】创建文件失败,<ERROR>:" + e.getMessage(), e); LOGGER.info("【文件API】创建文件,同时创建整个路径.<START>.[filePath]=" + filePath);
} if (StringUtil.isEmpty(filePath)) {
} return false;
LOGGER.info("【文件API】创建文件,同时创建整个路径.<END>"); }
return false; filePath = filePath.replace(File.separator, "/");
} String dirPath = filePath.substring(0, filePath.lastIndexOf("/"));
File dirFile = new File(dirPath);
if (!dirFile.exists()) {
try {
dirFile.mkdirs();
} catch (Exception e) {
LOGGER.error("【文件工具】创建文件夹失败,<ERROR>:" + e.getMessage(), e);
return false;
}
}
File file = new File(filePath);
if (!file.exists()) {
try {
file.createNewFile();
return true;
} catch (Exception e) {
LOGGER.error("【文件工具】创建文件失败,<ERROR>:" + e.getMessage(), e);
}
}
LOGGER.info("【文件API】创建文件,同时创建整个路径.<END>");
return false;
}
/** /**
* 该方法用来判断文件夹是否存在,如果不存在则创建,存在则什么都不做 * 该方法用来判断文件夹是否存在,如果不存在则创建,存在则什么都不做
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment