Skip to content

Instantly share code, notes, and snippets.

@jsuereth
Created April 22, 2011 05:03
Show Gist options
  • Save jsuereth/936060 to your computer and use it in GitHub Desktop.
Save jsuereth/936060 to your computer and use it in GitHub Desktop.
Scalaz Iteratee NIO
Welcome to Scala version 2.8.1.final (OpenJDK 64-Bit Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scalaz.io.ByteBuffers._
import scalaz.io.ByteBuffers._
scala> import scalaz.Scalaz._
import scalaz.Scalaz._
scala> import scalaz.io.Channels._
import scalaz.io.Channels._
scala> val x = new java.io.FileInputStream("test.txt")
x: java.io.FileInputStream = java.io.FileInputStream@3c3069be
scala> val y = new java.io.FileOutputStream("test2.txt")
y: java.io.FileOutputStream = java.io.FileOutputStream@7a1d6f6f
scala> val in = byteBuffer
byteBufferInputChannel byteBufferOutputChannel
scala> val in = byteBufferInputChannel(x.getChannel, java.nio.ByteBuffer.allocate(512))
in: scalaz.io.Channels.InputChannel[java.nio.ByteBuffer] = scalaz.io.Channels$$anon$2@7a6da228
scala> val out = byteBuffer
byteBufferInputChannel byteBufferOutputChannel
scala> val out = byteBufferOutputChannel(y.getChannel)
out: scalaz.io.Channels.OutputChannel[java.nio.ByteBuffer] = scalaz.io.Channels$$anon$1@739b2cdc
scala> writeToChannel(out)(in)
res0: scalaz.IterV[java.nio.ByteBuffer,Unit] = scalaz.IterV$Done$$anon$1@237bde13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment