From f1074afe9597ca242805197cc347a2d9ee2813cc Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Thu, 18 Jul 2024 19:24:02 +0200 Subject: [PATCH] Clean metrics.httpaccess package. --- .../metrics/httpaccess/HttpLogIterator.java | 119 ------------------ .../metrics/httpaccess/NGinxLogAnalyzer.java | 37 ------ .../devinsy/statoolinfos/util/FilesLines.java | 66 ++++++++++ 3 files changed, 66 insertions(+), 156 deletions(-) delete mode 100644 src/fr/devinsy/statoolinfos/metrics/httpaccess/HttpLogIterator.java delete mode 100644 src/fr/devinsy/statoolinfos/metrics/httpaccess/NGinxLogAnalyzer.java create mode 100644 src/fr/devinsy/statoolinfos/util/FilesLines.java diff --git a/src/fr/devinsy/statoolinfos/metrics/httpaccess/HttpLogIterator.java b/src/fr/devinsy/statoolinfos/metrics/httpaccess/HttpLogIterator.java deleted file mode 100644 index 55b6b0d..0000000 --- a/src/fr/devinsy/statoolinfos/metrics/httpaccess/HttpLogIterator.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2021-2023 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); - - 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 HttpAccessLog next() throws IOException - { - HttpAccessLog result; - - try - { - String line = this.iterator.next(); - result = HttpAccessLogParser.parseLog(line, HttpAccessLogParser.COMBINED_PATTERN, HttpAccessLogParser.DATETIME_FORMATTER); - } - catch (Exception exception) - { - exception.printStackTrace(); - this.errorCount += 1; - if (this.iterator.hasNext()) - { - result = next(); - } - else - { - result = null; - } - } - - // - return result; - } -} diff --git a/src/fr/devinsy/statoolinfos/metrics/httpaccess/NGinxLogAnalyzer.java b/src/fr/devinsy/statoolinfos/metrics/httpaccess/NGinxLogAnalyzer.java deleted file mode 100644 index 1f18ad1..0000000 --- a/src/fr/devinsy/statoolinfos/metrics/httpaccess/NGinxLogAnalyzer.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The Class NGinxLogAnalyzer. - */ -public class NGinxLogAnalyzer -{ - private static Logger logger = LoggerFactory.getLogger(NGinxLogAnalyzer.class); - - /** - * Instantiates a new n ginx log analyzer. - */ - private NGinxLogAnalyzer() - { - } -} diff --git a/src/fr/devinsy/statoolinfos/util/FilesLines.java b/src/fr/devinsy/statoolinfos/util/FilesLines.java new file mode 100644 index 0000000..4e46643 --- /dev/null +++ b/src/fr/devinsy/statoolinfos/util/FilesLines.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2022-2024 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.util; + +import java.io.File; +import java.util.Iterator; + +/** + * The Class FilesLines. + */ +public class FilesLines implements Iterable +{ + private Files source; + + /** + * Instantiates a new file lines. + * + * @param source + * the source + */ + public FilesLines(final File source) + { + this(new Files(source)); + } + + /** + * Instantiates a new files lines. + * + * @param source + * the source + */ + public FilesLines(final Files source) + { + this.source = source; + } + + /* (non-Javadoc) + * @see java.lang.Iterable#iterator() + */ + @Override + public Iterator iterator() + { + Iterator result; + + result = new FilesLineIterator(this.source); + + // + return result; + } +}