import "Prelude" import "JavaBuiltin" as Java class Closeable a where close :: a -> () // Reading importJava "java.io.InputStream" where data InputStream @private @JavaName close closeInputStream :: InputStream -> () instance Closeable InputStream where close = closeInputStream // Writing importJava "java.io.OutputStream" where data OutputStream @private @JavaName close closeOutputStream :: OutputStream -> () instance Closeable OutputStream where close = closeOutputStream // Classes class Writable a where openForWriting :: a -> OutputStream class Readable a where openForReading :: a -> InputStream // Byte array stream importJava "java.io.ByteArrayInputStream" where @private @JavaName "" openArrayForReading :: ByteArray -> InputStream instance Readable ByteArray where openForReading = openArrayForReading importJava "java.io.ByteArrayOutputStream" where data Buffer @JavaName "" createBuffer :: () -> Buffer toByteArray :: Buffer -> ByteArray instance Writable Buffer where openForWriting = Java.unsafeCoerce