org.apache.nutch.util
Class NutchConf

java.lang.Object
  extended byorg.apache.nutch.util.NutchConf
Direct Known Subclasses:
JobConf

public class NutchConf
extends Object

Provides access to Nutch configuration parameters.

Default values for all parameters are specified in a file named nutch-default.xml located on the classpath. Overrides for these defaults should be in an optional file named nutch-site.xml, also located on the classpath. Typically these files reside in the conf/ subdirectory at the top-level of a Nutch installation.


Constructor Summary
NutchConf()
          A new configuration.
 
Method Summary
 void addConfResource(File file)
          Adds a file to the chain of resources read.
 void addConfResource(String name)
          Adds a resource name to the chain of resources read.
static NutchConf get()
          Return the default configuration.
 String get(String name)
          Returns the value of the name property, or null if no such property exists.
 String get(String name, String defaultValue)
          Returns the value of the name property.
 boolean getBoolean(String name, boolean defaultValue)
          Returns the value of the name property as an boolean.
 Class getClass(String name, Class defaultValue)
          Returns the value of the name property as a Class.
 Class getClass(String propertyName, Class defaultValue, Class xface)
          Returns the value of the name property as a Class.
 InputStream getConfResourceAsInputStream(String name)
          Returns an input stream attached to the configuration resource with the given name.
 Reader getConfResourceAsReader(String name)
          Returns a reader attached to the configuration resource with the given name.
 float getFloat(String name, float defaultValue)
          Returns the value of the name property as a float.
 int getInt(String name, int defaultValue)
          Returns the value of the name property as an integer.
 long getLong(String name, long defaultValue)
          Returns the value of the name property as a long.
 URL getResource(String name)
          Returns the URL for the named resource.
 String[] getStrings(String name)
          Returns the value of the name property as an array of strings.
static void main(String[] args)
          For debugging.
 void set(String name, Object value)
          Sets the value of the name property.
 void setClass(String propertyName, Class theClass, Class xface)
          Sets the value of the name property to the name of a class.
 void setInt(String name, int value)
          Sets the value of the name property to an integer.
 void write(OutputStream out)
          Writes non-default properties in this configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NutchConf

public NutchConf()
A new configuration.

Method Detail

get

public static NutchConf get()
Return the default configuration.


addConfResource

public void addConfResource(String name)
Adds a resource name to the chain of resources read. Such resources are located on the CLASSPATH. The first resource is always nutch-default.xml, and the last is always nutch-site.xml. New resources are inserted between these, so they can override defaults, but not site-specifics.


addConfResource

public void addConfResource(File file)
Adds a file to the chain of resources read. The first resource is always nutch-default.xml, and the last is always nutch-site.xml. New resources are inserted between these, so they can override defaults, but not site-specifics.


get

public String get(String name)
Returns the value of the name property, or null if no such property exists.


set

public void set(String name,
                Object value)
Sets the value of the name property.


get

public String get(String name,
                  String defaultValue)
Returns the value of the name property. If no such property exists, then defaultValue is returned.


getInt

public int getInt(String name,
                  int defaultValue)
Returns the value of the name property as an integer. If no such property is specified, or if the specified value is not a valid integer, then defaultValue is returned.


setInt

public void setInt(String name,
                   int value)
Sets the value of the name property to an integer.


getLong

public long getLong(String name,
                    long defaultValue)
Returns the value of the name property as a long. If no such property is specified, or if the specified value is not a valid long, then defaultValue is returned.


getFloat

public float getFloat(String name,
                      float defaultValue)
Returns the value of the name property as a float. If no such property is specified, or if the specified value is not a valid float, then defaultValue is returned.


getBoolean

public boolean getBoolean(String name,
                          boolean defaultValue)
Returns the value of the name property as an boolean. If no such property is specified, or if the specified value is not a valid boolean, then defaultValue is returned. Valid boolean values are "true" and "false".


getStrings

public String[] getStrings(String name)
Returns the value of the name property as an array of strings. If no such property is specified, then null is returned. Values are whitespace or comma delimted.


getClass

public Class getClass(String name,
                      Class defaultValue)
Returns the value of the name property as a Class. If no such property is specified, then defaultValue is returned.


getClass

public Class getClass(String propertyName,
                      Class defaultValue,
                      Class xface)
Returns the value of the name property as a Class. If no such property is specified, then defaultValue is returned. An error is thrown if the returned class does not implement the named interface.


setClass

public void setClass(String propertyName,
                     Class theClass,
                     Class xface)
Sets the value of the name property to the name of a class. First checks that the class implements the named interface.


getResource

public URL getResource(String name)
Returns the URL for the named resource.


getConfResourceAsInputStream

public InputStream getConfResourceAsInputStream(String name)
Returns an input stream attached to the configuration resource with the given name.


getConfResourceAsReader

public Reader getConfResourceAsReader(String name)
Returns a reader attached to the configuration resource with the given name.


write

public void write(OutputStream out)
           throws IOException
Writes non-default properties in this configuration.

Throws:
IOException

main

public static void main(String[] args)
                 throws Exception
For debugging. List non-default properties to the terminal and exit.

Throws:
Exception


Copyright © 2006 The Apache Software Foundation