FileDocCategorySizeDatePackage
Config.javaAPI DocJCIFS 1.3.17 API11861Tue Oct 18 15:26:24 BST 2011jcifs

Config

public class Config extends Object
This class uses a static {@link java.util.Properties} to act as a cental repository for all jCIFS configuration properties. It cannot be instantiated. Similar to System properties the namespace is global therefore property names should be unique. Before use, the load method should be called with the name of a Properties file (or null indicating no file) to initialize the Config. The System properties will then populate the Config as well potentially overwriting properties from the file. Thus properties provided on the commandline with the -Dproperty.name=value VM parameter will override properties from the configuration file.

There are several ways to set jCIFS properties. See the overview page of the API documentation for details.

Fields Summary
public static int
socketCount
private static Properties
prp
The static Properties.
private static jcifs.util.LogStream
log
public static String
DEFAULT_OEM_ENCODING
Constructors Summary
Config()

Methods Summary
public static java.lang.Objectget(java.lang.String key)
Retrieve a property as an Object.

        return prp.get( key );
    
public static booleangetBoolean(java.lang.String key, boolean def)
Retrieve a boolean value. If the property is not found, the value of def is returned.

        String b = getProperty( key );
        if( b != null ) {
            def = b.toLowerCase().equals( "true" );
        }
        return def;
    
public static java.net.InetAddressgetInetAddress(java.lang.String key, java.net.InetAddress def)
Retrieve an InetAddress. If the address is not an IP address and cannot be resolved null will be returned.

        String addr = prp.getProperty( key );
        if( addr != null ) {
            try {
                def = InetAddress.getByName( addr );
            } catch( UnknownHostException uhe ) {
                if( log.level > 0 ) {
                    log.println( addr );
                    uhe.printStackTrace( log );
                }
            }
        }
        return def;
    
public static java.net.InetAddress[]getInetAddressArray(java.lang.String key, java.lang.String delim, java.net.InetAddress[] def)
Retrieve an array of InetAddress created from a property value containting a delim separated list of hostnames and/or ipaddresses.

        String p = getProperty( key );
        if( p != null ) {
            StringTokenizer tok = new StringTokenizer( p, delim );
            int len = tok.countTokens();
            InetAddress[] arr = new InetAddress[len];
            for( int i = 0; i < len; i++ ) {
                String addr = tok.nextToken();
                try {
                    arr[i] = InetAddress.getByName( addr );
                } catch( UnknownHostException uhe ) {
                    if( log.level > 0 ) {
                        log.println( addr );
                        uhe.printStackTrace( log );
                    }
                    return def;
                }
            }
            return arr;
        }
        return def;
    
public static intgetInt(java.lang.String key, int def)
Retrieve an int. If the key does not exist or cannot be converted to an int, the provided default argument will be returned.

        String s = prp.getProperty( key );
        if( s != null ) {
            try {
                def = Integer.parseInt( s );
            } catch( NumberFormatException nfe ) {
                if( log.level > 0 )
                    nfe.printStackTrace( log );
            }
        }
        return def;
    
public static intgetInt(java.lang.String key)
Retrieve an int. If the property is not found, -1 is returned.

        String s = prp.getProperty( key );
        int result = -1;
        if( s != null ) {
            try {
                result = Integer.parseInt( s );
            } catch( NumberFormatException nfe ) {
                if( log.level > 0 )
                    nfe.printStackTrace( log );
            }
        }
        return result;
    
public static java.net.InetAddressgetLocalHost()

        String addr = prp.getProperty( "jcifs.smb.client.laddr" );

        if (addr != null) {
            try {
                return InetAddress.getByName( addr );
            } catch( UnknownHostException uhe ) {
                if( log.level > 0 ) {
                    log.println( "Ignoring jcifs.smb.client.laddr address: " + addr );
                    uhe.printStackTrace( log );
                }
            }
        }

        return null;
    
public static longgetLong(java.lang.String key, long def)
Retrieve a long. If the key does not exist or cannot be converted to a long, the provided default argument will be returned.

        String s = prp.getProperty( key );
        if( s != null ) {
            try {
                def = Long.parseLong( s );
            } catch( NumberFormatException nfe ) {
                if( log.level > 0 )
                    nfe.printStackTrace( log );
            }
        }
        return def;
    
public static java.lang.StringgetProperty(java.lang.String key)
Retrieve a String. If the property is not found, null is returned.

        return prp.getProperty( key );
    
public static java.lang.StringgetProperty(java.lang.String key, java.lang.String def)
Retrieve a String. If the key cannot be found, the provided def default parameter will be returned.

        return prp.getProperty( key, def );
    
public static voidlist(java.io.PrintStream out)
List the properties in the Code.

        prp.list( out );
    
public static voidload(java.io.InputStream in)
Load the Config with properties from the stream in from a Properties file.

        if( in != null ) {
            prp.load( in );
        }
        try {
            prp.putAll( System.getProperties() );
        } catch( SecurityException se ) {
            if( log.level > 1 )
                log.println( "SecurityException: jcifs will ignore System properties" );
        }
    
public static voidregisterSmbURLHandler()
This static method registers the SMB URL protocol handler which is required to use SMB URLs with the java.net.URL class. If this method is not called before attempting to create an SMB URL with the URL class the following exception will occur:
Exception MalformedURLException: unknown protocol: smb
at java.net.URL.(URL.java:480)
at java.net.URL.(URL.java:376)
at java.net.URL.(URL.java:330)
at jcifs.smb.SmbFile.(SmbFile.java:355)
...


     
        String filename;
        int level;
        FileInputStream in = null;

        log = LogStream.getInstance();

        try {
            filename = System.getProperty( "jcifs.properties" );
            if( filename != null && filename.length() > 1 ) {
                in = new FileInputStream( filename );
            }
            Config.load( in );
            if (in != null)
                in.close();
        } catch( IOException ioe ) {
            if( log.level > 0 )
                ioe.printStackTrace( log );
        }

        if(( level = Config.getInt( "jcifs.util.loglevel", -1 )) != -1 ) {
            LogStream.setLevel( level );
        }

        try {
            "".getBytes(DEFAULT_OEM_ENCODING);
        } catch (UnsupportedEncodingException uee) {
            if (log.level >= 2) {
                log.println("WARNING: The default OEM encoding " + DEFAULT_OEM_ENCODING +
                " does not appear to be supported by this JRE. The default encoding will be US-ASCII.");
            }
            DEFAULT_OEM_ENCODING = "US-ASCII";
        }

        if (log.level >= 4) {
            try {
                prp.store( log, "JCIFS PROPERTIES" );
            } catch( IOException ioe ) {
            }
        }
    
        String ver, pkgs;

        ver = System.getProperty( "java.version" );
        if( ver.startsWith( "1.1." ) || ver.startsWith( "1.2." )) {
             throw new RuntimeException( "jcifs-0.7.0b4+ requires Java 1.3 or above. You are running " + ver );
        }
        pkgs = System.getProperty( "java.protocol.handler.pkgs" );
        if( pkgs == null ) {
            System.setProperty( "java.protocol.handler.pkgs", "jcifs" );
        } else if( pkgs.indexOf( "jcifs" ) == -1 ) {
            pkgs += "|jcifs";
            System.setProperty( "java.protocol.handler.pkgs", pkgs );
        }
    
public static voidsetProperties(java.util.Properties prp)
Set the default properties of the static Properties used by Config. This permits a different Properties object/file to be used as the source of properties for use by the jCIFS library. The Properties must be set before jCIFS classes are accessed as most jCIFS classes load properties statically once. Using this method will also override properties loaded using the -Djcifs.properties= commandline parameter.

        Config.prp = new Properties( prp );
        try {
            Config.prp.putAll( System.getProperties() );
        } catch( SecurityException se ) {
            if( log.level > 1 )
                log.println( "SecurityException: jcifs will ignore System properties" );
        }
    
public static java.lang.ObjectsetProperty(java.lang.String key, java.lang.String value)
Add a property.

        return prp.setProperty( key, value );
    
public static voidstore(java.io.OutputStream out, java.lang.String header)

        prp.store( out, header );