Hacker News new | past | comments | ask | show | jobs | submit login

One liner in Java 8:

    List<String> contents = Arrays.stream(urls).parallel().map(UrlLoader::getContent).collect(Collectors.toList());
but as far as I know the API doesn't provide any way to get a String from an URL, so you need an helper class that also workaround checked exceptions ...

    public class UrlLoader {
      private static String getContent(String url) {
        try {
          return new BufferedReader(new InputStreamReader(new URL(url).openConnection().getInputStream())).lines().collect(Collectors.joining("\n"));
        } catch (IOException e) {
          throw new IOError(e);
        }
      }
    }
so not a real one liner :(



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: