FileDocCategorySizeDatePackage
Confidentializer.javaAPI DocExample2204Tue Jan 25 10:45:14 GMT 2000None

Confidentializer

public class Confidentializer extends HttpServlet

Fields Summary
Frame
frame
Graphics
g
Constructors Summary
Methods Summary
public voiddestroy()

    // Clean up resources
    if (frame != null) frame.removeNotify();
  
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)

    ServletOutputStream out = res.getOutputStream();

    try {
      // Get the image location from the path info
      String source = req.getPathTranslated();
      if (source == null) {
        throw new ServletException("Extra path information " +
                                   "must point to an image");
      }
  
      // Load the image (from bytes to an Image object)
      MediaTracker mt = new MediaTracker(frame);  // frame acts as an ImageObserver
      Image image = Toolkit.getDefaultToolkit().getImage(source);
      mt.addImage(image, 0);
      try {
        mt.waitForAll();
      }
      catch (InterruptedException e) {
        getServletContext().log(e, "Interrupted while loading image");
        throw new ServletException(e.getMessage());
      }

      // Construct a matching-size off screen graphics context
      int w = image.getWidth(frame);
      int h = image.getHeight(frame);
      Image offscreen = frame.createImage(w, h);
      g = offscreen.getGraphics();

      // Draw the image to the off screen graphics context
      g.drawImage(image, 0, 0, frame);
  
      // Write CONFIDENTIAL over its top
      g.setFont(new Font("Monospaced", Font.BOLD | Font.ITALIC, 30));
      g.drawString("CONFIDENTIAL", 10, 30);

      // Encode the off screen graphics into a GIF and send it to the client
      res.setContentType("image/gif");
      GifEncoder encoder = new GifEncoder(offscreen, out);
      encoder.encode();
    }
    finally {
      // Clean up resources
      if (g != null) g.dispose();
    }
  
public voidinit(javax.servlet.ServletConfig config)


        
    super.init(config);
    // Construct a reusable unshown frame
    frame = new Frame();
    frame.addNotify();