Author: niallp
Date: Thu Aug  5 01:00:36 2010
New Revision: 982449

URL: http://svn.apache.org/viewvc?rev=982449&view=rev
Log:
IO-234 Add Methods For Retrieving System Directories/Paths to FileUtils - 
thanks to Michael Wooten for the patch

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
    
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java?rev=982449&r1=982448&r2=982449&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java 
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java Thu 
Aug  5 01:00:36 2010
@@ -114,6 +114,51 @@ public class FileUtils {
 
     //-----------------------------------------------------------------------
     /**
+     * Returns the path to the system temporary directory.
+     * 
+     * @return the path to the system temporary directory.
+     * 
+     * @since Commons IO 2.0
+     */
+    public static String getTempDirectoryPath() {
+        return System.getProperty("java.io.tmpdir");
+    }
+    
+    /**
+     * Returns a {...@link File} representing the system temporary directory.
+     * 
+     * @return the system temporary directory. 
+     * 
+     * @since Commons IO 2.0
+     */
+    public static File getTempDirectory() {
+        return new File(getTempDirectoryPath());
+    }
+    
+    /**
+     * Returns the path to the user's home directory.
+     * 
+     * @return the path to the user's home directory.
+     * 
+     * @since Commons IO 2.0
+     */
+    public static String getUserDirectoryPath() {
+        return System.getProperty("user.home");
+    }
+    
+    /**
+     * Returns a {...@link File} representing the user's home directory.
+     * 
+     * @return the user's home directory.
+     * 
+     * @since Commons IO 2.0
+     */
+    public static File getUserDirectory() {
+        return new File(getUserDirectoryPath());
+    }
+    
+    //-----------------------------------------------------------------------
+    /**
      * Opens a {...@link FileInputStream} for the specified file, providing 
better
      * error messages than simply calling <code>new 
FileInputStream(file)</code>.
      * <p>

Modified: 
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java?rev=982449&r1=982448&r2=982449&view=diff
==============================================================================
--- 
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java 
(original)
+++ 
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java 
Thu Aug  5 01:00:36 2010
@@ -101,6 +101,39 @@ public class FileUtilsTestCase extends F
     }
 
     //-----------------------------------------------------------------------
+    /**
+     * Tests the {...@link FileUtils#getTempDirectoryPath()} method.
+     */
+    public void testGetTempDirectoryPath() {
+        assertEquals(System.getProperty("java.io.tmpdir"), 
+            FileUtils.getTempDirectoryPath());
+    }
+    
+    /**
+     * Tests the {...@link FileUtils#getTempDirectory()} method.
+     */
+    public void testGetTempDirectory() {
+        File tempDirectory = new File(System.getProperty("java.io.tmpdir"));
+        assertEquals(tempDirectory, FileUtils.getTempDirectory());
+    }
+    
+    /**
+     * Tests the {...@link FileUtils#getUserDirectoryPath()} method.
+     */
+    public void testGetUserDirectoryPath() {
+        assertEquals(System.getProperty("user.home"), 
+            FileUtils.getUserDirectoryPath());
+    }
+    
+    /**
+     * Tests the {...@link FileUtils#getUserDirectory()} method.
+     */
+    public void testGetUserDirectory() {
+        File userDirectory = new File(System.getProperty("user.home"));
+        assertEquals(userDirectory, FileUtils.getUserDirectory());
+    }
+    
+    //-----------------------------------------------------------------------
     public void test_openInputStream_exists() throws Exception {
         File file = new File(getTestDirectory(), "test.txt");
         createLineBasedFile(file, new String[] {"Hello"});


Reply via email to