예제 #1
0
파일: Controler.java 프로젝트: lucee/Lucee
    public boolean accept(Resource res) {

      if (res.isDirectory()) return allowDir;

      // load content
      String str = null;
      try {
        str = IOUtil.toString(res, "UTF-8");
      } catch (IOException e) {
        return false;
      }

      int index = str.indexOf(':');
      if (index != -1) {
        long expires = Caster.toLongValue(str.substring(0, index), -1L);
        // check is for backward compatibility, old files have no expires date inside. they do ot
        // expire
        if (expires != -1) {
          if (expires < System.currentTimeMillis()) {
            return true;
          }
          str = str.substring(index + 1);
          return false;
        }
      }
      // old files not having a timestamp inside
      else if (res.lastModified() <= time) {
        return true;
      }
      return false;
    }
예제 #2
0
파일: Controler.java 프로젝트: lucee/Lucee
 private void checkSize(ConfigWeb config, Resource dir, long maxSize, ResourceFilter filter) {
   if (!dir.exists()) return;
   Resource res = null;
   int count = ArrayUtil.size(filter == null ? dir.list() : dir.list(filter));
   long size = ResourceUtil.getRealSize(dir, filter);
   PrintWriter out = config.getOutWriter();
   SystemOut.printDate(out, "check size of directory [" + dir + "]");
   SystemOut.printDate(out, "- current size	[" + size + "]");
   SystemOut.printDate(out, "- max size 	[" + maxSize + "]");
   int len = -1;
   while (count > 100000 || size > maxSize) {
     Resource[] files = filter == null ? dir.listResources() : dir.listResources(filter);
     if (len == files.length) break; // protect from inifinti loop
     len = files.length;
     for (int i = 0; i < files.length; i++) {
       if (res == null || res.lastModified() > files[i].lastModified()) {
         res = files[i];
       }
     }
     if (res != null) {
       size -= res.length();
       try {
         res.remove(true);
         count--;
       } catch (IOException e) {
         SystemOut.printDate(out, "cannot remove resource " + res.getAbsolutePath());
         break;
       }
     }
     res = null;
   }
 }