1 5 package org.roller.presentation.pagecache.rollercache; 6 7 import java.io.*; 8 9 import java.util.Locale ; 10 11 import javax.servlet.ServletResponse ; 12 import javax.servlet.http.HttpServletResponse ; 13 14 22 public class ResponseContent implements Serializable { 23 private transient ByteArrayOutputStream bout = new ByteArrayOutputStream(1000); 24 private Locale locale = null; 25 private String contentType = null; 26 private byte[] content = null; 27 private long lastModified = -1; 28 29 33 public void setContentType(String value) { 34 contentType = value; 35 } 36 37 public long getLastModified() { 38 return lastModified; 39 } 40 41 public void setLastModified(long value) { 42 lastModified = value; 43 } 44 45 49 public void setLocale(Locale value) { 50 locale = value; 51 } 52 53 57 public OutputStream getOutputStream() { 58 return bout; 59 } 60 61 67 public int getSize() { 68 return (content != null) ? content.length : (-1); 69 } 70 71 76 public void commit() { 77 content = bout.toByteArray(); 78 } 79 80 86 public void writeTo(ServletResponse response) throws IOException { 87 if (contentType != null) { 89 response.setContentType(contentType); 90 } 91 92 96 response.setContentLength(content.length); 97 98 if (locale != null) { 99 response.setLocale(locale); 100 } 101 102 OutputStream out = new BufferedOutputStream(response.getOutputStream()); 103 out.write(content); 104 out.flush(); 105 } 106 } 107 | Popular Tags |