1 29 30 package nextapp.echo2.webcontainer.image; 31 32 import java.io.IOException ; 33 34 import nextapp.echo2.app.ImageReference; 35 import nextapp.echo2.app.StreamImageReference; 36 import nextapp.echo2.webrender.Connection; 37 import nextapp.echo2.webrender.ContentType; 38 import nextapp.echo2.webrender.WebRenderServlet; 39 40 43 public class StreamImageService extends AbstractImageService { 44 45 46 private static final String SERVICE_ID = "Echo.StreamImage"; 47 48 49 public static final StreamImageService INSTANCE = new StreamImageService(); 50 51 static { 52 WebRenderServlet.getServiceRegistry().add(INSTANCE); 53 } 54 55 58 public String getId() { 59 return SERVICE_ID; 60 } 61 62 65 public int getVersion() { 66 return 0; } 68 69 73 public void renderImage(Connection conn, ImageReference imageReference) 74 throws IOException { 75 try { 76 if (!(imageReference instanceof StreamImageReference)) { 77 throw new IOException ("Image is not a StreamImageReference."); 78 } 79 StreamImageReference streamImageReference = (StreamImageReference) imageReference; 80 conn.setContentType(new ContentType(streamImageReference.getContentType(), true)); 81 streamImageReference.render(conn.getOutputStream()); 82 } catch (IOException ex) { 83 } 88 } 89 } 90 | Popular Tags |