class AccessLogParser implements LogReader.LogParser {

  LogReader.Log parseLog(String line) throws IOException {
    try {
      // the enhanced log
      Matcher m = regPattern.matcher(line);
      if (m.matches()) {
        LogReader.Log log = new LogReader.Log();
        log.ip = m.group(1);
        log.date = convertDate(m.group(3));
        String request = m.group(4);
        log.returnCode = parse(m.group(5));
        log.sizeBytes = parseLong(m.group(6));
        log.referrer = m.group(7);
        log.client = m.group(8);
        log.msecs = parseLong(m.group(9));

        String[] reqss = request.split(" ");
        if (reqss.length == 3) {
          log.verb = reqss[0].intern();
          log.path = reqss[1];
          log.http = reqss[2].intern();

        } else if (reqss.length == 2) { // no HTTP/1.x
          log.verb = reqss[0].intern();
          log.path = reqss[1];
        }
        return log;

      } else {
        // the non-enhanced log
        m = regPattern2.matcher(line);
        if (m.matches()) {
          LogReader.Log log = new LogReader.Log();
          log.ip = m.group(1);
          log.date = convertDate(m.group(3));
          String request = m.group(4);
          log.returnCode = parse(m.group(5));
          log.sizeBytes = parseLong(m.group(6));

          log.referrer = "-";
          log.client = "-";
          log.msecs = -1;

          String[] reqss = request.split(" ");
          if (reqss.length == 3) {
            log.verb = reqss[0].intern();
            log.path = reqss[1];
            log.http = reqss[2].intern();

          } else if (reqss.length == 2) { // no HTTP/1.x
            log.verb = reqss[0].intern();
            log.path = reqss[1];
          }
          return log;
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
      System.out.println("Cant parse " + line);
    }
    return null;
  }

}