Apache Nutch is an extensible and scalable web crawler
Merged changes from master; improved Javadoc and exception handling
Julien Nioche49d85eac7398
diff --cc conf/nutch-default.xmlindex 8d97dca9d,b20afdfe3..8b24f092a--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@@ -1872,34 -1872,16 +1872,40 @@@ CAUTION: Set the parser.timeout to -1 o<property><name>urlfilter.fast.file</name><value>fast-urlfilter.txt</value>- <description>Name of file on CLASSPATH containing regular expressions- used by urlfilter-fast (FastURLFilter) plugin.</description>+ <description>Name of file containing rules and regular expressions+ used by urlfilter-fast (FastURLFilter) plugin. If the filename+ includes a scheme (for example, hdfs://) it is loaded using the+ Hadoop FileSystem implementation supporting that scheme. If the+ filename does not contain a scheme, the file is loaded from+ CLASSPATH. If indicated by file extension (.gz, .bzip2, .zst),+ the file is decompressed while reading using Hadoop-provided+ compression codecs.</description></property>+<property>+ <name>urlfilter.fast.url.max.length</name>+ <value>-1</value>+ <description>Filters URLs based on their overall length.+ The default value of -1 means that it is deactivated.+ </description>+</property>++<property>+ <name>urlfilter.fast.url.path.max.length</name>+ <value>-1</value>+ <description>Filters URLs based on the length of their path element.+ The default value of -1 means that it is deactivated.+ </description>+</property>++<property>+ <name>urlfilter.fast.url.query.max.length</name>+ <value>-1</value>+ <description>Filters URLs based on the length of their query element.+ The default value of -1 means that it is deactivated.+ </description>+</property>+<property><name>urlfilter.order</name><value></value>diff --cc src/plugin/urlfilter-fast/src/java/org/apache/nutch/urlfilter/fast/FastURLFilter.javaindex ab905c19d,bb4a11b7c..b1e589a0e--- a/src/plugin/urlfilter-fast/src/java/org/apache/nutch/urlfilter/fast/FastURLFilter.java+++ b/src/plugin/urlfilter-fast/src/java/org/apache/nutch/urlfilter/fast/FastURLFilter.java@@@ -89,6 -95,6 +95,9 @@@ import java.util.regex.PatternSyntaxExc** The rules file is defined via the property <code>urlfilter.fast.file</code>,* the default name is <code>fast-urlfilter.txt</code>.++ *++ * In addition, it can filter based on the length of the whole URL, its path element or++ * its query element. See <code>urlfilter.fast.url.*</code> configurations.*/public class FastURLFilter implements URLFilter {@@@ -227,13 -187,24 +236,34 @@@public void reloadRules() throws IOException {String fileRules = conf.get(URLFILTER_FAST_FILE);- try (Reader reader = conf.getConfResourceAsReader(fileRules)) {- reloadRules(reader);-+ InputStream is;++ Path fileRulesPath = new Path(fileRules);+ if (fileRulesPath.toUri().getScheme() != null) {+ FileSystem fs = fileRulesPath.getFileSystem(conf);+ is = fs.open(fileRulesPath);+ } else {+ is = conf.getConfResourceAsInputStream(fileRules);+ }++ CompressionCodec codec = new CompressionCodecFactory(conf)+ .getCodec(fileRulesPath);- if (codec != null) {++ if (codec != null && is != null) {+ is = codec.createInputStream(is);+ }+- reloadRules(new InputStreamReader(is));++ try {++ reloadRules(new InputStreamReader(is));+ } catch (Exception e) {- String message = "Couldn't load the rules from "+fileRules;++ String message = "Couldn't load the rules from " + fileRules;+ LOG.error(message);+ throw new IOException(message);+ }++ finally {++ if (is != null) {++ is.close();++ }++ }}private void reloadRules(Reader rules) throws IOException {