Statistics
| Revision:

root / tmp / org.txm.groovy.core / src / groovy / org / txm / scripts / prototypes / WGet.groovy @ 1000

History | View | Annotate | Download (637 Bytes)

1 1000 mdecorde
package org.txm.scripts.test
2 881 mdecorde
3 321 mdecorde
URL url = new URL("http://docs.codehaus.org/display/GROOVY/Simple+file+download+from+URL");
4 321 mdecorde
File outFile = new File("test.out")
5 321 mdecorde
6 321 mdecorde
static def download(def file, def url) {
7 321 mdecorde
                url.withInputStream() {is->
8 321 mdecorde
                         file.withOutputStream() {os->
9 321 mdecorde
                                 def bs = new BufferedOutputStream( os )
10 321 mdecorde
                                 bs << is
11 321 mdecorde
                         }
12 321 mdecorde
                 }
13 321 mdecorde
}
14 321 mdecorde
15 321 mdecorde
// if proxy , uncomment this and set up properties
16 321 mdecorde
//System.properties.putAll( ["http.proxyHost":"proxy-host",
17 321 mdecorde
//                                                         "http.proxyPort":"proxy-port",
18 321 mdecorde
//                                                         "http.proxyUserName":"user-name",
19 321 mdecorde
//                                                         "http.proxyPassword":"proxy-passwd"] )
20 321 mdecorde
21 321 mdecorde
WGet.download(outFile, url);
22 321 mdecorde
println outFile.getText()