Created
October 22, 2010 06:38
-
-
Save rbe/640064 to your computer and use it in GitHub Desktop.
Copy a stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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