private Icon makeIcon(final String gifFile) throws IOException {
    /* Copy resource into a byte array.  This is
     * necessary because several browsers consider
     * Class.getResource a security risk because it
     * can be used to load additional classes.
     * Class.getResourceAsStream just returns raw
     * bytes, which we can convert to an image.
     */
    InputStream resource = MyImageView.class.getResourceAsStream(gifFile);

    if (resource == null) {
      System.err.println(MyImageView.class.getName() + "/" + gifFile + " not found!!.");
      return null;
    }
    BufferedInputStream in = new BufferedInputStream(resource);
    ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
    byte[] buffer = new byte[1024];
    int n;
    while ((n = in.read(buffer)) > 0) {
      out.write(buffer, 0, n);
    }
    in.close();
    out.flush();

    buffer = out.toByteArray();
    if (buffer.length == 0) {
      System.err.println("warning: " + gifFile + " is zero-length");
      return null;
    }
    return new ImageIcon(buffer);
  }
Beispiel #2
0
 public String getData() {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   try {
     getDrawing().getOutputFormats().get(0).write(out, getDrawing());
     return out.toString("UTF8");
   } catch (IOException e) {
     SVGTextFigure tf = new SVGTextFigure();
     tf.setText(e.getMessage());
     tf.setBounds(new Point2D.Double(10, 10), new Point2D.Double(100, 100));
     getDrawing().add(tf);
     e.printStackTrace();
     return "";
   }
 }