Пример #1
0
 /**
  * 复制文件中的数据至(数据库 || 缓存)
  *
  * @param logFile
  * @throws IOException
  */
 public <R> void copyDataFromLogFile(
     LogFileUtils<T> myChild, File logFile, LogFileCallback<T, R> callback) throws IOException {
   BufferedReader br = null;
   Class<T> clazz = myChild.getMyClass();
   try {
     List<T> logs = new ArrayList<T>();
     br = new BufferedReader(new FileReader(logFile));
     String line = null;
     while ((line = br.readLine()) != null) {
       T log = checkLineAndToBean(line, clazz);
       if (log != null) {
         logs.add(log);
       }
       // 10000条日志进行一次批处理
       if (logs.size() == 10000) {
         R result = callback.callBack(logs);
         //					loginLogDAO.insertList(logs);
         logs.clear();
       }
     }
     // 把最后剩余的日志进行操作
     if (logs.size() != 0) {
       R result = callback.callBack(logs);
       //				loginLogDAO.insertList(logs);
     }
   } finally {
     if (br != null) {
       br.close();
     }
   }
 }
Пример #2
0
 public static void main(String[] args) {
   LogFileUtils<String> lfu = new LogFileUtils<String>() {};
   System.out.println(lfu.getMyClass());
 }