コード例 #1
0
    /** Shows current tweet dialog and downloads user image */
    private void showTweet() {
      String text = current_tweet.getText();

      if (text != null) {
        String from = current_tweet.getFromUser();
        Alert a = new Alert("" + from, text, null, AlertType.INFO);

        a.setTimeout(Alert.FOREVER);
        display.setCurrent(a, this);
        String url = current_tweet.getProfileImageUrl();

        if (url != null) {
          // download and set user image to visible alert
          Image img;
          InputStream is = null;

          try {
            is = Connector.openInputStream(url);
            img = Image.createImage(is);
            a.setImage(img);
          } catch (Throwable t) { // do not show errors if image
            // download fails
          } finally {
            try {
              if (is != null) {
                is.close();
              }
            } catch (Throwable e) {
            }
          }
        }
      }
    }
コード例 #2
0
ファイル: TrafficCams.java プロジェクト: raghulj/tis
  private Image getImage(String str) throws IOException {
    String url = "http://" + controller.selectedCity.URL + "/cameras/images/" + str + ".jpg";
    System.out.println(url);
    InputStream iStrm = (InputStream) Connector.openInputStream(url);
    Image im = null;

    try {
      ByteArrayOutputStream bStrm = new ByteArrayOutputStream();

      int ch;
      while ((ch = iStrm.read()) != -1) bStrm.write(ch);

      // Place into image array
      byte imageData[] = bStrm.toByteArray();

      // Create the image from the byte array
      im = Image.createImage(imageData, 0, imageData.length);

    } finally {
      // Clean up
      if (iStrm != null) iStrm.close();
    }

    return (im == null ? null : im);
  }