Exemplo n.º 1
0
 public void getAlldeleteOrRemoveFile() throws IOException {
   List<Attachment> abandonFileList = attachmentService.getAlldeleteOrRemoveFile();
   attachmentService.deleteAlldeleteOrRemoveFile();
   LiGuangUtils.listToJson(abandonFileList);
   /**
    * 删除文件 for (Attachment att : abandonFileList) { File file = new
    * File(ServletActionContext.getServletContext().getRealPath(att.getFileurl())); File smallfile;
    * if (LiGuangUtils.isPicture(file.getName())) { smallfile = new
    * File(ServletActionContext.getServletContext().getRealPath(att.getSmallurl())); if
    * (smallfile.exists()) { smallfile.delete(); } } if (file.exists()) { file.delete(); } }
    */
 }
Exemplo n.º 2
0
  @Override
  public String execute() throws Exception {
    System.out.println(filename);
    System.out.println(file.getName());
    System.out.println(file.length());
    String RandomfileName = LiGuangUtils.getNewFilename(filename);
    att = new Attachment();
    att.setUploaddate(
        Timestamp.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
    att.setFilename(filename);
    att.setUid(uid);
    // att.setBelongid(belongid);
    att.setFilesize(file.length());
    String outpathString =
        ServletActionContext.getServletContext().getRealPath("/upload/" + RandomfileName);
    String AttUrl = "/upload/" + RandomfileName;
    att.setFileurl(AttUrl);
    att.setFiletype(LiGuangUtils.isPicture(filename) ? "pic" : "doc");
    if (!(new File(outpathString)).getParentFile().exists()) {
      (new File(outpathString)).getParentFile().mkdirs();
    }
    FileOutputStream fos =
        new FileOutputStream(
            ServletActionContext.getServletContext().getRealPath("/upload/" + RandomfileName));
    FileInputStream fis = new FileInputStream(file);

    byte[] buffer = new byte[1024];
    int len = 0;
    while ((len = fis.read(buffer)) > 0) {
      fos.write(buffer, 0, len);
    }
    fos.close();
    fis.close();
    if (LiGuangUtils.isPicture(outpathString)) {
      String smallname =
          LiGuangUtils.CreateThumbnail(
              ServletActionContext.getServletContext().getRealPath("/upload"), RandomfileName);
      att.setSmallurl("/upload/" + RandomfileName);
    }
    User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
    String ip = (String) ServletActionContext.getRequest().getSession().getAttribute("ip");
    att.setUid(null != user ? user.getUid() : null);
    att.setIp(null != ip ? ip : null);
    attachmentService.save(att);

    return super.execute();
  }
Exemplo n.º 3
0
 public void removeByNameAndSize() {
   attachmentService.removeByNameAndSize(filename, filesize);
 }
Exemplo n.º 4
0
 public void deleteNoOwnerfile() {
   User user = (User) ServletActionContext.getRequest().getSession().getAttribute("user");
   if (null != user) {
     attachmentService.updateAttachmentBelongid("delete", user.getUid());
   }
 }