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); } }
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); } }
private static void write(List<String> list, EventLoader event_loader) { PrintWriter out = null; try { out = event_loader.response().getWriter(); Iterator<String> itr = list.iterator(); for (; itr.hasNext(); ) { out.write(itr.next()); } out.flush(); } catch (Exception e) { event_loader.log.error( "Response output stream exception in " + event_loader.request_path(), e); } finally { if (out != null) out.close(); } }