You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2022/01/19 23:05:14 UTC

[logging-log4j2] 01/03: Add ConfigurationSource.ConfigurationSource(InputStream, Path).

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 83b3468d16217700b52715c52c8e92607a5120b9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jan 19 18:01:40 2022 -0500

    Add ConfigurationSource.ConfigurationSource(InputStream, Path).
---
 .../log4j/core/config/ConfigurationSource.java     | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
index be931c5..c1616eb 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationSource.java
@@ -29,6 +29,8 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Objects;
 
 import javax.net.ssl.HttpsURLConnection;
@@ -90,6 +92,26 @@ public class ConfigurationSource {
 
     /**
      * Constructs a new {@code ConfigurationSource} with the specified input stream that originated from the specified
+     * path.
+     *
+     * @param stream the input stream, the caller is responsible for closing this resource.
+     * @param path the path where the input stream originated.
+     */
+    public ConfigurationSource(final InputStream stream, final Path path) {
+        this.stream = Objects.requireNonNull(stream, "stream is null");
+        this.data = null;
+        this.source = new Source(path);
+        long modified = 0;
+        try {
+            modified = Files.getLastModifiedTime(path).toMillis();
+        } catch (Exception ex) {
+            // There is a problem with the file. It will be handled somewhere else.
+        }
+        this.lastModified = modified;
+    }
+
+    /**
+     * Constructs a new {@code ConfigurationSource} with the specified input stream that originated from the specified
      * url.
      *
      * @param stream the input stream, the caller is responsible for closing this resource.