Пример #1
0
 /*
  * 根据配置文件中key获得模块
  */
 public static InputStream getTemplateByKey(String key) {
   try {
     if (key != null && !"".equals(key)) {
       String templatePath = PropertiesUtil.getInstance().getProperty("excelExportTemplatePath");
       String k_v = PropertiesUtil.getInstance().getProperty(key);
       if (k_v != null && !"".equals(k_v)) {
         String realPath = templatePath + "/" + new String(k_v.getBytes(), "UTF-8");
         File file = new File(realPath);
         if (!file.exists()) {
           log.info(realPath + ":对应文件不存在!");
           FileException fe = new FileException(FileExceptionType.FILE_EXCEPTION_ALLOWEDTYPES);
           throw new GeneralException(fe.getErrorCode(), fe.getMessage(), fe, new Object[] {}) {};
         }
         return new FileInputStream(file);
       } else {
         log.info("配置文件中没有对应模块的键值对!");
         FileException fe =
             new FileException(FileExceptionType.FILE_EXCEPTION_PROPKEYVALNOTEXISTS);
         throw new GeneralException(fe.getErrorCode(), fe.getMessage(), fe, new Object[] {}) {};
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
Пример #2
0
 /*
  * 删除磁盘文件
  */
 public static boolean deleteDiskFile(String path) {
   File f = new File(path);
   if (!f.exists()) {
     FileException fe = new FileException(FileExceptionType.FILE_EXCEPTION_FILENOTEXISTS);
     throw new GeneralException(fe.getErrorCode(), fe.getMessage(), fe, new Object[] {}) {};
   }
   return f.delete();
 }
Пример #3
0
 /*
  * 创建文件名
  */
 @SuppressWarnings("serial")
 public static String createFileName(String fileName) {
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd_");
   String name = formatter.format(new Date()) + UUID.randomUUID().toString();
   if (fileName.lastIndexOf(".") != -1) {
     // 得到后缀名
     String extension = fileName.substring(fileName.lastIndexOf("."));
     String allowedTypes = PropertiesUtil.getInstance().getProperty("allowedTypes").trim();
     if (allowedTypes == null
         || "".equals(allowedTypes)
         || allowedTypes.indexOf(extension.substring(1, extension.length()).toLowerCase()) < 0) {
       FileException fe = new FileException(FileExceptionType.FILE_EXCEPTION_ALLOWEDTYPES);
       throw new GeneralException(fe.getErrorCode(), fe.getMessage(), fe, new Object[] {}) {};
     }
     name = name + extension;
   }
   return name;
 }