@Test public void testStuff() throws IOException { AccessLogParser p = new AccessLogParser(); String line = "24.18.236.132 - - [04/Feb/2011:17:49:03 -0700] \"GET /thredds/fileServer Matcher m = AccessLogParser.regPattern.matcher(line); System.out.printf("%s %s%n", m.matches(), m); for (int i = 0; i < m.groupCount(); i++) { System.out.println(" " + i + " " + m.group(i)); } LogReader.Log log = p.parseLog(line); System.out.printf("%s%n", log); }
LogReader.Log parseLog(String line) throws IOException { try { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } else { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } } } catch (Exception e) { e.printStackTrace(); System.out.println("Cant parse " + line); } return null; }
AccessLogParser implements LogReader.LogParser { LogReader.Log parseLog(String line) throws IOException { try { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } else { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } } } catch (Exception e) { e.printStackTrace(); System.out.println("Cant parse " + line); } return null; } }
AccessLogParser implements LogReader.LogParser { LogReader.Log parseLog(String line) throws IOException { try { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } else { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } } } catch (Exception e) { e.printStackTrace(); System.out.println("Cant parse " + line); } return null; }  }
AccessLogParser implements LogReader.LogParser { LogReader.Log parseLog(String line) throws IOException { try { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } else { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } } } catch (Exception e) { e.printStackTrace(); System.out.println("Cant parse " + line); } return null; }  LogReader.Log nextLog(BufferedReader dataIS); }
AccessLogParser implements LogReader.LogParser { LogReader.Log parseLog(String line) throws IOException { try { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } else { 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) { log.verb = reqss[0].intern(); log.path = reqss[1]; } return log; } } } catch (Exception e) { e.printStackTrace(); System.out.println("Cant parse " + line); } return null; }  LogReader.Log nextLog(BufferedReader dataIS);  }