Just saving this away for a rainy day…something I concocted in response to a question on the Groovy mailing list:
new File("local.gif").withOutputStream { os ->
new URL("remote.gif").withInputStream { is ->
os << is
}
}
The important thing to note here is the way the streams are carefully ’scoped’ and maintained so that no leaks can occur even if exceptions or other sticky situations arise.
