--- /dev/null
+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
+