]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/scl/Stream.scl
150d55e6c9462ce3ca129f3c969e250b632ec0f2
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Stream.scl
1 import "Prelude"
2 import "JavaBuiltin" as Java
3
4 class Closeable a where
5     close :: a -> <Proc> ()
6
7 // Reading    
8     
9 importJava "java.io.InputStream" where
10     data InputStream
11     
12     @private
13     @JavaName close
14     closeInputStream :: InputStream -> <Proc> ()
15     skip :: InputStream -> Long -> <Proc> Long
16     
17 instance Closeable InputStream where
18     close = closeInputStream
19
20 // Writing
21
22 importJava "java.io.OutputStream" where
23     data OutputStream
24
25     @private
26     @JavaName close
27     closeOutputStream :: OutputStream -> <Proc> ()
28     
29 instance Closeable OutputStream where
30     close = closeOutputStream
31
32 // Classes
33
34 class Writable a where
35     openForWriting :: a -> <Proc> OutputStream 
36
37 class Readable a where
38     openForReading :: a -> <Proc> InputStream
39     
40 // Byte array stream
41
42 importJava "java.io.ByteArrayInputStream" where
43     @private
44     @JavaName "<init>"
45     openArrayForReading :: ByteArray -> <Proc> InputStream
46
47 instance Readable ByteArray where
48     openForReading = openArrayForReading
49
50 importJava "java.io.ByteArrayOutputStream" where
51     data Buffer
52     
53     @JavaName "<init>"
54     createBuffer :: () -> <Proc> Buffer
55     toByteArray :: Buffer -> <Proc> ByteArray    
56     
57 instance Writable Buffer where
58     openForWriting = Java.unsafeCoerce
59