Class ConfigurationSource


  • public class ConfigurationSource
    extends java.lang.Object
    Represents the source for the logging configuration.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ConfigurationSource​(byte[] data, java.net.URL url, long lastModified)  
        ConfigurationSource​(java.io.InputStream stream)
      Constructs a new ConfigurationSource with the specified input stream.
        ConfigurationSource​(java.io.InputStream stream, java.io.File file)
      Constructs a new ConfigurationSource with the specified input stream that originated from the specified file.
        ConfigurationSource​(java.io.InputStream stream, java.net.URL url)
      Constructs a new ConfigurationSource with the specified input stream that originated from the specified URL.
        ConfigurationSource​(java.io.InputStream stream, java.net.URL url, long lastModified)
      Constructs a new ConfigurationSource with the specified input stream that originated from the specified URL.
        ConfigurationSource​(java.io.InputStream stream, java.nio.file.Path path)
      Constructs a new ConfigurationSource with the specified input stream that originated from the specified path.
        ConfigurationSource​(Source source, byte[] data, long lastModified)
      Constructs a new ConfigurationSource with the specified source.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static ConfigurationSource fromResource​(java.lang.String resource, java.lang.ClassLoader loader)
      Retrieves the configuration via the ClassLoader.
      static ConfigurationSource fromUri​(java.net.URI configLocation)
      Loads the configuration from a URI.
      private static ConfigurationSource getConfigurationSource​(java.net.URL url)  
      java.io.File getFile()
      Returns the file configuration source, or null if this configuration source is based on an URL or has neither a file nor an URL.
      java.io.InputStream getInputStream()
      Returns the input stream that this configuration source was constructed with.
      long getLastModified()
      Returns the last modification time known when the ConfigurationSource was created.
      java.lang.String getLocation()
      Returns a string describing the configuration source file or URL, or null if this configuration source has neither a file nor an URL.
      java.net.URI getURI()
      Returns a URI representing the configuration resource or null if it cannot be determined.
      java.net.URL getURL()
      Returns the configuration source URL, or null if this configuration source is based on a file or has neither a file nor an URL.
      private boolean isLocation()  
      ConfigurationSource resetInputStream()
      Returns a new ConfigurationSource whose input stream is reset to the beginning.
      void setData​(byte[] data)  
      void setModifiedMillis​(long currentLastModified)
      Updates the last known modification time of the resource.
      void setSource​(Source ignored)
      Deprecated.
      Not used internally, no replacement.
      private static byte[] toByteArray​(java.io.InputStream inputStream)
      Returns the contents of the specified InputStream as a byte array.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final Logger LOGGER
      • NULL_SOURCE

        public static final ConfigurationSource NULL_SOURCE
        ConfigurationSource to use with Configurations that do not require a "real" configuration source.
      • stream

        private final java.io.InputStream stream
      • data

        private volatile byte[] data
      • source

        private final Source source
      • initialLastModified

        private final long initialLastModified
      • currentLastModified

        private volatile long currentLastModified
    • Constructor Detail

      • ConfigurationSource

        public ConfigurationSource​(java.io.InputStream stream,
                                   java.io.File file)
        Constructs a new ConfigurationSource with the specified input stream that originated from the specified file.
        Parameters:
        stream - the input stream, the caller is responsible for closing this resource.
        file - the file where the input stream originated
      • ConfigurationSource

        public ConfigurationSource​(java.io.InputStream stream,
                                   java.nio.file.Path path)
        Constructs a new ConfigurationSource with the specified input stream that originated from the specified path.
        Parameters:
        stream - the input stream, the caller is responsible for closing this resource.
        path - the path where the input stream originated.
      • ConfigurationSource

        public ConfigurationSource​(java.io.InputStream stream,
                                   java.net.URL url)
        Constructs a new ConfigurationSource with the specified input stream that originated from the specified URL.
        Parameters:
        stream - the input stream, the caller is responsible for closing this resource.
        url - the URL where the input stream originated
      • ConfigurationSource

        public ConfigurationSource​(java.io.InputStream stream,
                                   java.net.URL url,
                                   long lastModified)
        Constructs a new ConfigurationSource with the specified input stream that originated from the specified URL.
        Parameters:
        stream - the input stream, the caller is responsible for closing this resource.
        url - the URL where the input stream originated
        lastModified - when the source was last modified.
      • ConfigurationSource

        public ConfigurationSource​(java.io.InputStream stream)
                            throws java.io.IOException
        Constructs a new ConfigurationSource with the specified input stream. Since the stream is the only source of data, this constructor makes a copy of the stream contents.
        Parameters:
        stream - the input stream, the caller is responsible for closing this resource.
        Throws:
        java.io.IOException - if an exception occurred reading from the specified stream
      • ConfigurationSource

        public ConfigurationSource​(Source source,
                                   byte[] data,
                                   long lastModified)
        Constructs a new ConfigurationSource with the specified source.
        Parameters:
        source - a Source.
        data - data from the source
        lastModified - when the source was last modified.
      • ConfigurationSource

        private ConfigurationSource​(byte[] data,
                                    java.net.URL url,
                                    long lastModified)
    • Method Detail

      • toByteArray

        private static byte[] toByteArray​(java.io.InputStream inputStream)
                                   throws java.io.IOException
        Returns the contents of the specified InputStream as a byte array.
        Parameters:
        inputStream - the stream to read
        Returns:
        the contents of the specified stream
        Throws:
        java.io.IOException - if a problem occurred reading from the stream
      • getFile

        public java.io.File getFile()
        Returns the file configuration source, or null if this configuration source is based on an URL or has neither a file nor an URL.
        Returns:
        the configuration source file, or null
      • isLocation

        private boolean isLocation()
      • getURL

        public java.net.URL getURL()
        Returns the configuration source URL, or null if this configuration source is based on a file or has neither a file nor an URL.
        Returns:
        the configuration source URL, or null
      • setSource

        @Deprecated
        public void setSource​(Source ignored)
        Deprecated.
        Not used internally, no replacement.
      • setData

        public void setData​(byte[] data)
      • setModifiedMillis

        public void setModifiedMillis​(long currentLastModified)
        Updates the last known modification time of the resource.
        Parameters:
        currentLastModified - The modification time of the resource in millis.
      • getURI

        public java.net.URI getURI()
        Returns a URI representing the configuration resource or null if it cannot be determined.
        Returns:
        The URI.
      • getLastModified

        public long getLastModified()
        Returns the last modification time known when the ConfigurationSource was created.
        Returns:
        the last modified time of the resource.
      • getLocation

        public java.lang.String getLocation()
        Returns a string describing the configuration source file or URL, or null if this configuration source has neither a file nor an URL.
        Returns:
        a string describing the configuration source file or URL, or null
      • getInputStream

        public java.io.InputStream getInputStream()
        Returns the input stream that this configuration source was constructed with.
        Returns:
        the input stream that this configuration source was constructed with.
      • resetInputStream

        public ConfigurationSource resetInputStream()
                                             throws java.io.IOException
        Returns a new ConfigurationSource whose input stream is reset to the beginning.
        Returns:
        a new ConfigurationSource
        Throws:
        java.io.IOException - if a problem occurred while opening the new input stream
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • fromUri

        public static ConfigurationSource fromUri​(java.net.URI configLocation)
        Loads the configuration from a URI.
        Parameters:
        configLocation - A URI representing the location of the configuration.
        Returns:
        The ConfigurationSource for the configuration or null.
      • fromResource

        public static ConfigurationSource fromResource​(java.lang.String resource,
                                                       java.lang.ClassLoader loader)
        Retrieves the configuration via the ClassLoader.
        Parameters:
        resource - The resource to load.
        loader - The default ClassLoader to use.
        Returns:
        The ConfigurationSource for the configuration.
      • getConfigurationSource

        private static ConfigurationSource getConfigurationSource​(java.net.URL url)