Exemplo n.º 1
0
 private static void read_file(EventLoader event_loader, String path, boolean need_cache) {
   Pair<Long, List<String>> b = null;
   try {
     b = read(path);
   } catch (FileNotFoundException e) {
     response_not_found(event_loader, path);
     return;
   } catch (IOException e) {
     event_loader.log.error(
         "request:" + event_loader.request_path() + " read failed for read file " + path, e);
     response_not_found(event_loader, path);
     return;
   }
   if (b == null || b.getValue().isEmpty()) {
     response_not_found(event_loader, path);
     return;
   } else {
     if (need_cache && b.getKey() < instance.file_max_size) {
       Resource r = new Resource(b.getValue());
       r.file = new File(path);
       r.last_modify_time = last_modify_time(path);
       file_map.put(MyMath.encryptionWithMD5(path), r);
     }
     write(b.getValue(), event_loader);
   }
 }
Exemplo n.º 2
0
 public static void handle_abs_file(EventLoader event_loader, String path, boolean need_cache) {
   HttpServletResponse response = event_loader.response();
   response.setContentType(ContentType.is(event_loader.postfix()));
   response.setCharacterEncoding(Controller.encode_type);
   if (need_cache) {
     Resource file = file_map.get(MyMath.encryptionWithMD5(path));
     if (file != null) {
       file.use++;
       write(file.list, event_loader);
     } else {
       read_file(event_loader, path, need_cache);
     }
   } else {
     read_file(event_loader, path, need_cache);
   }
 }
Exemplo n.º 3
0
 private static void read_file_in_not_found(EventLoader event_loader, File f) {
   Pair<Long, List<String>> b = null;
   try {
     b = read(f);
   } catch (FileNotFoundException e) {
     event_loader.log.error(
         "request:" + event_loader.request_path() + " read failed for read file " + f.getPath(),
         e);
     try {
       event_loader.text("404 page for default postfix");
     } catch (IOException e1) {
       e1.printStackTrace();
     }
     return;
   } catch (IOException e) {
     event_loader.log.error(
         "request:" + event_loader.request_path() + " read failed for read file " + f.getPath(),
         e);
     try {
       event_loader.text("404 page for default postfix");
     } catch (IOException e1) {
       e1.printStackTrace();
     }
     return;
   }
   if (b == null || b.getValue().isEmpty()) {
     try {
       event_loader.text("404 page for default postfix");
     } catch (IOException e) {
       e.printStackTrace();
     }
     return;
   } else {
     if (b.getKey() < instance.file_max_size) {
       Resource file = new Resource(b.getValue());
       file.file = f;
       file.last_modify_time = last_modify_time(f.getPath());
       file_map.put(MyMath.encryptionWithMD5(f.getPath()), file);
     }
     write(b.getValue(), event_loader);
   }
 }
Exemplo n.º 4
0
 private static void response_not_found(EventLoader event_loader, String path) {
   event_loader.response().setStatus(HttpServletResponse.SC_NOT_FOUND);
   String _404_file =
       event_loader.context.getRealPath("/WEB-INF/lizar/404.") + event_loader.postfix();
   Resource file = file_map.get(MyMath.encryptionWithMD5(_404_file));
   if (file == null) {
     if (StringHelper.isNull(event_loader.postfix())) event_loader.postfix("html");
     File f =
         new File(
             event_loader.context.getRealPath("/WEB-INF/lizar/404.") + event_loader.postfix());
     if (!f.exists()) {
       try {
         FileTool.write_to_file("404 page for default postfix", f);
       } catch (IOException e) {
         event_loader.log.error(path + " read exception.", e);
       }
     }
     read_file_in_not_found(event_loader, f);
   } else write(file.list, event_loader);
 }