1 29 30 package nextapp.echo2.webrender.service; 31 32 import java.io.IOException ; 33 34 import nextapp.echo2.webrender.Connection; 35 import nextapp.echo2.webrender.Service; 36 import nextapp.echo2.webrender.util.Resource; 37 38 41 public class StaticBinaryService 42 implements Service { 43 44 56 public static StaticBinaryService forResource(String id, String contentType, String resourceName) { 57 byte[] data = Resource.getResourceAsByteArray(resourceName); 58 return new StaticBinaryService(id, contentType, data); 59 } 60 61 private String id; 62 private byte[] data; 63 private String contentType; 64 65 72 public StaticBinaryService(String id, String contentType, byte[] data) { 73 super(); 74 this.id = id; 75 this.contentType = contentType; 76 this.data = data; 77 } 78 79 82 public String getId() { 83 return id; 84 } 85 86 89 public int getVersion() { 90 return 0; 91 } 92 93 96 public void service(Connection conn) 97 throws IOException { 98 try { 99 conn.getResponse().setContentType(contentType); 100 conn.getOutputStream().write(data); 101 } catch (IOException ex) { 102 } 107 } 108 } 109 | Popular Tags |