commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r821294 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/File.java native/os/unix/file.c native/os/win32/file.c
Date Sat, 03 Oct 2009 11:30:06 GMT
Author: mturk
Date: Sat Oct  3 11:30:06 2009
New Revision: 821294

URL: http://svn.apache.org/viewvc?rev=821294&view=rev
Log:
Implement getTempDirectory API

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
    commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=821294&r1=821293&r2=821294&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Sat
Oct  3 11:30:06 2009
@@ -60,6 +60,8 @@
                                         throws IOException, SecurityException;
     private static native String    tmpdir0(String pathname, String prefix)
                                         throws IOException, SecurityException;
+    private static native String    tmpdir1(String srchpath)
+                                        throws SecurityException;
 
     // Cached FileType Enum integer value.
     private int fileType = -1;
@@ -483,6 +485,50 @@
         return new File(dir, FileType.DIR.valueOf());
     }
 
+    private static File tmpDir;
+    /**
+     * Get system temporary directory path.
+     *
+     * @param {@link java.io.File#pathSeparator} delimited list of directories
+     *        to use as temporary directory. Firts one that is accessible will
+     *        be used.
+     * @return Temporary directory {@code File} instance.
+     * @throws SecurityException if Write access to directories listed inside
+     *         {@code searchPath} is denied.
+     */
+    public synchronized static File getTempDirectory(String searchPath)
+        throws SecurityException
+    {
+        String dir = tmpdir1(searchPath);
+        if (dir == null)
+            throw new SecurityException();
+        tmpDir = new File(dir, FileType.DIR.valueOf());
+
+        return tmpDir;
+    }
+
+    /**
+     * Get system temporary directory path.
+     *
+     * @param {@link java.io.File#pathSeparator} delimited list of directories
+     *        to use as temporary directory. Firts one that is accessible will
+     *        be used.
+     * @return Temporary directory {@code File} instance.
+     * @throws SecurityException if Write access to system temporary directory
+     *         is denied.
+     */
+    public  synchronized static File getTempDirectory()
+        throws SecurityException
+    {
+        if (tmpDir == null) {
+            String dir = tmpdir1(null);
+            if (dir == null)
+                throw new SecurityException();
+            tmpDir = new File(dir, FileType.DIR.valueOf());
+        }
+        return tmpDir;
+    }
+
     /**
      * Return target pathname of this abstract {@code File} instance.
      *

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c?rev=821294&r1=821293&r2=821294&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/file.c Sat Oct  3 11:30:06 2009
@@ -471,3 +471,18 @@
         return rv;
     }
 }
+
+ACR_IO_EXPORT_DECLARE(jstring, File, tmpdir1)(ACR_JNISTDARGS, jstring paths)
+{
+    const char *tmpd = NULL;
+
+    UNREFERENCED_O;
+
+    WITH_ZCSTR(paths) {
+        tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2S(paths));
+    } END_WITH_CSTR(paths);
+    if (tmpd)
+        return ACR_NewJavaStringA(_E, tmpd);
+    else
+        return NULL;
+}

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c?rev=821294&r1=821293&r2=821294&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/file.c Sat Oct  3 11:30:06 2009
@@ -903,3 +903,18 @@
         return rv;
     }
 }
+
+ACR_IO_EXPORT_DECLARE(jstring, File, tmpdir1)(ACR_JNISTDARGS, jstring paths)
+{
+    const wchar_t *tmpd = NULL;
+
+    UNREFERENCED_O;
+
+    WITH_ZWSTR(paths) {
+        tmpd = ACR_TempPathGet(INVALID_HANDLE_VALUE, J2W(paths));
+    } END_WITH_WSTR(paths);
+    if (tmpd)
+        return ACR_NewJavaStringW(_E, tmpd);
+    else
+        return NULL;
+}



Mime
View raw message