1 package com.opensymphony.webwork.dispatcher; 2 3 import com.opensymphony.xwork.ActionInvocation; 4 5 import javax.servlet.http.HttpServletResponse ; 6 import java.io.InputStream ; 7 import java.io.OutputStream ; 8 9 53 public class StreamResult extends WebWorkResultSupport { 54 protected String contentType = "text/plain"; 55 protected int contentLength; 56 protected String contentDisposition = "inline"; 57 protected String inputName = "inputStream"; 58 protected int bufferSize = 1024; 59 60 63 public int getBufferSize() { 64 return (bufferSize); 65 } 66 67 70 public void setBufferSize(int bufferSize) { 71 this.bufferSize = bufferSize; 72 } 73 74 77 public String getContentType() { 78 return (contentType); 79 } 80 81 84 public void setContentType(String contentType) { 85 this.contentType = contentType; 86 } 87 88 91 public int getContentLength() { 92 return contentLength; 93 } 94 95 98 public void setContentLength(int contentLength) { 99 this.contentLength = contentLength; 100 } 101 102 105 public String getContentDisposition() { 106 return contentDisposition; 107 } 108 109 112 public void setContentDisposition(String contentDisposition) { 113 this.contentDisposition = contentDisposition; 114 } 115 116 119 public String getInputName() { 120 return (inputName); 121 } 122 123 126 public void setInputName(String inputName) { 127 this.inputName = inputName; 128 } 129 130 133 protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { 134 InputStream oInput = (InputStream ) invocation.getStack().findValue(conditionalParse(inputName, invocation)); 136 137 try { 138 HttpServletResponse oResponse = (HttpServletResponse ) invocation.getInvocationContext().get(HTTP_RESPONSE); 140 141 oResponse.setContentType(conditionalParse(contentType, invocation)); 143 144 if (contentLength != 0) { 146 oResponse.setContentLength(contentLength); 147 } 148 149 if (contentDisposition != null) { 151 oResponse.addHeader("Content-disposition", conditionalParse(contentDisposition, invocation)); 152 } 153 154 OutputStream oOutput = oResponse.getOutputStream(); 156 157 byte[] oBuff = new byte[bufferSize]; 159 int iSize = 0; 160 while (-1 != (iSize = oInput.read(oBuff))) { 161 oOutput.write(oBuff, 0, iSize); 162 } 163 164 oOutput.flush(); 166 } 167 finally { 168 if (oInput != null) oInput.close(); 169 } 170 } 171 172 } 173 | Popular Tags |