public int copy(InputStream input,
OutputStream output) throws IOException {
byte[] buffer = new byte[getBufferSize()];
int count = 0;
int n = 0;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
Copy bytes from an InputStream to an
OutputStream. |
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
StreamInfo info = getStreamInfo(mapping, form, request, response);
String contentType = info.getContentType();
InputStream stream = info.getInputStream();
try {
response.setContentType(contentType);
copy(stream, response.getOutputStream());
} finally {
if (stream != null) {
stream.close();
}
}
// Tell Struts that we are done with the response.
return null;
}
Process the specified HTTP request, and create the corresponding HTTP
response (or forward to another web component that will create it).
Return an ActionForward instance describing where and how
control should be forwarded, or null if the response has
already been completed. |