/* * Copyright (C) 2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * * StatoolInfos is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * StatoolInfos is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with StatoolInfos. If not, see . */ package fr.devinsy.statoolinfos.metrics.http; import java.io.File; import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import fr.devinsy.statoolinfos.util.LineIterator; /** * The Class HttpLogIterator. */ public class HttpLogIterator { private static Logger logger = LoggerFactory.getLogger(HttpLogIterator.class); public static final String DEFAULT_CHARSET_NAME = "UTF-8"; private long errorCount; private LineIterator iterator; /** * Instantiates a new http log iterator. * * @param source * the source * @throws IOException * Signals that an I/O exception has occurred. */ public HttpLogIterator(final File source) throws IOException { this.errorCount = 0; this.iterator = new LineIterator(source); } /** * Close. */ public void close() { this.iterator.close(); } /** * Gets the error count. * * @return the error count */ public long getErrorCount() { return this.errorCount; } /** * Checks for next. * * @return true, if successful * @throws IOException */ public boolean hasNext() throws IOException { boolean result; result = this.iterator.hasNext(); // return result; } /** * Next. * * @return the http log * @throws IOException */ public HttpLog next() throws IOException { HttpLog result; try { String line = this.iterator.next(); result = HttpAccessLogAnalyzer.parseNginxCombinedLog(line); } catch (Exception exception) { exception.printStackTrace(); this.errorCount += 1; if (this.iterator.hasNext()) { result = next(); } else { result = null; } } // return result; } }