@@ -10,7 +10,7 @@ import java.io.{
1010 ByteArrayOutputStream
1111}
1212import java .net .URL
13- import java .nio .file .{FileAlreadyExistsException , Files }
13+ import java .nio .file .{FileAlreadyExistsException , Files , Paths }
1414
1515/**
1616 * An abstraction over files for use in the reflection/compiler libraries.
@@ -21,28 +21,26 @@ import java.nio.file.{FileAlreadyExistsException, Files}
2121 * @version 1.0, 23/03/2004
2222 */
2323object AbstractFile {
24- /** Returns "getFile(new File(path))". */
2524 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))
2728
2829 /**
2930 * If the specified File exists and is a regular file, returns an
3031 * abstract regular file backed by it. Otherwise, returns `null`.
3132 */
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
3735
3836 /**
3937 * If the specified File exists and is either a directory or a
4038 * readable zip or jar archive, returns an abstract directory
4139 * backed by it. Otherwise, returns `null`.
4240 */
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
4644 else null
4745
4846 /**
@@ -51,11 +49,8 @@ object AbstractFile {
5149 * Otherwise, returns `null`.
5250 */
5351 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)))
5954
6055 def getResources (url : URL ): AbstractFile = ZipArchive fromManifestURL url
6156}
0 commit comments