From: jsimomaa Date: Wed, 23 Aug 2017 18:00:42 +0000 (+0300) Subject: java.nio.file.Files and Charset SCL API with effect X-Git-Tag: v1.31.0~222 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=0ad1451845e5859184330dd6718f32604c1b7825 java.nio.file.Files and Charset SCL API with effect refs #7448 Change-Id: I6c4a5307ae5a0ce6c346e1afe80f97b90464c3c6 --- diff --git a/bundles/org.simantics.scl.runtime/scl/Charset.scl b/bundles/org.simantics.scl.runtime/scl/Charset.scl new file mode 100644 index 000000000..fd881ac5b --- /dev/null +++ b/bundles/org.simantics.scl.runtime/scl/Charset.scl @@ -0,0 +1,14 @@ +import "Prelude" + +importJava "java.nio.charset.Charset" where + data Charset + + forName :: String -> Charset + + name :: Charset -> String + +instance Show Charset where + show charset = name charset + +importJava "java.nio.charset.StandardCharsets" where + UTF_8 :: Charset \ No newline at end of file diff --git a/bundles/org.simantics.scl.runtime/scl/Files.scl b/bundles/org.simantics.scl.runtime/scl/Files.scl new file mode 100644 index 000000000..ed413889c --- /dev/null +++ b/bundles/org.simantics.scl.runtime/scl/Files.scl @@ -0,0 +1,139 @@ +import "Stream" +import "Vector" +import "Charset" + +importJava "java.nio.file.Path" where + data Path + +importJava "java.nio.file.Paths" where + + @JavaName "get" + paths :: String -> Vector String -> Path + +path :: String -> Path +path path = paths path (vector []) + +importJava "java.nio.file.OpenOption" where + data OpenOption + +importJava "java.nio.file.StandardOpenOption" where + READ :: OpenOption + WRITE :: OpenOption + APPEND :: OpenOption + TRUNCATE_EXISTING :: OpenOption + CREATE :: OpenOption + CREATE_NEW :: OpenOption + DELETE_ON_CLOSE :: OpenOption + SPARSE :: OpenOption + SYNC :: OpenOption + DSYNC :: OpenOption + +importJava "java.nio.file.CopyOption" where + data CopyOption + +importJava "java.nio.file.LinkOption" where + data LinkOption + +importJava "java.nio.file.StandardCopyOption" where + REPLACE_EXISTING :: CopyOption + COPY_ATTRIBUTES :: CopyOption + ATOMIC_MOVE :: CopyOption + +importJava "java.nio.file.LinkOption" where + NOFOLLOW_LINKS :: CopyOption // OpenOption + +importJava "java.nio.file.attribute.FileAttribute" where + data FileAttribute + +importJava "java.nio.file.Files" where + @JavaName newInputStream + newInputStreamWithOpenOptions :: Path -> Vector OpenOption -> InputStream + + @JavaName newOutputStream + newOutputStreamWithOpenOptions :: Path -> Vector OpenOption -> OutputStream + + @JavaName createFile + createFileWithFileAttributes :: Path -> Vector FileAttribute -> Path + + @JavaName createDirectory + createDirectoryWithFileAttributes :: Path -> Vector FileAttribute -> Path + + @JavaName createDirectories + createDirectoriesWithFileAttributes :: Path -> Vector FileAttribute -> Path + + @JavaName createTempFile + createTempFileWithFileAttributes :: Path -> String -> String -> Vector FileAttribute -> Path + + delete :: Path -> () + + deleteIfExists :: Path -> Boolean + + @JavaName copy + copyWithCopyOptions :: Path -> Path -> Vector CopyOption -> Path + + @JavaName move + moveWithCopyOptions :: Path -> Path -> Vector CopyOption -> Path + + size :: Path -> Long + + @JavaName exists + existsWithLinkOptions :: Path -> Vector LinkOption -> Boolean + + @JavaName notExists + notExistsWithLinkOptions :: Path -> Vector LinkOption -> Boolean + + isReadable :: Path -> Boolean + + isWritable :: Path -> Boolean + + isExecutable :: Path -> Boolean + + // Simupedia has BufferedReader.scl module which contains BufferedReader + // newBufferedReader :: Path -> Charset -> BufferedReader + // newBufferedReader :: Path -> BufferedReader + + @JavaName copy + copyInputStreamWithCopyOptions :: InputStream -> Path -> Vector CopyOption -> Long + + @JavaName copy + copyToOutputStream :: Path -> OutputStream -> Long + + readAllBytes :: Path -> Vector Byte + + @JavaName readAllLines + readAllLinesWithCharset :: Path -> Charset -> [String] + + readAllLines :: Path -> [String] + + @JavaName write + writeBytesWithOpenOptions :: Path -> Vector Byte -> Vector OpenOption -> Path + +newInputStream :: Path -> InputStream +newInputStream path = newInputStreamWithOpenOptions path (vector []) + +newOutputStream :: Path -> OutputStream +newOutputStream path = newOutputStreamWithOpenOptions path (vector []) + +createFile :: Path -> Path +createFile path = createFileWithFileAttributes path (vector []) + +createDirectory :: Path -> Path +createDirectory path = createDirectoryWithFileAttributes path (vector []) + +createDirectories :: Path -> Path +createDirectories path = createDirectoriesWithFileAttributes path (vector []) + +createTempFile :: Path -> String -> String -> Path +createTempFile dir prefix suffix = createTempFileWithFileAttributes dir prefix suffix (vector []) + +copy :: Path -> Path -> Path +copy source target = copyWithCopyOptions source target (vector []) + +move :: Path -> Path -> Path +move source target = moveWithCopyOptions source target (vector []) + +exists :: Path -> Boolean +exists path = existsWithLinkOptions path (vector []) + +notExists :: Path -> Boolean +notExists path = notExistsWithLinkOptions path (vector [])