Exemplo n.º 1
0
    @Nullable
    public Image load() throws IOException {
      String cacheKey = null;
      InputStream stream = null;
      URL url = null;
      if (cls != null) {
        //noinspection IOResourceOpenedButNotSafelyClosed
        stream = cls.getResourceAsStream(path);
        if (stream == null) return null;
      }
      if (stream == null) {
        cacheKey = path;
        Image image = ourCache.get(cacheKey);
        if (image != null) return image;

        url = new URL(path);
        URLConnection connection = url.openConnection();
        if (connection instanceof HttpURLConnection) {
          if (!original) return null;
          connection.addRequestProperty("User-Agent", "IntelliJ");
        }
        stream = connection.getInputStream();
      }
      Image image = type.load(url, stream, scale);
      if (image != null && cacheKey != null) {
        ourCache.put(cacheKey, image);
      }
      return image;
    }
Exemplo n.º 2
0
 @Nullable
 public static Image loadFromResource(String path, Class aClass) {
   for (Pair<String, Integer> each : getFileNames(path)) {
     InputStream stream = aClass.getResourceAsStream(each.first);
     if (stream == null) continue;
     Image image = loadFromStream(stream, each.second);
     if (image != null) return image;
   }
   return null;
 }