Last active
November 9, 2015 17:41
-
-
Save fmamud/7c67448b10c80e0926b7 to your computer and use it in GitHub Desktop.
Retrieve an image with a connection via proxy and uses the Java API NIO.2 to save the inputstream in a file on disk.
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 java.io.InputStream; | |
import java.net.InetSocketAddress; | |
import java.net.Proxy; | |
import java.net.Proxy.Type; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
public class HttpFileGet { | |
public static void main(String[] args) throws Exception { | |
Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("127.0.0.1",8888)); | |
URLConnection conn = new URL("http://flupy.org/data/flags/br/br.gif") | |
.openConnection(proxy); | |
try (InputStream is = conn.getInputStream()) { | |
Files.copy(is, Paths.get("/temp/br.gif")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment