@@ -10,7 +10,7 @@ import java.io.{
10
10
ByteArrayOutputStream
11
11
}
12
12
import java .net .URL
13
- import java .nio .file .{FileAlreadyExistsException , Files }
13
+ import java .nio .file .{FileAlreadyExistsException , Files , Paths }
14
14
15
15
/**
16
16
* An abstraction over files for use in the reflection/compiler libraries.
@@ -21,28 +21,26 @@ import java.nio.file.{FileAlreadyExistsException, Files}
21
21
* @version 1.0, 23/03/2004
22
22
*/
23
23
object AbstractFile {
24
- /** Returns "getFile(new File(path))". */
25
24
def getFile (path : String ): AbstractFile = getFile(File (path))
26
- def getFile (path : Path ): AbstractFile = getFile(path.toFile)
25
+ def getDirectory (path : String ): AbstractFile = getDirectory(Directory (path))
26
+ def getFile (path : JPath ): AbstractFile = getFile(File (path))
27
+ def getDirectory (path : JPath ): AbstractFile = getDirectory(Directory (path))
27
28
28
29
/**
29
30
* If the specified File exists and is a regular file, returns an
30
31
* abstract regular file backed by it. Otherwise, returns `null`.
31
32
*/
32
- def getFile (file : File ): AbstractFile =
33
- if (file.isFile) new PlainFile (file) else null
34
-
35
- /** Returns "getDirectory(new File(path))". */
36
- def getDirectory (path : Path ): AbstractFile = getDirectory(path.toFile)
33
+ def getFile (path : Path ): AbstractFile =
34
+ if (path.isFile) new PlainFile (path) else null
37
35
38
36
/**
39
37
* If the specified File exists and is either a directory or a
40
38
* readable zip or jar archive, returns an abstract directory
41
39
* backed by it. Otherwise, returns `null`.
42
40
*/
43
- def getDirectory (file : File ): AbstractFile =
44
- if (file .isDirectory) new PlainFile (file )
45
- else if (file .isFile && Path .isExtensionJarOrZip(file .jpath)) ZipArchive fromFile file
41
+ def getDirectory (path : Path ): AbstractFile =
42
+ if (path .isDirectory) new PlainFile (path )
43
+ else if (path .isFile && Path .isExtensionJarOrZip(path .jpath)) ZipArchive fromFile path.toFile
46
44
else null
47
45
48
46
/**
@@ -51,11 +49,8 @@ object AbstractFile {
51
49
* Otherwise, returns `null`.
52
50
*/
53
51
def getURL (url : URL ): AbstractFile =
54
- if (url.getProtocol == " file" ) {
55
- val f = new java.io.File (url.getPath)
56
- if (f.isDirectory) getDirectory(f)
57
- else getFile(f)
58
- } else null
52
+ if (url.getProtocol != " file" ) null
53
+ else new PlainFile (new Path (Paths .get(url.toURI)))
59
54
60
55
def getResources (url : URL ): AbstractFile = ZipArchive fromManifestURL url
61
56
}
0 commit comments