[#105] initial support for java.nio.file.Files

This commit is contained in:
Michiel Borkent 2019-11-27 17:14:24 +01:00 committed by GitHub
parent 51b61a921e
commit 1885c45255
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 11 deletions

View file

@ -179,12 +179,14 @@ The following Java classes are available:
- `clojure.lang.ExceptionInfo`
- `Integer`
- `java.io.File`
- `java.nio.Files`
- `java.util.regex.Pattern`
- `String`
- `System`
- `Thread`
More classes can be added by request.
More classes can be added by request. See `reflection.json` and the `:classes`
option in `main.clj`.
Babashka supports `import` : `(import clojure.lang.ExceptionInfo)`.

View file

@ -121,5 +121,45 @@
{
"name":"java.lang.UNIXProcess",
"allPublicMethods":true
},
{
"name":"java.nio.file.Path",
"allPublicMethods":true
},
{
"name":"java.nio.file.CopyOption",
"allPublicMethods":true,
"allPublicFields": true,
"allPublicConstructors": true
},
{
"name":"java.nio.file.FileAlreadyExistsException",
"allPublicMethods":true,
"allPublicFields": true,
"allPublicConstructors": true
},
{
"name":"java.nio.file.Files",
"allPublicMethods":true,
"allPublicFields": true,
"allPublicConstructors": true
},
{
"name":"java.nio.file.NoSuchFileException",
"allPublicMethods":true,
"allPublicFields": true,
"allPublicConstructors": true
},
{
"name":"java.nio.file.StandardCopyOption",
"allPublicMethods":true,
"allPublicFields": true,
"allPublicConstructors": true
},
{
"name":"sun.nio.fs.UnixPath",
"allPublicMethods":true,
"allPublicFields": true,
"allPublicConstructors": true
}
]

2
sci

@ -1 +1 @@
Subproject commit d91bf4bf1b831de58a4980379558aed6ce28a641
Subproject commit 736880b590e6df75e928a826f1aa24e17a613c67

View file

@ -227,7 +227,14 @@ Everything after that is bound to *command-line-args*."))
'java.io.StringReader java.io.StringReader
'java.io.StringWriter java.io.StringWriter
'java.lang.System System
'java.lang.Thread Thread}
'java.lang.Thread Thread
'sun.nio.fs.UnixPath sun.nio.fs.UnixPath
'java.nio.file.CopyOption java.nio.file.CopyOption
'java.nio.file.FileAlreadyExistsException java.nio.file.FileAlreadyExistsException
'java.nio.file.Files java.nio.file.Files
'java.nio.file.NoSuchFileException java.nio.file.NoSuchFileException
'java.nio.file.StandardCopyOption java.nio.file.StandardCopyOption
}
:imports '{ArithmeticException java.lang.ArithmeticException
AssertionError java.lang.AssertionError
Boolean java.lang.Boolean

View file

@ -269,3 +269,22 @@
(deftest with-in-str-test
(is (= 5 (bb nil "(count (with-in-str \"hello\" (read-line)))"))))
(deftest java-nio-test
(let [f (java.io.File/createTempFile "foo" "bar")
temp-path (.getPath f)
p (.toPath (io/file f))
p' (.resolveSibling p "f2")
f2 (.toFile p')]
(bb nil (format
"(let [f (io/file \"%s\")
p (.toPath (io/file f))
p' (.resolveSibling p \"f2\")]
(.delete (.toFile p'))
(dotimes [_ 2]
(try
(java.nio.file.Files/copy p p' (into-array java.nio.file.CopyOption []))
(catch java.nio.file.FileAlreadyExistsException _
(java.nio.file.Files/copy p p' (into-array [java.nio.file.StandardCopyOption/REPLACE_EXISTING]))))))"
temp-path))
(is (.exists f2))))