You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/08 03:12:22 UTC

[7/9] git commit: Add FileUtils method and deprecation.

Add FileUtils method and deprecation.

  - A couple methods from here will be replaced by the Resource framework.


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/d5489672
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/d5489672
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/d5489672

Branch: refs/heads/LOG4J2-814
Commit: d548967289cecb1bc09d0d7d4cbd5209ae7a1760
Parents: e6b33fc
Author: Matt Sicker <ma...@apache.org>
Authored: Sun Sep 7 19:54:18 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Sun Sep 7 19:54:18 2014 -0500

----------------------------------------------------------------------
 .../apache/logging/log4j/core/util/FileUtils.java   | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/d5489672/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java
index 44e2859..bba8951 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/FileUtils.java
@@ -45,13 +45,14 @@ public final class FileUtils {
     private FileUtils() {
     }
 
-      /**
+    /**
      * Tries to convert the specified URL to a file object. If this fails,
      * <b>null</b> is returned.
      *
      * @param uri the URI
      * @return the resulting file object
      */
+    @Deprecated
     public static File fileFromUri(URI uri) {
         if (uri == null || (uri.getScheme() != null &&
             (!PROTOCOL_FILE.equals(uri.getScheme()) && !JBOSS_FILE.equals(uri.getScheme())))) {
@@ -79,6 +80,7 @@ public final class FileUtils {
         return null;
     }
 
+    @Deprecated
     public static boolean isFile(final URL url) {
         return url != null && (url.getProtocol().equals(PROTOCOL_FILE) || url.getProtocol().equals(JBOSS_FILE));
     }
@@ -105,6 +107,16 @@ public final class FileUtils {
     }
 
     /**
+     * Cleans a {@link File} pathname by replacing Windows backslash directory separators with forward slashes.
+     *
+     * @param pathname the file pathname to clean
+     * @return the cleaned pathname
+     */
+    public static String cleanFilePath(final String pathname) {
+        return WINDOWS_DIRECTORY_SEPARATOR.matcher(pathname).replaceAll("/");
+    }
+
+    /**
      * Takes a given URI string which may contain backslashes (illegal in URIs) in it due to user input or variable
      * substitution and returns a URI with the backslashes replaced with forward slashes.
      *
@@ -113,6 +125,6 @@ public final class FileUtils {
      * @throws URISyntaxException if instantiating the URI threw a {@code URISyntaxException}.
      */
     public static URI getCorrectedFilePathUri(final String uri) throws URISyntaxException {
-        return new URI(WINDOWS_DIRECTORY_SEPARATOR.matcher(uri).replaceAll("/"));
+        return new URI(cleanFilePath(uri));
     }
 }