Created
August 13, 2012 19:48
-
-
Save xhanin/3343588 to your computer and use it in GitHub Desktop.
Download file with Vert.x (not working with vert.x 1.2.3)
This file contains hidden or 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
import static org.vertx.groovy.core.streams.Pump.createPump | |
vertx.createHttpClient(host: 'humanstxt.org', port: 80) | |
.getNow('/humans.txt') { resp -> | |
println "GOT response with status $resp.statusCode" | |
resp.pause(); | |
resp.endHandler { | |
println "response END with first registered handler" | |
} | |
def filename = "${UUID.randomUUID()}.txt" | |
vertx.fileSystem.open(filename) { ares -> | |
println "file opened" | |
def file = ares.result | |
def pump = createPump(resp, file.writeStream) | |
resp.endHandler { | |
println "response END with handler after file opening" | |
file.close { | |
println "Stored ${pump.bytesPumped} bytes to $filename" | |
} | |
} | |
pump.start() | |
resp.resume() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment