package algus; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.util.stream.Stream; public class Vork2 { public static String loe(String aadress){ try(BufferedReader sisse=new BufferedReader(new InputStreamReader( new URL(aadress).openStream()))){ return sisse.lines().map(a->a+"\n").reduce("", String::concat); } catch(Exception ex){ return ex.toString(); } } public static void main(String[] args) { String[] aadressid={ "http://www.bcs.ee/", // "http://www.microsoft.com/", // "http://www.eesti.ee/", "http://www.epl.ee/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://www.oracle.com/", "http://minitorn.tlu.ee/~jaagup/kool/java/kursused/14/javajatk/naited/september/java8/src/algus/harjutus.txt", "http://minitorn.tlu.ee/~jaagup/kool/java/kursused/14/javajatk/naited/september/java8/src/algus/harjutus.txt", "http://minitorn.tlu.ee/~jaagup/kool/java/kursused/14/javajatk/naited/september/java8/src/algus/harjutus.txt", "http://minitorn.tlu.ee/~jaagup/kool/java/kursused/14/javajatk/naited/september/java8/src/algus/harjutus.txt", "http://minitorn.tlu.ee/~jaagup/kool/java/kursused/14/javajatk/naited/september/java8/src/algus/harjutus.txt", "http://www.tlu.ee/" }; long algus=System.currentTimeMillis(); //System.out.println(loe(aadressid[5])); int kogupikkus=Stream.of(aadressid).parallel().map(Vork2::loe).mapToInt(s -> s.length()).sum(); long ots=System.currentTimeMillis(); System.out.println(ots-algus+" ms, "+kogupikkus+" märki"); } }