Ejemplo n.º 1
0
 public void preparePath(ServletContext context) {
   SimpleDateFormat sdf = new SimpleDateFormat("/yyyy/MM/dd/");
   String basePath = context.getRealPath("/WEB-INF/weibo_files");
   String subPath = sdf.format(new Date());
   path = basePath + subPath + UUID.randomUUID().toString(); // avoids same
   // name
   // directory
   // if not exists then create it
   File dir = new File(path);
   if (!dir.exists()) {
     dir.mkdirs();
   }
   // copy style files into it
   URL tamplateUrl = this.getClass().getResource("/templates/style");
   try {
     FileUtils.copyFile(new File(tamplateUrl.toURI()), dir);
   } catch (URISyntaxException e) {
     LOG.error(e.getMessage());
   } catch (IOException e) {
     LOG.error("occurred a errer when copy style files " + e);
   }
 }
Ejemplo n.º 2
0
  @Override
  public JcUser packageZip(JcUser jcUser) {
    try {
      String weibo = compositeWeibo(jcUser);
      byte[] data = weibo.getBytes();
      BufferedOutputStream stream =
          new BufferedOutputStream(new FileOutputStream(new File(path, "index.html")));
      stream.write(data);
      stream.close();

      // package files in zip
      String zipPath = path + ".zip";
      File zip = new File(zipPath);
      FileUtils.zipFile(new File(path), zip);
      jcUser.setZipPath(zipPath);
      float fileSize = zip.length();
      jcUser.setFileSize(fileSize / (1024 * 1024));
    } catch (FileNotFoundException e) {
      LOG.debug("not found file' \n" + e);
    } catch (IOException e2) {
      LOG.debug("dowload zip function occured errer: \n" + e2);
    }
    return jcUser;
  }