]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/Stream.scl
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / Stream.scl
diff --git a/bundles/org.simantics.scl.runtime/scl/Stream.scl b/bundles/org.simantics.scl.runtime/scl/Stream.scl
new file mode 100644 (file)
index 0000000..cd0d458
--- /dev/null
@@ -0,0 +1,58 @@
+import "Prelude"
+import "JavaBuiltin" as Java
+
+class Closeable a where
+    close :: a -> <Proc> ()
+
+// Reading    
+    
+importJava "java.io.InputStream" where
+    data InputStream
+    
+    @private
+    @JavaName close
+    closeInputStream :: InputStream -> <Proc> ()
+    
+instance Closeable InputStream where
+    close = closeInputStream
+
+// Writing
+
+importJava "java.io.OutputStream" where
+    data OutputStream
+
+    @private
+    @JavaName close
+    closeOutputStream :: OutputStream -> <Proc> ()
+    
+instance Closeable OutputStream where
+    close = closeOutputStream
+
+// Classes
+
+class Writable a where
+    openForWriting :: a -> <Proc> OutputStream 
+
+class Readable a where
+    openForReading :: a -> <Proc> InputStream
+    
+// Byte array stream
+
+importJava "java.io.ByteArrayInputStream" where
+    @private
+    @JavaName "<init>"
+    openArrayForReading :: ByteArray -> <Proc> InputStream
+
+instance Readable ByteArray where
+    openForReading = openArrayForReading
+
+importJava "java.io.ByteArrayOutputStream" where
+    data Buffer
+    
+    @JavaName "<init>"
+    createBuffer :: () -> <Proc> Buffer
+    toByteArray :: Buffer -> <Proc> ByteArray    
+    
+instance Writable Buffer where
+    openForWriting = Java.unsafeCoerce
+