]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/scl/Files.scl
Adding FileSystem and FileSystems to Files SCL-API
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Files.scl
1 import "Stream"
2 import "Vector"
3 import "Charset"
4
5 importJava "java.nio.file.Path" where
6     data Path
7     
8     @JavaName "getParent"
9     getParentPath :: Path -> <Proc> Path
10     
11     @JavaName "resolve"
12     resolvePath :: Path -> String -> <Proc> Path
13
14     @JavaName "relativize"
15     relativizePath :: Path -> Path -> <Proc> Path
16     
17     toAbsolutePath :: Path -> <Proc> Path
18     
19     @JavaName "toString"
20     pathToString :: Path -> <Proc> String
21
22 importJava "java.nio.file.Paths" where
23     
24     @JavaName "get"
25     paths :: String -> Vector String -> Path
26
27 path :: String -> Path
28 path path = paths path (vector [])
29
30 importJava "java.nio.file.OpenOption" where
31     data OpenOption
32
33 importJava "java.nio.file.StandardOpenOption" where
34     READ :: OpenOption
35     WRITE :: OpenOption
36     APPEND :: OpenOption
37     TRUNCATE_EXISTING :: OpenOption
38     CREATE :: OpenOption
39     CREATE_NEW :: OpenOption
40     DELETE_ON_CLOSE :: OpenOption
41     SPARSE :: OpenOption
42     SYNC :: OpenOption
43     DSYNC :: OpenOption
44
45 importJava "java.nio.file.CopyOption" where
46     data CopyOption
47
48 importJava "java.nio.file.LinkOption" where
49     data LinkOption
50
51 importJava "java.nio.file.StandardCopyOption" where
52     REPLACE_EXISTING :: CopyOption
53     COPY_ATTRIBUTES :: CopyOption
54     ATOMIC_MOVE :: CopyOption
55
56 importJava "java.nio.file.LinkOption" where
57     NOFOLLOW_LINKS :: CopyOption // OpenOption
58
59 importJava "java.nio.file.attribute.FileAttribute" where
60     data FileAttribute
61
62 importJava "java.nio.file.FileSystem" where
63     data FileSystem
64     
65     @JavaName close
66     closeFileSystem :: FileSystem -> <Proc> ()
67     
68     @JavaName getPath
69     getPathFromFileSystem :: FileSystem -> String -> Vector String -> <Proc> Path
70
71 importJava "java.lang.ClassLoader" where
72     @private
73     data ClassLoader
74
75 importJava "java.nio.file.FileSystems" where
76     @private
77     newFileSystem :: Path -> Maybe ClassLoader -> FileSystem
78
79 newFileSystemFromPath path = newFileSystem path Nothing
80
81 importJava "java.nio.file.Files" where
82     @JavaName newInputStream
83     newInputStreamWithOpenOptions :: Path -> Vector OpenOption -> <Proc, Exception> InputStream 
84
85     @JavaName newOutputStream
86     newOutputStreamWithOpenOptions :: Path -> Vector OpenOption -> <Proc, Exception> OutputStream
87
88     @JavaName createFile
89     createFileWithFileAttributes :: Path -> Vector FileAttribute -> <Proc, Exception> Path
90
91     @JavaName createDirectory
92     createDirectoryWithFileAttributes :: Path -> Vector FileAttribute -> <Proc, Exception> Path
93
94     @JavaName createDirectories
95     createDirectoriesWithFileAttributes :: Path -> Vector FileAttribute -> <Proc, Exception> Path
96
97     @JavaName createTempFile
98     createTempFileWithFileAttributes :: String -> String -> Vector FileAttribute -> <Proc, Exception> Path
99
100     delete :: Path -> <Proc, Exception> ()
101
102     deleteIfExists :: Path -> <Proc, Exception> Boolean
103     
104     @JavaName copy
105     copyWithCopyOptions :: Path -> Path -> Vector CopyOption -> <Proc, Exception> Path
106
107     @JavaName move
108     moveWithCopyOptions :: Path -> Path -> Vector CopyOption -> <Proc, Exception> Path
109
110     size :: Path -> <Proc, Exception> Long
111
112     @JavaName exists
113     existsWithLinkOptions :: Path -> Vector LinkOption -> <Proc> Boolean
114
115     @JavaName notExists
116     notExistsWithLinkOptions :: Path -> Vector LinkOption -> <Proc> Boolean
117
118     isReadable :: Path -> <Proc> Boolean
119
120     isWritable :: Path -> <Proc> Boolean
121
122     isExecutable :: Path -> <Proc> Boolean
123
124     // Simupedia has BufferedReader.scl module which contains BufferedReader
125     // newBufferedReader :: Path -> Charset -> <Proc> BufferedReader
126     // newBufferedReader :: Path -> <Proc> BufferedReader
127
128     @JavaName copy
129     copyInputStreamWithCopyOptions :: InputStream -> Path -> Vector CopyOption -> <Proc, Exception> Long
130
131     @JavaName copy
132     copyToOutputStream :: Path -> OutputStream -> <Proc, Exception> Long 
133
134     readAllBytes :: Path -> <Proc, Exception> Vector Byte
135     write :: Path -> Vector Byte -> Vector OpenOption -> <Proc,Exception> ()
136
137     @JavaName readAllLines
138     readAllLinesWithCharset :: Path -> Charset -> <Proc, Exception> [String]
139
140     readAllLines :: Path -> <Proc, Exception> [String]
141
142     @JavaName write
143     writeBytesWithOpenOptions :: Path -> Vector Byte -> Vector OpenOption -> <Proc, Exception> Path
144
145 newInputStream :: Path -> <Proc, Exception> InputStream
146 newInputStream path = newInputStreamWithOpenOptions path (vector [])
147
148 newOutputStream :: Path -> <Proc, Exception> OutputStream
149 newOutputStream path = newOutputStreamWithOpenOptions path (vector [])
150
151 createFile :: Path -> <Proc, Exception> Path
152 createFile path = createFileWithFileAttributes path (vector [])
153
154 createDirectory :: Path -> <Proc, Exception> Path
155 createDirectory path = createDirectoryWithFileAttributes path (vector [])
156
157 createDirectories :: Path -> <Proc, Exception> Path
158 createDirectories path = createDirectoriesWithFileAttributes path (vector [])
159
160 createTempFile :: String -> String -> <Proc, Exception> Path
161 createTempFile prefix suffix = createTempFileWithFileAttributes prefix suffix (vector [])
162
163 copy :: Path -> Path -> <Proc, Exception> Path
164 copy source target = copyWithCopyOptions source target (vector [])
165
166 move :: Path -> Path -> <Proc, Exception> Path
167 move source target = moveWithCopyOptions source target (vector [])
168
169 exists :: Path -> <Proc> Boolean
170 exists path = existsWithLinkOptions path (vector [])
171
172 notExists :: Path -> <Proc> Boolean
173 notExists path = notExistsWithLinkOptions path (vector [])