[Arakhnę-Dev] [160] Bug fix: FileSystem dirname does not reply current directory.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 160
Author:   galland
Date:     2010-06-15 12:13:44 +0200 (Tue, 15 Jun 2010)
Log Message:
-----------
Bug fix: FileSystem dirname does not reply current directory.

Modified Paths:
--------------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
    trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2010-06-15 09:17:53 UTC (rev 159)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2010-06-15 10:13:44 UTC (rev 160)
@@ -231,9 +231,19 @@
 	 * @see #basename(File)
 	 * @see #extension(File)
 	 */
-	public static File dirname(File filename) {
+	public static URL dirname(File filename) {
 		if (filename==null) return null;
-		return filename.getParentFile();
+		String parent = filename.getParent();
+		try {
+			if (parent==null || "".equals(parent)) { //$NON-NLS-1$
+				if (filename.isAbsolute()) return null;
+				return new URL(URISchemeType.FILE.name(), "", CURRENT_DIRECTORY); //$NON-NLS-1$
+			}
+			return new URL(URISchemeType.FILE.name(), "", parent); //$NON-NLS-1$
+		}
+		catch(MalformedURLException _) {
+			return null;
+		}
 	}
 
 	/** Replies the dirname of the specified file.
@@ -693,6 +703,15 @@
 			return uri.toURL();
 		}
 		catch (Throwable _) {
+			//
+		}
+		try {
+			return new URL(
+					urlBase.getProtocol(), 
+					urlBase.getHost(), 
+					buf.toString());
+		}
+		catch (Throwable _) {
 			return null;
 		}
 	}
@@ -733,6 +752,15 @@
 			return uri.toURL();
 		}
 		catch (Throwable _) {
+			//
+		}
+		try {
+			return new URL(
+					urlBase.getProtocol(), 
+					urlBase.getHost(), 
+					buf.toString());
+		}
+		catch (Throwable _) {
 			return null;
 		}
 	}
@@ -826,6 +854,15 @@
 			return uri.toURL();
 		}
 		catch(Throwable _) {
+			//
+		}
+		try {
+			return new URL(
+					filename.getProtocol(), 
+					filename.getHost(), 
+					buf.toString());
+		}
+		catch(Throwable _) {
 			return null;
 		}
 	}
@@ -891,6 +928,15 @@
 			return uri.toURL();
 		}
 		catch(Throwable _) {
+			//
+		}
+		try {
+			return new URL(
+					filename.getProtocol(), 
+					filename.getHost(), 
+					buf.toString());
+		}
+		catch(Throwable _) {
 			return null;
 		}
 	}

Modified: trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java
===================================================================
--- trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java	2010-06-15 09:17:53 UTC (rev 159)
+++ trunk/arakhneVmutils/java/src/test/java/org/arakhne/vmutil/FileSystemTest.java	2010-06-15 10:13:44 UTC (rev 160)
@@ -170,10 +170,13 @@
 	}
 
 	/**
+	 * @throws Exception
 	 */
-	public void testDirnameFile() {
-		assertEquals(pf1, FileSystem.dirname(f1));
-		assertEquals(pf2, FileSystem.dirname(f2));
+	public void testDirnameFile() throws Exception {
+		assertEquals(new URL("file", "", "/home"),  //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
+				FileSystem.dirname(f1));
+		assertEquals(new URL("file", "", "/"),  //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
+				FileSystem.dirname(f2));
 		assertNull(FileSystem.dirname(new File("/"))); //$NON-NLS-1$
 	}
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/