/** * parses a log entry line in default combined format (see <a * href="http://wiki.nginx.org/NginxHttpLogModule#log_format" >HttpLogModule#log_format</a>) * * @param line single log entry line in combined format * @return true if entry matched expected format */ public boolean populate(String line) { _line = line; _date.clear(); _requestLine.clear(); _previous = null; _field = 0; char[] chars = new char[line.length()]; line.getChars(0, line.length(), chars, 0); int last = -1; FieldState state = FieldState.NONE; for (int i = 0; i < chars.length; i++) { char c = chars[i]; switch (state) { case NONE: switch (c) { case ' ': // set(""); last = i; break; case '"': // new quoted field; state = FieldState.QUOTES; break; case '[': state = FieldState.BRACKETS; break; default: state = FieldState.NORMAL; } break; case NORMAL: if (c == ' ') { // end of field set(line.substring(last + 1, i)); last = i; state = FieldState.NONE; } break; case BRACKETS: if (c == ']' && (chars.length == i + 1 || chars[i + 1] == ' ')) { state = FieldState.NORMAL; } break; case QUOTES: if (c == '"' && (chars.length == i + 1 || chars[i + 1] == ' ')) { state = FieldState.NORMAL; } break; default: throw new IllegalStateException("" + state); } } if (last + 1 < line.length()) { set(line.substring(last + 1)); } return _field == 9 && _status > 0 && _length >= 0; }