Module jcifs

Class Config

java.lang.Object
org.codelibs.jcifs.smb1.Config

public class Config extends Object
This class uses a static 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.

  • Field Details

    • socketCount

      public static int socketCount
      Counter for tracking socket connections.
    • DEFAULT_OEM_ENCODING

      public static String DEFAULT_OEM_ENCODING
      Default OEM encoding used for SMB communication.
  • Method Details

    • registerSmbURLHandler

      public static void registerSmbURLHandler()
      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.<init>(URL.java:480)
           at java.net.URL.<init>(URL.java:376)
           at java.net.URL.<init>(URL.java:330)
           at org.codelibs.jcifs.smb1.smb1.SmbFile.<init>(SmbFile.java:355)
           ...
       
    • setProperties

      public static void setProperties(Properties prp)
      Set the properties to be used for configuration.
      Parameters:
      prp - the properties to set
    • load

      public static void load(InputStream in) throws IOException
      Load the Config with properties from the stream in from a Properties file.
      Parameters:
      in - the input stream to load properties from
      Throws:
      IOException - if an I/O error occurs
    • store

      public static void store(OutputStream out, String header) throws IOException
      Save the configuration properties to an output stream.
      Parameters:
      out - the output stream to write properties to
      header - a descriptive header for the properties
      Throws:
      IOException - if an I/O error occurs
    • list

      public static void list(PrintStream out) throws IOException
      List the properties in the Config.
      Parameters:
      out - the print stream to write the properties to
      Throws:
      IOException - if an I/O error occurs
    • setProperty

      public static Object setProperty(String key, String value)
      Add a property.
      Parameters:
      key - the property key
      value - the property value
      Returns:
      the previous value of the property, or null if it did not have one
    • get

      public static Object get(String key)
      Retrieve a property as an Object.
      Parameters:
      key - the property key to look up
      Returns:
      the property value as an Object, or null if not found
    • getProperty

      public static String getProperty(String key, String def)
      Retrieve a String. If the key cannot be found, the provided def default parameter will be returned.
      Parameters:
      key - the property key to look up
      def - the default value to return if the property is not found
      Returns:
      the property value, or the default value if not found
    • getProperty

      public static String getProperty(String key)
      Retrieve a String. If the property is not found, null is returned.
      Parameters:
      key - the property key to look up
      Returns:
      the property value, or null if not found
    • getInt

      public static int getInt(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.
      Parameters:
      key - the property key to look up
      def - the default value to return if the property is not found or cannot be parsed
      Returns:
      the property value as an int, or the default value
    • getInt

      public static int getInt(String key)
      Retrieve an int. If the property is not found, -1 is returned.
      Parameters:
      key - the property key to look up
      Returns:
      the property value as an int, or -1 if not found
    • getLong

      public static long getLong(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.
      Parameters:
      key - the property key to look up
      def - the default value to return if the property is not found or cannot be parsed
      Returns:
      the property value as a long, or the default value
    • getInetAddress

      public static InetAddress getInetAddress(String key, InetAddress def)
      Retrieve an InetAddress. If the address is not an IP address and cannot be resolved null will be returned.
      Parameters:
      key - the property key to look up
      def - the default InetAddress to return if the property is not found or cannot be resolved
      Returns:
      the property value as an InetAddress, or the default value
    • getLocalHost

      public static InetAddress getLocalHost()
      Get the local host address configured for the client.
      Returns:
      the configured local InetAddress, or null if not configured
    • getBoolean

      public static boolean getBoolean(String key, boolean def)
      Retrieve a boolean value. If the property is not found, the value of def is returned.
      Parameters:
      key - the property key to look up
      def - the default value to return if the property is not found
      Returns:
      the property value as a boolean, or the default value
    • getInetAddressArray

      public static InetAddress[] getInetAddressArray(String key, String delim, InetAddress[] def)
      Retrieve an array of InetAddress created from a property value containting a delim separated list of hostnames and/or ipaddresses.
      Parameters:
      key - the property key to look up
      delim - the delimiter used to separate addresses in the property value
      def - the default array to return if the property is not found or cannot be parsed
      Returns:
      an array of InetAddress objects, or the default array