Parcourir la source

PathHelper#getClassDir - wywalono
ClassInspector #getLocation, #getFQLocation - poprawiono, zwracał URL

Ranides Atterwim il y a 13 ans
Parent
commit
d31f696178

+ 6 - 2
src/main/java/net/ranides/assira/io/FileHelper.java

@@ -261,7 +261,7 @@ public final class FileHelper {
      * @throws IOException
      */
     public static File createTempFile(String prefix, String suffix, Class<?> clazz) throws IOException {
-        final String dir = PathHelper.getClassDir(clazz);
+        final String dir = getClassDir(clazz);
         final File file = Li.location(dir);
         if(!file.exists() && !file.mkdirs()) {
             throw new IOException("can't create directory: " + file);
@@ -284,7 +284,7 @@ public final class FileHelper {
      * @throws IOException
      */
     public static File createTempFile(String suffix, Class<?> clazz) throws IOException {
-        final String dir = PathHelper.getClassDir(clazz);
+        final String dir = getClassDir(clazz);
         final File file = Li.location(dir);
         if(!file.exists() && !file.mkdirs()) {
             throw new IOException("can't create directory: " + file);
@@ -299,4 +299,8 @@ public final class FileHelper {
         return result;
     }
 
+    private static String getClassDir(Class<?> clazz) {
+        return clazz.getPackage().getName().replace(".", File.separator);
+    }
+    
 }

+ 0 - 11
src/main/java/net/ranides/assira/io/PathHelper.java

@@ -286,17 +286,6 @@ public final class PathHelper {
         }
     }
 
-    /**
-     * Zwraca ścieżkę względną, w jakiej umieszczona zostałaby podana klasa - 
-     * tworzy listę wszystkich katalogów pośrednich na podstawie pakietu, w którym
-     * klasa jest zadeklarowana.
-     * @param clazz
-     * @return
-     */
-    public static String getClassDir(Class<?> clazz) {
-        return clazz.getPackage().getName().replace(".", File.separator);
-    }
-    
     /**
      * Usuwa z podanej pełnej <b>nazwy</b> pliku rozszerzenie, zwracając nazwę
      * przyjazną dla użytkownika.

+ 2 - 2
src/main/java/net/ranides/assira/reflection/ClassInspector.java

@@ -742,7 +742,7 @@ public final class ClassInspector {
      * @return
      */
     public static String getLocation(Class<?> clazz) {
-        return clazz.getProtectionDomain().getCodeSource().getLocation().toString();
+        return clazz.getProtectionDomain().getCodeSource().getLocation().getFile();
     }
     
     /**
@@ -753,7 +753,7 @@ public final class ClassInspector {
      * @return 
      */
     public static String getFQLocation(Class<?> clazz) {
-        return clazz.getClassLoader().getResource( clazz.getName().replace('.', '/') + ".class" ).toString();
+        return clazz.getClassLoader().getResource( clazz.getName().replace('.', '/') + ".class" ).getFile();
     }
 
     /**