Skip to content

Instantly share code, notes, and snippets.

@rbe
Created October 22, 2010 06:38
Show Gist options
  • Save rbe/640064 to your computer and use it in GitHub Desktop.
Save rbe/640064 to your computer and use it in GitHub Desktop.
Copy a stream
class GroovyHelper {
/**
* Copy a stream using a certain buffer size.
*/
def static copyStream = { from, to, bufKb = 1 ->
byte[] buf = new byte[bufKb * 1024]
def len = 0
while ((len = from.read(buf)) > 0) {
to.write(buf, 0, len)
}
to.close()
from.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment