@Nullable
 public static Image loadFromUrl(URL url) {
   for (Pair<String, Integer> each : getFileNames(url.toString())) {
     try {
       return loadFromStream(URLUtil.openStream(new URL(each.first)), each.second);
     } catch (IOException ignore) {
     }
   }
   return null;
 }
示例#2
0
  @NotNull
  public static String loadText(@NotNull URL url) throws IOException {
    InputStream inputStream = new BufferedInputStream(URLUtil.openStream(url));

    InputStreamReader reader = null;
    try {
      reader = new InputStreamReader(inputStream, ENCODING_UTF_8);
      StringBuffer text = new StringBuffer();
      char[] buf = new char[5000];
      while (reader.ready()) {
        final int length = reader.read(buf);
        if (length == -1) break;
        text.append(buf, 0, length);
      }
      return text.toString();
    } finally {
      if (reader != null) {
        reader.close();
      }
    }
  }