Created
July 20, 2014 04:57
-
-
Save yehjames/4ddebe1edb5355ae0049 to your computer and use it in GitHub Desktop.
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
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import org.omg.CORBA.PUBLIC_MEMBER; | |
public class Download2 { | |
public static void main(String[] args) throws IOException { | |
// TODO Auto-generated method stub | |
long start = System.currentTimeMillis(); | |
final URL[] urls={ | |
new URL("http://openhome.cc/Gossip/Encoding/"), | |
new URL("http://openhome.cc/Gossip/Scala/"), | |
new URL("http://openhome.cc/Gossip/JavaScript/"), | |
new URL("http://openhome.cc/Gossip/Python/") | |
}; | |
final String[] fileNames= { | |
"Encoding.html", | |
"Scala.html", | |
"JavaScript.html", | |
"Python.html" | |
}; | |
for (int i = 0; i < urls.length; i++) { | |
final int index=i; | |
new Thread(){ | |
@Override | |
public void run() { | |
try { | |
dump(urls[index].openStream(),new FileOutputStream(fileNames[index])); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
throw new RuntimeException(e); | |
} | |
}; | |
}.start(); | |
} | |
long exit = System.currentTimeMillis(); | |
System.out.println("Exit"); | |
System.out.println((exit-start)); | |
} | |
public static void dump(InputStream src,OutputStream dest) throws IOException{ | |
try(InputStream input=src;OutputStream output=dest){ | |
byte[] data=new byte[1024]; | |
int length=-1; | |
while ((length=input.read(data))!=-1) { | |
output.write(data,0,length); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment