harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r818792 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/File.java main/native/luni/shared/file.c main/native/luni/unix/exports.txt test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java
Date Fri, 25 Sep 2009 09:41:57 GMT
Author: tellison
Date: Fri Sep 25 09:41:57 2009
New Revision: 818792

URL: http://svn.apache.org/viewvc?rev=818792&view=rev
Log:
Part of HARMONY-6341 ([classlib][luni] - implement File.isAbsolute/getAbsolutePath() in java
code)
Apply first patch to implement isAbsolute() in Java code rather than native code.


Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c
    harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java?rev=818792&r1=818791&r2=818792&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/File.java Fri Sep 25
09:41:57 2009
@@ -753,18 +753,31 @@
      * Indicates if this file's pathname is absolute. Whether a pathname is
      * absolute is platform specific. On UNIX, absolute paths must start with
      * the character '/'; on Windows it is absolute if either it starts with
-     * '\', '/', '\\' (to represent a file server), or a letter followed by a
-     * colon.
+     * '\\' (to represent a file server), or a letter followed by a colon.
      * 
      * @return {@code true} if this file's pathname is absolute, {@code false}
      *         otherwise.
      * @see #getPath
      */
     public boolean isAbsolute() {
-        return isAbsoluteImpl(Util.getUTF8Bytes(path));
-    }
+        if (File.separatorChar == '\\') {
+            // for windows
+            if (path.length() > 1 && path.charAt(0) == File.separatorChar
+                    && path.charAt(1) == File.separatorChar) {
+                return true;
+            }
+            if (path.length() > 2) {
+                if (Character.isLetter(path.charAt(0)) && path.charAt(1) == ':'
+                        && (path.charAt(2) == '/' || path.charAt(2) == '\\')) {
+                    return true;
+                }
+            }
+            return false;
+        }
 
-    private native boolean isAbsoluteImpl(byte[] filePath);
+        // for Linux
+        return (path.length() > 0 && path.charAt(0) == File.separatorChar);
+    }
 
     /**
      * Indicates if this file represents a <em>directory</em> on the
@@ -1311,8 +1324,9 @@
         if (properPath != null) {
             return properPath;
         }
-        byte[] pathBytes = Util.getUTF8Bytes(path);
-        if (isAbsoluteImpl(pathBytes)) {
+
+        if (isAbsolute()) {
+            byte[] pathBytes = Util.getUTF8Bytes(path);
             return properPath = pathBytes;
         }
         // Check security by getting user.dir when the path is not absolute

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c?rev=818792&r1=818791&r2=818792&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/shared/file.c Fri Sep
25 09:41:57 2009
@@ -252,36 +252,6 @@
 }
 
 JNIEXPORT jboolean JNICALL
-Java_java_io_File_isAbsoluteImpl (JNIEnv * env, jobject recv, jbyteArray path)
-{
-  I_32 result = 0;
-  jsize length = (*env)->GetArrayLength (env, path);
-  jbyte *lpath = (jbyte *) ((*env)->GetPrimitiveArrayCritical (env, path, 0));
-
-  if (jclSeparator == '/' && length > 0)
-    {
-      result = (lpath[0] == jclSeparator);
-      goto release;
-    }
-  if (length > 1 && lpath[0] == '\\' && lpath[1] == '\\')
-    {
-      result = 1;
-      goto release;
-    }
-  if (length > 2)
-    {
-      if (isalpha (lpath[0]) && lpath[1] == ':'
-          && (lpath[2] == '\\' || lpath[2] == '/'))
-        result = 1;
-    }
-
-release:
-  /* Easier to release in one area than copy the code around */
-  (*env)->ReleasePrimitiveArrayCritical (env, path, lpath, JNI_ABORT);
-  return result;
-}
-
-JNIEXPORT jboolean JNICALL
 Java_java_io_File_mkdirImpl (JNIEnv * env, jobject recv, jbyteArray path)
 {
   PORT_ACCESS_FROM_ENV (env);

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt?rev=818792&r1=818791&r2=818792&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/unix/exports.txt Fri
Sep 25 09:41:57 2009
@@ -25,7 +25,6 @@
 Java_java_io_File_existsImpl
 Java_java_io_File_getCanonImpl
 Java_java_io_File_getLinkImpl
-Java_java_io_File_isAbsoluteImpl
 Java_java_io_File_isCaseSensitiveImpl
 Java_java_io_File_isDirectoryImpl
 Java_java_io_File_isFileImpl

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java?rev=818792&r1=818791&r2=818792&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/io/FileTest.java
Fri Sep 25 09:41:57 2009
@@ -1073,11 +1073,29 @@
             assertTrue("Absolute returned false", (f.isAbsolute() && !f1
                     .isAbsolute())
                     || (!f.isAbsolute() && f1.isAbsolute()));
+
+            assertTrue(new File("C:/").isAbsolute());
+            assertTrue(new File("f:/").isAbsolute());
+            assertTrue(new File("f:\\").isAbsolute());
+            assertFalse(new File("f:").isAbsolute());
+            assertFalse(new File("K:").isAbsolute());
+            assertTrue(new File("\\\\").isAbsolute());
+            assertTrue(new File("\\\\\\").isAbsolute());
+            assertTrue(new File("\\\\hello").isAbsolute());
+            assertFalse(new File("\\").isAbsolute());
+            assertFalse(new File("/").isAbsolute());
         } else {
             File f = new File("/test");
             File f1 = new File("\\test");
             assertTrue("Absolute returned false", f.isAbsolute());
             assertFalse("Absolute returned true", f1.isAbsolute());
+            assertTrue(new File("//test").isAbsolute());
+            assertFalse(new File("test").isAbsolute());
+            assertFalse(new File("c:/").isAbsolute());
+            assertFalse(new File("c:\\").isAbsolute());
+            assertFalse(new File("c:").isAbsolute());
+            assertFalse(new File("\\").isAbsolute());
+            assertFalse(new File("\\\\").isAbsolute());
         }
         assertTrue("Non-Absolute returned true", !new File("../test")
                 .isAbsolute());



Mime
View raw message