1 29 30 package nextapp.echo2.webcontainer.image; 31 32 import java.io.IOException ; 33 import nextapp.echo2.app.AwtImageReference; 34 import nextapp.echo2.app.ImageReference; 35 import nextapp.echo2.webrender.Connection; 36 import nextapp.echo2.webrender.ContentType; 37 import nextapp.echo2.webrender.WebRenderServlet; 38 39 42 public class AwtImageService extends AbstractImageService { 43 44 private static final String SERVICE_ID = "Echo.AwtImage"; 45 46 public static final AwtImageService INSTANCE = new AwtImageService(); 47 48 static { 49 WebRenderServlet.getServiceRegistry().add(INSTANCE); 50 } 51 52 55 public String getId() { 56 return SERVICE_ID; 57 } 58 59 62 public int getVersion() { 63 return 0; } 65 66 70 public void renderImage(Connection conn, ImageReference imageReference) 71 throws IOException { 72 try { 73 if (!(imageReference instanceof AwtImageReference)) { 74 throw new IOException ("Image is not an AwtImageReference."); 75 } 76 PngEncoder encoder = new PngEncoder(((AwtImageReference) imageReference).getImage(), true, null, 3); 77 conn.setContentType(ContentType.IMAGE_PNG); 78 encoder.encode(conn.getOutputStream()); 79 } catch (IOException ex) { 80 } 83 } 84 } 85 | Popular Tags |