]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.runtime/scl/Stream.scl
Introduce WrapLayout to replace FlowLayout
[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     
16 instance Closeable InputStream where
17     close = closeInputStream
18
19 // Writing
20
21 importJava "java.io.OutputStream" where
22     data OutputStream
23
24     @private
25     @JavaName close
26     closeOutputStream :: OutputStream -> <Proc> ()
27     
28 instance Closeable OutputStream where
29     close = closeOutputStream
30
31 // Classes
32
33 class Writable a where
34     openForWriting :: a -> <Proc> OutputStream 
35
36 class Readable a where
37     openForReading :: a -> <Proc> InputStream
38     
39 // Byte array stream
40
41 importJava "java.io.ByteArrayInputStream" where
42     @private
43     @JavaName "<init>"
44     openArrayForReading :: ByteArray -> <Proc> InputStream
45
46 instance Readable ByteArray where
47     openForReading = openArrayForReading
48
49 importJava "java.io.ByteArrayOutputStream" where
50     data Buffer
51     
52     @JavaName "<init>"
53     createBuffer :: () -> <Proc> Buffer
54     toByteArray :: Buffer -> <Proc> ByteArray    
55     
56 instance Writable Buffer where
57     openForWriting = Java.unsafeCoerce
58